मुख्य सामग्री पर जाएँ
Skillpedia
मशीन लर्निंग14k · #11183

sentencepiece

यह क्या करती है

यह स्किल SentencePiece समझाती है, एक tokenizer जिसे किसी भाषा-विशेष नियमों की ज़रूरत नहीं होती। यह उन डेवलपर्स के लिए है जो ऐसे मॉडल बनाते हैं जिन्हें कई भाषाएँ सँभालनी हैं या जिन्हें दोहराया जा सकने वाला शब्दकोश चाहिए।

कब इस्तेमाल करें

  • ✓जब आप ऐसा मॉडल बना रहे हैं जिसे कई भाषाएँ सँभालनी हैं।
  • ✓जब आपके टेक्स्ट में चीनी, जापानी या कोरियाई अक्षर हैं।
  • ✓जब आप बिना अलग पहले-से-विभाजन के चरण के, कच्चे टेक्स्ट पर tokenizer ट्रेन करना चाहते हैं।

Skill का लिंक

https://github.com/Orchestra-Research/AI-Research-SKILLs/blob/main/02-tokenization/sentencepiece/SKILL.md

इसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।

कैसे इस्तेमाल करें

सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।

पेस्ट करने के लिए तैयार मैसेज

इस skill से मेरी मदद करो: https://github.com/Orchestra-Research/AI-Research-SKILLs/blob/main/02-tokenization/sentencepiece/SKILL.md इस लिंक की SKILL.md फ़ाइल पढ़ो और मेरे काम में उसके निर्देशों का पालन करो।
क्या आप चाहते हैं कि आपका AI ऐसी skills खुद ढूँढे?मुफ़्त Skillpedia MCP इंस्टॉल करें: बस एक लाइन, और हर काम से पहले यह 15,000+ skills में खोजता है।1 मिनट में इंस्टॉल करें →

AI से क्या माँगें: उदाहरण

“मेरे कई भाषाओं वाले टेक्स्ट पर, जिसमें जापानी भी है, अच्छा काम करने वाला tokenizer ट्रेन कीजिए।”

हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।

यह कैसे काम करती है

यह टेक्स्ट को कच्चे अक्षरों की तरह लेता है, BPE या Unigram से शब्दकोश सीखता है, और एक छोटी मॉडल फ़ाइल सेव करता है। स्किल दोनों तरीके दिखाती है, कमांड लाइन और Python।

तकनीकी सामग्री (मूल SKILL.md)

लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।

SentencePiece - Language-Independent Tokenization

Unsupervised tokenizer that works on raw text without language-specific preprocessing.

When to use SentencePiece

Use SentencePiece when:

  • Building multilingual models (no language-specific rules)
  • Working with CJK languages (Chinese, Japanese, Korean)
  • Need reproducible tokenization (deterministic vocabulary)
  • Want to train on raw text (no pre-tokenization needed)
  • Require lightweight deployment (6MB memory, 50k sentences/sec)

Performance:

  • Speed: 50,000 sentences/sec
  • Memory: ~6MB for loaded model
  • Languages: All (language-independent)

Use alternatives instead:

  • HuggingFace Tokenizers: Faster training, more flexibility
  • tiktoken: OpenAI models (GPT-3.5/4)
  • BERT WordPiece: English-centric tasks

Quick start

Installation

# Python
pip install sentencepiece

# C++ (requires CMake)
git clone https://github.com/google/sentencepiece.git
cd sentencepiece
mkdir build && cd build
cmake .. && make -j $(nproc)
sudo make install

Train model

# Command-line (BPE with 8000 vocab)
spm_train --input=data.txt --model_prefix=m --vocab_size=8000 --model_type=bpe

# Python API
import sentencepiece as spm

spm.SentencePieceTrainer.train(
    input='data.txt',
    model_prefix='m',
    vocab_size=8000,
    model_type='bpe'
)

Training time: ~1-2 minutes for 100MB corpus

Encode and decode

import sentencepiece as spm

# Load model
sp = spm.SentencePieceProcessor(model_file='m.model')

# Encode to pieces
pieces = sp.encode('This is a test', out_type=str)
print(pieces)  # ['▁This', '▁is', '▁a', '▁test']

# Encode to IDs
ids = sp.encode('This is a test', out_type=int)
print(ids)  # [284, 47, 11, 1243]

# Decode
text = sp.decode(ids)
print(text)  # "This is a test"

Language-independent design

Whitespace as symbol (▁)

text = "Hello world"
pieces = sp.encode(text, out_type=str)
print(pieces)  # ['▁Hello', '▁world']

# Decode preserves spaces
decoded = sp.decode_pieces(pieces)
print(decoded)  # "Hello world"

Key principle: Treat text as raw Unicode, whitespace = ▁ (meta symbol)

Tokenization algorithms

BPE (Byte-Pair Encoding)

spm.SentencePieceTrainer.train(
    input='data.txt',
    model_prefix='bpe_model',
    vocab_size=16000,
    model_type='bpe'
)

Used by: mBART

Unigram (default)

spm.SentencePieceTrainer.train(
    input='data.txt',
    model_prefix='unigram_model',
    vocab_size=8000,
    model_type='unigram'
)

Used by: T5, ALBERT, XLNet

Training configuration

Essential parameters

spm.SentencePieceTrainer.train(
    input='corpus.txt',
    model_prefix='m',
    vocab_size=32000,
    model_type='unigram',
    character_coverage=0.9995,  # 1.0 for CJK
    user_defined_symbols=['[SEP]', '[CLS]'],
    unk_piece='<unk>',
    num_threads=16
)

Character coverage

Language Type Coverage Rationale
English 0.9995 Most common chars
CJK (Chinese) 1.0 All characters needed
Multilingual 0.9995 Balance

Encoding options

Subword regularization

# Sample different tokenizations
for _ in range(3):
    pieces = sp.encode('tokenization', out_type=str, enable_sampling=True, alpha=0.1)
    print(pieces)

# Output (different each time):
# ['▁token', 'ization']
# ['▁tok', 'en', 'ization']

Use case: Data augmentation for robustness.

Common patterns

T5-style training

spm.SentencePieceTrainer.train(
    input='c4_corpus.txt',
    model_prefix='t5',
    vocab_size=32000,
    model_type='unigram',
    user_defined_symbols=[f'<extra_id_{i}>' for i in range(100)],
    unk_id=2,
    eos_id=1,
    pad_id=0
)

Integration with transformers

from transformers import T5Tokenizer

# T5 uses SentencePiece internally
tokenizer = T5Tokenizer.from_pretrained('t5-base')
inputs = tokenizer('translate English to French: Hello', return_tensors='pt')

Performance benchmarks

Training speed

Corpus BPE (16k) Unigram (8k)
100 MB 1-2 min 3-4 min
1 GB 10-15 min 30-40 min

Tokenization speed

  • SentencePiece: 50,000 sentences/sec
  • HF Tokenizers: 200,000 sentences/sec (4× faster)

Supported models

T5 family: t5-base, t5-large (32k vocab, Unigram) ALBERT

अक्सर पूछे जाने वाले सवाल

यह कितनी तेज़ है?

स्किल बताती है कि यह लगभग 50,000 वाक्य प्रति सेकंड सँभाल सकती है।

इसे कौन से मॉडल इस्तेमाल करते हैं?

स्किल T5, ALBERT, XLNet और mBART का ज़िक्र करती है।

ट्रेनिंग में कितना समय लगता है?

स्किल बताती है कि ट्रेनिंग में आम तौर पर एक से दो मिनट लगते हैं।

जानकारी

लेखक का मूल विवरण

Language-independent tokenizer treating text as raw Unicode. Supports BPE and Unigram algorithms. Fast (50k sentences/sec), lightweight (6MB memory), deterministic vocabulary. Used by T5, ALBERT, XLNet, mBART. Train on raw text without pre-tokenization. Use when you need multilingual support, CJK languages, or reproducible tokenization.

repo: Orchestra-Research/AI-Research-SKILLs

लोकप्रियता

GitHub स्टार
14k
रैंकिंग में स्थान
#11183
लाइसेंस
MIT
अपडेट की गई
10/10/2026

क्या यह skill काम की है?

0

लॉग इन करें वोट करने के लिए।

कमेंट

  • …

इस repository की और skills

autoresearch

14k

यह आपके एजेंट को साहित्य समीक्षा से प्रयोग और लेखन तक पूरे AI रिसर्च प्रोजेक्ट में मार्गदर्शन देती है, परीक्षण और समीक्षा के दोहराने वाले चक्र के साथ।

AI और एजेंटएजेंट

prompt-guard

14k

यह आपके एजेंट को Meta के छोटे classifier से टेक्स्ट को AI ऐप तक पहुँचने से पहले prompt injection और jailbreak कोशिशों के लिए जाँचने देती है।

कोडिंगसिक्योरिटी

pytorch-fsdp2

14k

यह आपके एजेंट को दिखाती है कि ट्रेनिंग स्क्रिप्ट में PyTorch FSDP2 कैसे जोड़ें, ताकि बड़े मॉडल GPU पर बँटें और सही तरीके से सेव हों।

डेटामशीन लर्निंग

ml-training-recipes

14k

यह आपके एजेंट को न्यूरल नेटवर्क के लिए परखे हुए ट्रेनिंग तरीके देती है, जिनमें मॉडल चुनाव, optimizers, learning rates और loss spikes ठीक करना शामिल है।

डेटामशीन लर्निंग

मिलती-जुलती skills