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

Function encode_whitespaces

codegeex/tokenizer/tokenizer.py:7–15  ·  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, max_len: int)

Source from the content-addressed store, hash-verified

5
6
7def encode_whitespaces(text: str, start_extra_id: int, max_len: int):
8 """ Encode whitespaces to extra tokens.
9
10 >>> encode_whitespaces('a\\n b\\n c', 10, 10)
11 'a\\n<|extratoken_10|>b\\n<|extratoken_11|>c'
12 """
13 for i in np.arange(max_len, 1, -1):
14 text = text.replace(" " * i, f"<|extratoken_{start_extra_id + i - 2}|>")
15 return text
16
17
18def decode_whitespaces(text: str, start_extra_id: int, max_len: int):

Callers 1

encode_codeMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected