ihanif / pashto-tokenizer

huggingface.co
Total runs: 0
24-hour runs: 0
7-day runs: 0
30-day runs: 0
Model's Last Updated: April 24 2026

Introduction of pashto-tokenizer

Model Details of pashto-tokenizer

Pashto BPE Tokenizer (32k)

A Pashto-native BPE tokenizer trained on 24 million unique sentences from the PashtoCorp corpus (1.25 billion words). Provided in two formats: a HuggingFace-native tokenizer (load with AutoTokenizer ) and a SentencePiece model for broader compatibility.

Performance
Metric Value
Vocabulary size 32,000
Pashto BPE fertility 1.2516 tokens/word
XLM-R fertility (Pashto) 1.5018 tokens/word
Token reduction vs XLM-R 16.67% fewer tokens
Training sentences 24,035,371

Fertility measures average tokens per whitespace-split word — lower means more efficient encoding. At 1.2516 tokens/word, this tokenizer uses 16.67% fewer tokens than XLM-R's multilingual tokenizer on Pashto text, which directly reduces compute cost for any transformer model trained with it.

Files
File Format Use case
tokenizer.json HuggingFace tokenizers AutoTokenizer.from_pretrained()
tokenizer_config.json HuggingFace config Required for AutoTokenizer
special_tokens_map.json HuggingFace config Required for AutoTokenizer
sentencepiece/pashto_bpe_32k.model SentencePiece MT, ASR, other pipelines
sentencepiece/pashto_bpe_32k.vocab SentencePiece vocab Human-readable vocabulary
Training details
Setting Value
Algorithm Byte Pair Encoding (BPE)
Vocabulary size 32,000
Min subword frequency 2
Training data 24M unique Pashto sentences (PashtoCorp)
Normalisation NFC Unicode
Pre-tokenisation Whitespace
Special tokens [PAD] , [CLS] , [SEP] , [UNK] , [MASK]
Installation
pip install transformers tokenizers
Usage — HuggingFace tokenizer
Load with AutoTokenizer
from transformers import AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained("ihanif/pashto-tokenizer")

text = "پښتو ژبه د افغانستان او پاکستان د ملیونونو خلکو مورنۍ ژبه ده"
tokens = tokenizer.tokenize(text)
print(tokens)
# ['پښتو', 'ژبه', 'د', 'افغانستان', 'او', 'پاکستان', 'د', 'ملیونونو', 'خلکو', 'مورنۍ', 'ژبه', 'ده']

encoded = tokenizer(text, return_tensors="pt")
print(encoded["input_ids"])
Encode and decode
from transformers import AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained("ihanif/pashto-tokenizer")

# Encode
ids = tokenizer.encode("د افغانستان خلک د سولې غوښتونکي دي")
print(ids)

# Decode back
text = tokenizer.decode(ids, skip_special_tokens=True)
print(text)
Batch encoding for model training
from transformers import AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained("ihanif/pashto-tokenizer")

sentences = [
    "کابل د افغانستان پلازمینه ده",
    "د افغانستان خلک د سولې غوښتونکي دي",
]

batch = tokenizer(
    sentences,
    padding=True,
    truncation=True,
    max_length=128,
    return_tensors="pt",
)
print(batch["input_ids"].shape)  # (2, 128)
Training a model from scratch with this tokenizer
from transformers import AutoTokenizer, RobertaConfig, RobertaForMaskedLM

tokenizer = AutoTokenizer.from_pretrained("ihanif/pashto-tokenizer")

config = RobertaConfig(
    vocab_size=tokenizer.vocab_size,
    max_position_embeddings=514,
    num_attention_heads=12,
    num_hidden_layers=6,
    type_vocab_size=1,
)

model = RobertaForMaskedLM(config=config)
print(f"Parameters: {model.num_parameters():,}")
Usage — SentencePiece
import sentencepiece as spm
from huggingface_hub import hf_hub_download

model_path = hf_hub_download(
    repo_id="ihanif/pashto-tokenizer",
    filename="sentencepiece/pashto_bpe_32k.model",
)

sp = spm.SentencePieceProcessor()
sp.Load(model_path)

text = "پښتو ژبه د افغانستان مورنۍ ژبه ده"
pieces = sp.EncodeAsPieces(text)
ids    = sp.EncodeAsIds(text)
print(pieces)
print(ids)

# Decode
print(sp.Decode(ids))
SentencePiece with byte fallback (handles any character)
# The model uses byte_fallback=True, so any OOV character
# is safely encoded as UTF-8 bytes rather than [UNK]
text_with_numbers = "د ۲۰۲۶ کال راپور"
print(sp.EncodeAsPieces(text_with_numbers))
Measuring fertility on your own text
from transformers import AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained("ihanif/pashto-tokenizer")

def fertility(text):
    words  = text.split()
    tokens = tokenizer.tokenize(text)
    return len(tokens) / len(words) if words else 0

print(fertility("د افغانستان د ملت د سولې غوښتنه"))
# → ~1.25 tokens/word
Related resources
Citation
@misc{rahman2026pashtocorp,
  title        = {PashtoCorp: A 1.25B-Word Corpus, Evaluation Suite, and
                  Reproducible Pipeline for Low-Resource Language Development},
  author       = {Rahman, Hanif},
  year         = {2026},
  howpublished = {\url{https://huggingface.co/ihanif/pashto-tokenizer}},
}

Runs of ihanif pashto-tokenizer on huggingface.co

0
Total runs
0
24-hour runs
0
3-day runs
0
7-day runs
0
30-day runs

More Information About pashto-tokenizer huggingface.co Model

More pashto-tokenizer license Visit here:

https://choosealicense.com/licenses/cc-by-4.0

pashto-tokenizer huggingface.co

pashto-tokenizer huggingface.co is an AI model on huggingface.co that provides pashto-tokenizer's model effect (), which can be used instantly with this ihanif pashto-tokenizer model. huggingface.co supports a free trial of the pashto-tokenizer model, and also provides paid use of the pashto-tokenizer. Support call pashto-tokenizer model through api, including Node.js, Python, http.

pashto-tokenizer huggingface.co Url

https://huggingface.co/ihanif/pashto-tokenizer

ihanif pashto-tokenizer online free

pashto-tokenizer huggingface.co is an online trial and call api platform, which integrates pashto-tokenizer's modeling effects, including api services, and provides a free online trial of pashto-tokenizer, you can try pashto-tokenizer online for free by clicking the link below.

ihanif pashto-tokenizer online free url in huggingface.co:

https://huggingface.co/ihanif/pashto-tokenizer

pashto-tokenizer install

pashto-tokenizer is an open source model from GitHub that offers a free installation service, and any user can find pashto-tokenizer on GitHub to install. At the same time, huggingface.co provides the effect of pashto-tokenizer install, users can directly use pashto-tokenizer installed effect in huggingface.co for debugging and trial. It also supports api for free installation.

pashto-tokenizer install url in huggingface.co:

https://huggingface.co/ihanif/pashto-tokenizer

Url of pashto-tokenizer

pashto-tokenizer huggingface.co Url

Provider of pashto-tokenizer huggingface.co

ihanif
ORGANIZATIONS

Other API from ihanif

huggingface.co

Total runs: 101
Run Growth: -46
Growth Rate: -46.46%
Updated:June 26 2024
huggingface.co

Total runs: 48
Run Growth: -50
Growth Rate: -102.04%
Updated:December 19 2024
huggingface.co

Total runs: 24
Run Growth: 6
Growth Rate: 28.57%
Updated:September 14 2025
huggingface.co

Total runs: 22
Run Growth: 10
Growth Rate: 47.62%
Updated:October 04 2024
huggingface.co

Total runs: 13
Run Growth: 10
Growth Rate: 76.92%
Updated:February 21 2025
huggingface.co

Total runs: 7
Run Growth: -4
Growth Rate: -50.00%
Updated:October 31 2024
huggingface.co

Total runs: 6
Run Growth: 3
Growth Rate: 50.00%
Updated:June 12 2025
huggingface.co

Total runs: 4
Run Growth: 3
Growth Rate: 75.00%
Updated:January 20 2023
huggingface.co

Total runs: 4
Run Growth: -4
Growth Rate: -80.00%
Updated:October 12 2024
huggingface.co

Total runs: 2
Run Growth: 0
Growth Rate: 0.00%
Updated:April 03 2025
huggingface.co

Total runs: 2
Run Growth: 0
Growth Rate: 0.00%
Updated:February 11 2023
huggingface.co

Total runs: 1
Run Growth: -2
Growth Rate: -200.00%
Updated:January 17 2023
huggingface.co

Total runs: 0
Run Growth: -8
Growth Rate: 0.00%
Updated:October 11 2024
huggingface.co

Total runs: 0
Run Growth: 0
Growth Rate: 0.00%
Updated:February 28 2026
huggingface.co

Total runs: 0
Run Growth: 0
Growth Rate: 0.00%
Updated:June 12 2025