A simple tokenizer for Mon text
Project description
Mon Tokenizer
Tokenize Mon text like a pro. No fancy stuff, just gets the job done.
quick start
# using pip
pip install mon-tokenizer
# using uv
uv add mon-tokenizer
from mon_tokenizer import MonTokenizer
tokenizer = MonTokenizer()
text = "ဂွံအခေါင်အရာမွဲသ္ဂောံဒုင်စသိုင်ကၠာကၠာရ။"
# tokenize
result = tokenizer.encode(text)
print(result["pieces"]) # ['▁ဂွံ', 'အခေါင်', 'အရာ', 'မွဲ', 'သ္ဂောံ', 'ဒုင်စသိုင်', 'ကၠာ', 'ကၠာ', 'ရ', '။']
print(result["ids"]) # [1234, 5678, ...]
# decode
decoded = tokenizer.decode(result["pieces"])
print(decoded) # ဂွံအခေါင်အရာမွဲသ္ဂောံဒုင်စသိုင်ကၠာကၠာရ။
Tokenizer in Hugging Face Format
from transformers import AutoTokenizer
# load tokenizer
tokenizer = AutoTokenizer.from_pretrained("janakhpon/mon_tokenizer")
# tokenize
text = "ပ္ဍဲအခိင်မာံနဲသဵု မဒှ်ဘဝကွးဘာတက္ကသိုလ်ဂှ် ပါလုပ်ချဳဓရာင်ကၠုင်"
tokens = tokenizer(text, return_tensors="pt")
input_ids = tokens["input_ids"][0]
print("token ids:", input_ids.tolist())
print("tokens:", tokenizer.convert_ids_to_tokens(input_ids))
print("decoded:", tokenizer.decode(input_ids, skip_special_tokens=True))
cli
# tokenize
mon-tokenizer "ဂွံအခေါင်အရာမွဲသ္ဂောံဒုင်စသိုင်ကၠာကၠာရ။"
# verbose output
mon-tokenizer -v "ဂွံအခေါင်အရာမွဲသ္ဂောံဒုင်စသိုင်ကၠာကၠာရ။"
# decode tokens
mon-tokenizer -d -t "▁ဂွံ,အခေါင်,အရာ,မွဲ,သ္ဂောံ,ဒုင်စသိုင်,ကၠာ,ကၠာ,ရ,။"
# interactive mode
mon-tokenizer
API
encode(text: str)→{"pieces": list, "ids": list, "text": str}decode(pieces: list)→strdecode_ids(ids: list)→strget_vocab_size()→intget_vocab()→dict
Dev Setup
git clone git@github.com:Code-Yay-Mal/mon_tokenizer.git
cd mon_tokenizer
uv sync --dev
uv run pytest
# Release workflow
uv version --bump patch
git add pyproject.toml
git commit -m "bump version"
git tag v0.1.5
git push origin main --tags
Resources
License
MIT - do whatever you want with it.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
mon_tokenizer-0.1.5.tar.gz
(949.6 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
mon_tokenizer-0.1.5-py3-none-any.whl
(950.3 kB
view details)
File details
Details for the file mon_tokenizer-0.1.5.tar.gz.
File metadata
- Download URL: mon_tokenizer-0.1.5.tar.gz
- Upload date:
- Size: 949.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.8.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0bd11c60a65d2290f4ae07d74ea81d8a4e024fb1cacaf52d6c8b82edc6c516b2
|
|
| MD5 |
12ff2ba9e49212a46716414d4ca95794
|
|
| BLAKE2b-256 |
0c64587516e79e891f0d8b828db58214b34111b758122370ead4f156b2280c80
|
File details
Details for the file mon_tokenizer-0.1.5-py3-none-any.whl.
File metadata
- Download URL: mon_tokenizer-0.1.5-py3-none-any.whl
- Upload date:
- Size: 950.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.8.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
786f4b5419e17654223bd4e4aba71bce186ada4a643d78f65270eea9bf760b42
|
|
| MD5 |
ed72b23f6a7232b589efff678e5e5a92
|
|
| BLAKE2b-256 |
4ac853933ca70c52375fbd1560dee8ba5f70955d9eda88aefe6b8ab2151d8fad
|