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)
| 35 | |
| 36 | |
| 37 | def 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 | |
| 52 | def build_hgf_tokenizer(args): |