Spaces:
Runtime error
Runtime error
Download ml/tokenizer/regex_split.py from TheAbyss99/abyss-api: direct link, hf CLI and curl.
- Browser
- Download file 601 Bytes
-
https://huggingface.co/spaces/TheAbyss99/abyss-api/resolve/main/ml/tokenizer/regex_split.py
- Command line
-
hf download hf://spaces/TheAbyss99/abyss-api/ml/tokenizer/regex_split.py
-
curl -L -o regex_split.py https://huggingface.co/spaces/TheAbyss99/abyss-api/resolve/main/ml/tokenizer/regex_split.py
601 Bytes
| """GPT-2 style pre-tokenization. Splits text into chunks (words with a | |
| leading space, number runs, punctuation runs, whitespace) so BPE only | |
| ever merges *within* a chunk, never across word boundaries.""" | |
| import regex as re | |
| # The GPT-2 pattern. Order matters: contractions, spaced letters, | |
| # spaced numbers, spaced punctuation, the whitespace. | |
| GPT2_PATTERN = ( | |
| r"""'s|'t|'re|'ve|'m|'ll|'d""" | |
| r"""| ?\p{L}+| ?\p{N}+| ?[^\s\p{L}\p{N}]+|\s+(?!\S)|\s+""" | |
| ) | |
| _PAT = re.compile(GPT2_PATTERN) | |
| def split(text): | |
| """Return list of chunk strings.""" | |
| return _PAT.findall(text) |