tokenizers README

The project's README from github.com/huggingface/tokenizers. As one markdown file: README.md.



Build GitHub

Provides an implementation of today's most used tokenizers, with a focus on performance and versatility.

Main features:

Performances

Performances can vary depending on hardware, but running the ~/bindings/python/benches/test_tiktoken.py should give the following on a g6 aws instance: image

Bindings

We provide bindings to the following languages (more to come!):

Installation

You can install from source using:

pip install git+https://github.com/huggingface/tokenizers.git#subdirectory=bindings/python

or install the released versions with

pip install tokenizers

Quick example using Python:

Choose 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!

tokenizers (huggingface/tokenizers)

Searching Database…

What is this?Tokenizers is a library implementing today's most-used tokenizers (BPE, WordPiece, Unigram) for NLP, built in Rust for speed and exposed to other languages via bindings. It's made by Hugging Face and powers tokenization for transformer models.
Is this a standalone app or a library I import into code?It's a library: a Rust core with bindings for Python, Node.js, and a community Ruby binding, meant to be imported into your own training/inference code.
How do I install and use it?Install from source or via the released package for your language (e.g. pip for Python), then pick a model type like BPE, WordPiece, or Unigram, instantiate a tokenizer, and train it on your files in just a couple lines of code.
Do I need Rust installed to use the Python bindings?No separate Rust toolchain is required for end users — the released Python/Node packages ship precompiled, you only need source build tools if compiling from source.
Does performance depend on my hardware?Yes, benchmarked speed numbers can vary depending on hardware; the README gives figures from a specific AWS g6 instance as a reference point, not a universal guarantee.
Who is this built for?It targets both researchers experimenting with tokenization and production teams needing fast, reliable text preprocessing for language models.
How fast is tokenization really?The README states it takes less than 20 seconds to tokenize a gigabyte of text on a server's CPU, thanks to the Rust implementation.
Can I trace tokens back to the original text?Yes, normalization comes with alignment tracking, so you can always retrieve the exact part of the original sentence a given token corresponds to.
Does it handle padding and truncation for me?Yes, it does all the needed pre-processing: truncating, padding, and adding the special tokens your model requires.
Which tokenizer algorithms are supported?You can choose between Byte-Pair Encoding (BPE), WordPiece, or Unigram models when instantiating a tokenizer.
Size
22.4 MB
Stars
11.2K
Age
6y
Commits · 90 Days