villm-tok-fast
Rust-backed fast tokenizer for Vietnamese-English code-switching, used in the viLLM project.
Installation
pip install villm-tok-fast
Usage
from villm_tok_fast import create_fast_tokenizer
from transformers import PreTrainedTokenizerFast
# Load from HuggingFace Hub (auto-downloads vocab files)
hf_tokenizer = create_fast_tokenizer("vlinhd11/villm-tokenizer")
# Or load from local directory
hf_tokenizer = create_fast_tokenizer("./path/to/villm-tokenizer")
# Tokenize
enc = hf_tokenizer("Học sinh giỏi tiếng Việt và học lập trình Python")
# tokens: ['Học_sinh', 'giỏi', 'tiếng_Việt', 'và_học', 'lập_trình', '[VI→EN]', '▁Python']
# Batch encode
batch = hf_tokenizer(["Câu thứ nhất", "Câu thứ hai"], padding=True, truncation=True)
Features
- Language detection — per-word Vi/EN/Num/Code/Punct classification
- Vietnamse Viterbi — merges frequent syllable bigrams into compound tokens (
học_sinh,Việt_Nam) - English subword — embedded SentencePiece trie for English OOV words (
▁Python,▁programming) - Code-switch markers — optional
[VI→EN]/[EN→VI]at language boundaries - Byte fallback —
<0xNN>for unknown characters
Performance
~4x faster than the pure Python equivalent (~55k texts/sec vs ~14k).
Requirements
- Python 3.8+
- transformers >= 4.30.0
How it works
This package provides a Rust implementation of the ViLLM tokenizer as a PyO3 native extension.
It exposes a Python class compatible with HuggingFace PreTrainedTokenizerFast via the
tokenizer_object= parameter.
The Rust core handles:
- Word-level language detection
- Viterbi dynamic programming for Vietnamese compound formation
- SentencePiece trie with whole-word preference for English subword
- Code-switch marker insertion
- Byte fallback for OOV characters
- Decoding with smart punctuation join
License
MIT
Metadata
Release files for villm-tok-fast 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| villm_tok_fast-0.2.1-cp38-abi3-win_amd64.whl | CPython 3.8 | abi3 | Windows x86-64 | Details for villm_tok_fast-0.2.1-cp38-abi3-win_amd64.whl |
Release files / villm_tok_fast-0.2.1-cp38-abi3-win_amd64.whl
| Download URL | villm_tok_fast-0.2.1-cp38-abi3-win_amd64.whl |
|---|---|
| Size | 873.0 kB |
| Tags | CPython 3.8 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
289d6d86546503dd885bcd0826ec20211db38e666fdb49aea87aa83ca7f4cd1e
|
|
BLAKE2b-256 checksum How to use checksums |
bcd2c057b3d759aabaa40c09130550c7b1fd30033b117f86545d8aca33661d43
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.11
|
Security for villm-tok-fast 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.