sentencepiece

Train and apply language-independent BPE or Unigram tokenizers on raw Unicode text.

2|Updated Jan 26, 2026
One-click install
npx skills add https://github.com/Nzettodess/Awesome-Agent-Skills --skill sentencepiece-nzettodess
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: sentencepiece
Source: https://github.com/Nzettodess/Awesome-Agent-Skills/tree/main/Skills/Agentic%20AI%20Development/AI-research-SKILLs-1.1.0/02-tokenization/sentencepiece
Command: npx skills add https://github.com/Nzettodess/Awesome-Agent-Skills --skill sentencepiece-nzettodess

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Tokenizing multilingual or CJK text usually requires language-specific preprocessing and pre-tokenization rules. This Skill trains deterministic subword tokenizers directly on raw text, producing reproducible vocabularies used by models like T5, ALBERT, XLNet, and mBART. ## Core Features & Use Cases - BPE and Unigram Training: Train tokenizers from a corpus file or Python iterator with configurable vocabulary size, character coverage, and normalization rules. - Encoding and Decoding: Convert text to subword pieces or token IDs and back, with whitespace preserved via the ▁ meta symbol. - Subword Regularization: Sample alternative tokenizations during training for data augmentation and model robustness. - Use Case: Train a 32k Unigram tokenizer on a multilingual corpus with character_coverage=1.0 for CJK support, then load it through the transformers T5Tokenizer for model training. ## Quick Start Train a SentencePiece Unigram tokenizer with 8000 vocabulary on my corpus.txt file and show me how to encode a sample sentence.

Frequently Asked Questions about sentencepiece

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

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

Call spm.SentencePieceTrainer.train with your input corpus file, model_prefix, vocab_size, and model_type set to 'unigram' or 'bpe'. This produces a .model binary and .vocab file you load with SentencePieceProcessor for encoding.

BPE vs Unigram tokenization: which should I use?▼

Unigram is probabilistic, supports sampling for subword regularization, and suits multilingual tasks; it is used by T5, ALBERT, and XLNet. BPE trains faster and is deterministic, used by mBART.

Does SentencePiece support Chinese, Japanese, and Korean text?▼

Yes, SentencePiece is language-independent and works on raw Unicode without pre-tokenization. For CJK languages, set character_coverage=1.0 during training so all characters are covered in the vocabulary.

Can I use SentencePiece with HuggingFace transformers?▼

Yes, models like T5 use SentencePiece internally. Load them with T5Tokenizer.from_pretrained('t5-base'), which wraps the SentencePiece model for encoding and decoding.

When should I not use SentencePiece?▼

Use HuggingFace Tokenizers when you need faster training and more flexibility, tiktoken for OpenAI GPT models, or BERT WordPiece for English-centric tasks. SentencePiece tokenizes at about 50k sentences per second versus 200k for HF Tokenizers.