huggingface-tokenizers

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

14|5|Updated Apr 9, 2026
One-click install
npx skills add https://github.com/MLT-OSS/hermes-agent-go --skill huggingface-tokenizers-mlt-oss
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: huggingface-tokenizers
Source: https://github.com/MLT-OSS/hermes-agent-go/tree/main/optional-skills/mlops/huggingface-tokenizers
Command: npx skills add https://github.com/MLT-OSS/hermes-agent-go --skill huggingface-tokenizers-mlt-oss

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 domain-specific or multilingual models requires deep knowledge of subword algorithms. This Skill provides guidance for using the Rust-based HuggingFace Tokenizers library to tokenize 1GB of text in under 20 seconds and train custom tokenizers from scratch. ## Core Features & Use Cases - High-Speed Tokenization: Encode text at roughly 4GB per minute using the Rust core, with batch encoding, padding, truncation, and multi-processing support. - Custom Tokenizer Training: Train BPE, WordPiece, or Unigram tokenizers on files or streaming dataset iterators, with configurable vocabulary size, special tokens, and normalization pipelines. - Alignment Tracking & Transformers Integration: Map tokens back to original character offsets for NER and QA tasks, and wrap custom tokenizers with PreTrainedTokenizerFast for use with 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, verify the unknown-token rate is under 1%, and export it in transformers format alongside your model. ## Quick Start Ask the agent to train a BPE tokenizer with a 30,000-token vocabulary on your corpus file and show the tokenized output for a sample sentence.

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 ByteLevel or Whitespace, then call tokenizer.train with a BpeTrainer configured with vocab_size and special_tokens. Training a 30k vocabulary on 100MB of text takes about 1-2 minutes on a multi-core 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, suiting multilingual models like T5 and ALBERT.

How do I use a custom tokenizer with the transformers library?

Save your trained tokenizer to JSON, then wrap it with PreTrainedTokenizerFast specifying unk_token, pad_token, and other special tokens. Call save_pretrained to export it in transformers format, after which AutoTokenizer.from_pretrained can load it like any hub tokenizer.

Does HuggingFace Tokenizers support tracking token positions in original text?

Yes, fast tokenizers return offset mappings that link each token to its character span in the source text. This enables downstream tasks like named entity recognition and extractive question answering where predictions must map back to original positions.

Why is my tokenizer producing too many unknown tokens?

High unknown-token rates usually mean the vocabulary is too small, min_frequency is too high, or training data is not representative. Increase vocab_size, lower min_frequency, or switch to byte-level BPE which eliminates unknown tokens entirely.

When should I use SentencePiece or tiktoken instead of HuggingFace Tokenizers?

Use tiktoken when replicating OpenAI GPT model tokenization exactly. SentencePiece suits language-independent training for T5 or ALBERT-style models. HuggingFace Tokenizers is preferable for custom training, alignment tracking, and native transformers integration.