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

Function decode_whitespaces

codegeex/mindspore/src/code_tokenizer.py:43–55  ·  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

41
42
43def decode_whitespaces(text: str, start_extra_id: int, max_len: int):
44 """ Decode the whitespace-encoded strings produced by encode_whitespace.
45
46 >>> text = 'a\\n b\\n c'
47 >>> s, l = 10, 10
48 >>> text == decode_whitespaces(encode_whitespaces(text, s, l), s, l)
49 True
50 """
51 for l in range(2, max_len + 1):
52 token_id = start_extra_id - 2 + l
53 token = f'<|extratoken_{token_id}|>'
54 text = text.replace(token, ' ' * l)
55 return text
56
57
58class Code13BDictionary(object):

Callers 1

decode_codeMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected