huggingface-tokenizers

Train and apply fast BPE, WordPiece, and Unigram tokenizers for NLP pipelines.

13.0k|930|Updated Nov 3, 2025
One-click install
npx skills add https://github.com/Orchestra-Research/AI-research-SKILLs --skill huggingface-tokenizers-orchestra-research
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: huggingface-tokenizers
Source: https://github.com/Orchestra-Research/AI-research-SKILLs/tree/main/02-tokenization/huggingface-tokenizers
Command: npx skills add https://github.com/Orchestra-Research/AI-research-SKILLs --skill huggingface-tokenizers-orchestra-research

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires tokenizers, transformers, datasets, and includes references (resource) components.

What problem does it solve? Tokenizing large text corpora with pure Python implementations is slow, and building custom vocabularies for new models or domains requires deep knowledge of subword algorithms. This Skill provides Rust-based tokenization that processes 1GB of text in under 20 seconds, plus complete guidance for training custom tokenizers from scratch. ## Core Features & Use Cases - Custom Tokenizer Training: Train BPE, WordPiece, or Unigram tokenizers on your own corpus with configurable vocabulary size, special tokens, and normalization pipelines. - High-Speed Batch Encoding: Tokenize large datasets with padding, truncation, and multi-processing, achieving 80x speedup over pure Python. - Alignment Tracking: Map tokens back to original character positions for NER, question answering, and token classification tasks. - Transformers Integration: Wrap custom tokenizers with PreTrainedTokenizerFast and use them directly with AutoTokenizer and any transformers model. - Use Case: You are pretraining a domain-specific language model on medical literature. Use this Skill to train a 50k BPE tokenizer on your PubMed corpus, configure BERT-style post-processing, and export it in transformers format for model training. ## Quick Start Train a custom BPE tokenizer with a 30,000 token vocabulary on my corpus file and show me how to encode text with it.

Frequently Asked Questions about huggingface-tokenizers

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I train a custom BPE tokenizer in Python?▼

Initialize a Tokenizer with the BPE model, set a pre-tokenizer like Whitespace or ByteLevel, then call tokenizer.train with a BpeTrainer configured with your vocab_size and special tokens. Training on 100MB of text takes roughly 1-2 minutes on a modern CPU.

What is the difference between BPE, WordPiece, and Unigram tokenization?▼

BPE merges the most frequent character pairs and is used by GPT-2 and RoBERTa. WordPiece scores merges by likelihood ratio and powers BERT. Unigram starts with a large vocabulary and prunes tokens probabilistically, used by T5 and ALBERT via SentencePiece.

HuggingFace tokenizers vs SentencePiece vs tiktoken: which should I use?▼

Use HuggingFace tokenizers for fast general-purpose tokenization and custom training with transformers integration. Choose SentencePiece for language-independent models like T5, and tiktoken when working specifically with OpenAI GPT models.

Does HuggingFace tokenizers work with the transformers library?▼

Yes, AutoTokenizer uses fast tokenizers from this library internally when available. You can wrap a custom trained tokenizer with PreTrainedTokenizerFast and use it with any transformers model, including saving both together with save_pretrained.

Why is my tokenizer producing too many unknown tokens?▼

High unknown token rates usually mean the vocabulary is too small or min_frequency is too high during training. Increase vocab_size, lower min_frequency, or switch to byte-level BPE which eliminates unknown tokens entirely by falling back to bytes.

How do I track token positions in the original text for NER?▼

Encode with the fast tokenizer and read the output offsets, which give character start and end positions for each token. In transformers, pass return_offsets_mapping=True and use word_ids or char_to_token to align predictions with original text spans.