Fast State-of-the-Art Tokenizers optimized for Research and Production
Fast State-of-the-Art Tokenizers optimized for Research and Production
<br>
<a href="https://github.com/huggingface/tokenizers/blob/main/LICENSE">
</a>
<a href="https://pepy.tech/project/tokenizers">
</a>
Provides an implementation of today's most used tokenizers, with a focus on performance and versatility.
Performances can vary depending on hardware, but running the ~/bindings/python/benches/test_tiktoken.py should give the following on a g6 aws instance:
We provide bindings to the following languages (more to come!):
You can install from source using:
pip install git+https://github.com/huggingface/tokenizers.git#subdirectory=bindings/pythonor install the released versions with
pip install tokenizersChoose your model between Byte-Pair Encoding, WordPiece or Unigram and instantiate a tokenizer:
from tokenizers import Tokenizer
from tokenizers.models import BPE
tokenizer = Tokenizer(BPE())You can customize how pre-tokenization (e.g., splitting into words) is done:
from tokenizers.pre_tokenizers import Whitespace
tokenizer.pre_tokenizer = Whitespace()Then training your tokenizer on a set of files just takes two lines of codes:
from tokenizers.trainers import BpeTrainer
trainer = BpeTrainer(special_tokens=["[UNK]", "[CLS]", "[SEP]", "[PAD]", "[MASK]"])
tokenizer.train(files=["wiki.train.raw", "wiki.valid.raw", "wiki.test.raw"], trainer=trainer)Once your tokenizer is trained, encode any text with just one line:
output = tokenizer.encode("Hello, y'all! How are you ?")
print(output.tokens)
# ["Hello", ",", "y", "'", "all", "!", "How", "are", "you", "[UNK]", "?"]Check the documentation or the quicktour to learn more!
[1.0.0rc2] Encoding.ids_array panics while another thread decodes the ids
[1.0.0rc2] Possible regressions vs. `0.23.x`: Byte atom not found in the vocabulary
v1.0.0-rc.2: canonicalize_file rejects ByteLevel add_prefix_space=true supported by 0.23.2
do we have plan support java ,we need you
Two incorrect type annotations affect input typing to tokenizers.Tokenizer.encode()
Type Stubs for subpackages don't work with basedpyright
Release 0.23.1 introduces breaking change in Encoding.overflowing
[Feature/Security] Support trusted and untrusted special-token spans
Inconsistent behaviour of `PreTrainedTokenizerFast`s on diacritics marked texts
[Security] Load-time process abort when loading a malicious tokenizer.json (BPE merge buffer overrun)