MCPcopy Index your code
hub / github.com/zai-org/CodeGeeX / decode_whitespaces

Function decode_whitespaces

codegeex/tokenizer/tokenizer.py:18–30  ·  view source on GitHub ↗

Decode the whitespace-encoded strings produced by encode_whitespace. >>> text = 'a\\n b\\n c' >>> s, l = 10, 10 >>> text == decode_whitespaces(encode_whitespaces(text, s, l), s, l) True

(text: str, start_extra_id: int, max_len: int)

Source from the content-addressed store, hash-verified

16
17
18def decode_whitespaces(text: str, start_extra_id: int, max_len: int):
19 """ Decode the whitespace-encoded strings produced by encode_whitespace.
20
21 >>> text = 'a\\n b\\n c'
22 >>> s, l = 10, 10
23 >>> text == decode_whitespaces(encode_whitespaces(text, s, l), s, l)
24 True
25 """
26 for l in range(2, max_len + 1):
27 token_id = start_extra_id - 2 + l
28 token = f'<|extratoken_{token_id}|>'
29 text = text.replace(token, ' ' * l)
30 return text
31
32
33class CodeGeeXTokenizer(object):

Callers 1

decode_codeMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected