πŸ‘‘ VietBPE-32k-v1

VietBPE-32k-v1 is a highly optimized, high-density Byte-Level BPE (Byte Pair Encoding) tokenizer engineered specifically for Vietnamese text, multi-lingual web corpora, and source code (Python, JavaScript, Java, C++).

With a compact vocabulary size of 32,768 tokens, VietBPE-32k-v1 significantly outperforms generic high-vocabulary tokenizers (such as OpenAI's o200k_base with 200,000 tokens) on Vietnamese text compression and sequence density while keeping embedding table parameters minimal for small-to-medium Llama-style language models.


✨ Key Features & Highlights

  • ⚑ High Compression Density: Achieves ~4.04 chars/token on native Vietnamese prose (e.g., benchmarked against OpenAI's o200k_base taking 135 tokens vs. 161 tokens for a 537-character paragraph).
  • πŸ›‘οΈ Zero Diacritic & Tone Fragmentation: Full Vietnamese tone-marked words (e.g., GiαΊ£i, bΓ³ng, thαΊΏ, giα»›i) tokenize cleanly into single subwords without multi-byte fallback splits.
  • πŸ’» Source Code & Keyword Optimization: Contains dedicated single-token merges for major programming keywords (import, function, class) and language names (JavaScript, Python, Java).
  • 🌐 Internet & Social Entity Awareness: Dedicated single-token entries for major domains, entities, and global platforms (Wikipedia, Facebook, Instagram, Twitter).
  • πŸ“¦ Clean Roundtrip Decoding: 100% roundtrip accuracy with zero UTF-8 byte corruption, no unhandled mojibake, and optimized byte-level newline/indentation handling (\n repeated merges).

πŸ“Š Benchmark & Comparison

Evaluation on a standard 537-character Vietnamese Wikipedia entry (2014 FIFA World Cup):

Tokenizer Vocabulary Size Token Count Sequence Efficiency
VietBPE-32k-v1 32,768 135 tokens πŸ‘‘ 3.98 chars/token
o200k_base (GPT-4o) 200,000 161 tokens πŸ“‰ 3.33 chars/token

Result: VietBPE-32k-v1 delivers ~19.2% higher sequence compression on Vietnamese text while using less than 1/6th of the vocabulary size.


πŸš€ Quickstart & Usage

Installation

pip install transformers

Loading in Python

from transformers import AutoTokenizer

# Load tokenizer from Hugging Face Hub
tokenizer = AutoTokenizer.from_pretrained("VietBPE-32k-v1")

# Test Vietnamese Text
text = "GiαΊ£i vΓ΄ Δ‘α»‹ch bΓ³ng Δ‘Γ‘ thαΊΏ giα»›i 2014 (tiαΊΏng Anh: 2014 FIFA World Cup)"
tokens = tokenizer.encode(text)

print(f"Token IDs   : {tokens}")
print(f"Token Count : {len(tokens)}")
print(f"Decoded     : '{tokenizer.decode(tokens)}'")

Clean Subword Breakdown Script

from transformers import PreTrainedTokenizerFast

tokenizer = PreTrainedTokenizerFast.from_pretrained("VietBPE-32k-v1")
text = "import JavaScript Facebook Wikipedia"

encoded = tokenizer(text, add_special_tokens=True)
token_ids = encoded["input_ids"]

print(f"{'INDEX':<6} | {'TOKEN ID':<10} | {'SUBWORD'}")
print("-" * 40)
for idx, tid in enumerate(token_ids):
    subword = tokenizer.decode([tid])
    print(f"{idx:<6} | {tid:<10} | '{subword}'")

🧩 Special Tokens

Token ID Purpose
<pad> 0 Padding token
<unk> 1 Unknown token fallback
<bos> 2 Beginning of sequence
<eos> 3 End of sequence
<mask> 4 Mask token for MLM/Infilling

πŸ“„ License

This project is open-sourced under the MIT License.

MIT License

Copyright (a) 2026

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
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

Datasets used to train DinoResearch/VietBPE-32k-v1