Download core/tokenizer_utils.py from build-small-hackathon/tiny-press: direct link, hf CLI and curl.
- Browser
- Download file 453 Bytes
-
https://huggingface.co/spaces/build-small-hackathon/tiny-press/resolve/main/core/tokenizer_utils.py
- Command line
-
hf download hf://spaces/build-small-hackathon/tiny-press/core/tokenizer_utils.py
-
curl -L -o tokenizer_utils.py https://huggingface.co/spaces/build-small-hackathon/tiny-press/resolve/main/core/tokenizer_utils.py
453 Bytes
| from models.model_loader import get_tokenizer_only | |
| def count_tokens(text: str) -> int: | |
| tokenizer = get_tokenizer_only() | |
| return len(tokenizer.encode(text, add_special_tokens=False)) | |
| def get_token_strings(text: str) -> list[str]: | |
| """Return the decoded surface string for every token in text.""" | |
| tokenizer = get_tokenizer_only() | |
| ids = tokenizer.encode(text, add_special_tokens=False) | |
| return [tokenizer.decode([i]) for i in ids] | |