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

Function encode_whitespaces

codegeex/megatron/tokenizer/tokenizer.py:26–34  ·  view source on GitHub ↗

Encode whitespaces to extra tokens. >>> encode_whitespaces('a\\n b\\n c', 10, 10) 'a\\n<|extratoken_10|>b\\n<|extratoken_11|>c'

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

Source from the content-addressed store, hash-verified

24
25
26def encode_whitespaces(text: str, start_extra_id: int=10, max_len: int=10):
27 """Encode whitespaces to extra tokens.
28
29 >>> encode_whitespaces('a\\n b\\n c', 10, 10)
30 'a\\n<|extratoken_10|>b\\n<|extratoken_11|>c'
31 """
32 for i in np.arange(max_len, 1, -1):
33 text = text.replace(" " * i, f"<|extratoken_{start_extra_id + i - 2}|>")
34 return text
35
36
37def decode_whitespaces(text: str, start_extra_id: int=10, max_len: int=10):

Callers 1

tokenizeMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected