Sinhala BPE Tokenizer

A Byte-Pair Encoding (BPE) tokenizer tailored for Sinhala text, designed for seamless integration with Hugging Face's Transformers library. Optimized for modern NLP tasks, it ensures efficient and accurate tokenization of Sinhala language data.

πŸ” Overview

  • Tokenizer Type: Byte-Pair Encoding (BPE)
  • Vocabulary Size: 32,000 tokens
  • Training Dataset: Navanjana/sinhala-articles
  • Language: Sinhala (ΰ·ƒΰ·’ΰΆ‚ΰ·„ΰΆ½)
  • License: Apache 2.0

πŸ”§ Features

  • Utilizes Unicode NFD normalization for accurate Sinhala character segmentation
  • Employs whitespace and punctuation pre-tokenization for precise token boundaries
  • Fully compatible with Hugging Face's transformers and tokenizers libraries
  • Optimized for tasks like text generation, classification, and translation

🧹 Special Tokens

Token Purpose
<bos> Beginning of sequence
<eos> End of sequence
</s> Separator token
<unk> Unknown token
<pad> Padding token
[MASK] Masking token for MLM tasks
`< startoftext >` Start of raw text segment
`< endoftext >` End of raw text segment

πŸš€ Getting Started

✨ Installation

pip install transformers tokenizers

πŸ› οΈ Usage

from transformers import AutoTokenizer

# Load the tokenizer
tokenizer = AutoTokenizer.from_pretrained("your-username/sinhala-bpe-tokenizer")

# Sample text
text = "ࢸේ ΰ·ƒΰ·’ΰΆ‚ΰ·„ΰΆ½ ࢴාࢨࢺ්࢚"

# Tokenize
tokens = tokenizer.tokenize(text)
print("Tokens:", tokens)

# Encode
token_ids = tokenizer.encode(text)
print("Token IDs:", token_ids)

# Decode
decoded = tokenizer.decode(token_ids)
print("Decoded:", decoded)

# Encode with special tokens
with_special = tokenizer.encode(text, add_special_tokens=True)
print("With special tokens:", with_special)

🧠 Advanced Usage

texts = [
    "ΰ·ΰ·Šβ€ΰΆ»ΰ·“ ΰΆ½ΰΆ‚ΰΆšΰ·ΰ·€ ΰΆ…ΰΆ΄ΰ·š ΰΆ»ΰΆ§",
    "ΰΆ…ΰΆ― ΰ·„ΰ·œΰΆ³ ΰΆ―ΰ·’ΰΆ±ΰΆΊΰΆšΰ·Š",
    "ΰ·ƒΰ·’ΰΆ‚ΰ·„ΰΆ½ ࢷාෂාව ΰΆ½ΰ·ƒΰ·Šΰ·ƒΰΆ±"
]

# Batch encode
encoded = tokenizer(texts, padding=True, truncation=True, return_tensors="pt")
print(encoded)

βš™οΈ Training Specifications

  • Vocabulary Size: 32,000
  • Minimum Frequency: 2
  • Normalization: NFD
  • Pre-tokenizer: Whitespace and Punctuation
  • End-of-word marker: </w>

Configuration Example

tokenizer_config = {
    "vocab_size": 32000,
    "min_frequency": 2,
    "normalizer": "NFD",
    "pre_tokenizer": ["Whitespace", "Punctuation"],
    "decoder": "BPEDecoder",
    "post_processor": "TemplateProcessing"
}

🌐 Use Cases

NLP Tasks

  • Language Modeling
  • Text Generation
  • Machine Translation
  • Text Classification
  • Named Entity Recognition (NER)

Research

  • Low-resource NLP
  • Multilingual and cross-lingual model training

🎯 Example Tokenizations

text = "ΰΆΈΰΆΈ ΰ·ƒΰ·’ΰΆ‚ΰ·„ΰΆ½ ΰΆ‰ΰΆœΰ·™ΰΆ± ΰΆœΰΆ±ΰ·ŠΰΆ±ΰ·€ΰ·"
# Output: ['▁ࢸࢸ', '▁සිࢂහࢽ', 'β–ΰΆ‰ΰΆœΰ·™ΰΆ±', 'β–ΰΆœΰΆ±ΰ·ŠΰΆ±ΰ·€ΰ·']

text = "ΰ·ΰ·Šβ€ΰΆ»ΰ·“ ΰΆ½ΰΆ‚ΰΆšΰ·ΰ·€ΰ·š ΰΆ“ΰΆ­ΰ·’ΰ·„ΰ·ΰ·ƒΰ·’ΰΆš ࢱ࢜ࢻࢺ්࢚ ΰ·€ΰΆ± ࢅࢱුࢻාࢰࢴුࢻࢺ"
# Output: ['β–ΰ·ΰ·Šβ€ΰΆ»ΰ·“', 'β–ΰΆ½ΰΆ‚ΰΆšΰ·ΰ·€ΰ·š', 'β–ΰΆ“ΰΆ­ΰ·’ΰ·„ΰ·ΰ·ƒΰ·’ΰΆš', 'β–ΰΆ±ΰΆœΰΆ»ΰΆΊΰΆšΰ·Š', '▁වࢱ', '▁ࢅࢱුࢻාࢰࢴුࢻࢺ']

text = "2024 ΰ·€ΰΆ»ΰ·Šΰ·‚ΰΆΊΰ·š ΰ·ΰ·Šβ€ΰΆ»ΰ·“ ΰΆ½ΰΆ‚ΰΆšΰ·ΰ·€"
# Output: ['▁2024', 'β–ΰ·€ΰΆ»ΰ·Šΰ·‚ΰΆΊΰ·š', 'β–ΰ·ΰ·Šβ€ΰΆ»ΰ·“', 'β–ΰΆ½ΰΆ‚ΰΆšΰ·ΰ·€']

🧐 Model Integration

GPT-style Models

from transformers import GPT2LMHeadModel, GPT2Config

config = GPT2Config(vocab_size=tokenizer.vocab_size)
model = GPT2LMHeadModel(config)

BERT-style Models

from transformers import BertForMaskedLM, BertConfig

config = BertConfig(vocab_size=tokenizer.vocab_size)
model = BertForMaskedLM(config)

πŸ“Š Evaluation Metrics

Metric Value Description
Vocabulary Coverage >95% Coverage of common Sinhala words
Compression Ratio ~3.2 Average characters per token
Special Token Ratio 0.025% Ratio of special to regular tokens
OOV Rate <2% Out-of-vocabulary rate on test set

πŸ—’οΈ Version History

  • v1.0: Initial release with 32K vocabulary

    • Trained on Navanjana/sinhala-articles dataset
    • Compatible with Transformers 4.0+

πŸ“š Citation

If you use this tokenizer in your research, please cite:

@misc{sinhala-bpe-tokenizer-2025,
  title={Sinhala BPE Tokenizer: A Specialized Tokenizer for Sinhala Text Processing},
  author={Your Name},
  year={2025},
  url={https://huggingface.co/your-username/sinhala-bpe-tokenizer},
  note={Hugging Face Model Hub}
}

🀝 Contributing

Contributions are welcome! You can:

  • Report issues with specific edge cases
  • Suggest improvements or optimizations
  • Submit evaluation results on downstream Sinhala NLP tasks
  • Share model training results using this tokenizer

🌍 License

This tokenizer is released under the Apache 2.0 License. See the LICENSE file for details.

πŸ™ Acknowledgments

  • Built using Hugging Face's Tokenizers library
  • Trained on the Navanjana/sinhala-articles dataset
  • Inspired by modern tokenization best practices
  • Special thanks to the Sinhala NLP community

πŸ“¬ Contact

For questions, issues, or collaboration:

  • Open an issue in this repository
  • Email: [[email protected]]
  • Twitter: [@your-twitter-handle]
Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Dataset used to train Navanjana/sinhala-gemma3-tokenizer