MCPcopy Create free account
hub / github.com/zai-org/CodeGeeX / decode_whitespaces

Function decode_whitespaces

codegeex/megatron/tokenizer/tokenizer.py:37–49  ·  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=10, max_len: int=10)

Source from the content-addressed store, hash-verified

35
36
37def decode_whitespaces(text: str, start_extra_id: int=10, max_len: int=10):
38 """Decode the whitespace-encoded strings produced by encode_whitespace.
39
40 >>> text = 'a\\n b\\n c'
41 >>> s, l = 10, 10
42 >>> text == decode_whitespaces(encode_whitespaces(text, s, l), s, l)
43 True
44 """
45 for l in range(2, max_len + 1):
46 token_id = start_extra_id - 2 + l
47 token = f"<|extratoken_{token_id}|>"
48 text = text.replace(token, " " * l)
49 return text
50
51
52def build_hgf_tokenizer(args):

Callers 1

detokenizeMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected