百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
A

Amharic-Tokenizer

> AI 编程
开源

Ampharic语言(QQ)的Syllable-aware BPE符号器 – 快速,准确,可训练.

100 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

Ampharic语言(QQ)的Syllable-aware BPE符号器 – 快速,准确,可训练.

Amharic Tokenizer

Amharic tokenizer with a GPT-style BPE-like pipeline over decomposed fidel. Implements: cleaning → fidel decomposition → BPE training/application → detokenization, with a Cython core for speed.


What's new in v0.2.6

  • Vocab size: 30,000 tokens
  • Trained on a larger and more diverse Amharic corpus
  • Improved tokenization quality and detokenization accuracy
  • Better handling of edge cases and rare words
  1. Pretrained tokenizer loading
  • You can now load a pretrained tokenizer directly:
python
from amharic_tokenizer import AmharicTokenizer
tok = AmharicTokenizer.load("amh_bpe_v0.2.6")

This version includes a pretrained model (amh_bpe_v0.2.6) that can be used immediately without any additional setup and training.

  1. Full token-to-ID and ID-to-token functionality
  • Added complete round-trip processing methods:
python
tokens = tok.tokenize(text)
ids = tok.encode(tokens)
detokenized = tok.detokenize(tokens)

The tokenizer now supports seamless conversion between tokens and IDs, ensuring full consistency between tokenization and detokenization.


Test Script: test_roundtrip_basic.py

…

Additional Improvements

  • Added vocab_size property for inspecting model vocabulary.
  • Added test_roundtrip_basic.py example script for verifying tokenizer round-trip behavior.
  • Internal `` token remains an end-of-word marker and is excluded from final detokenized output.

Installation

From PyPI (recommended)

bash
python -m venv .venv
source .venv/bin/activate  # Linux/Mac
.venv\Scripts\activate     # Windows

pip install amharic-tokenizer

Verify the CLI:

bash
amh-tokenizer --help

From source (for development)

bash
python -m venv .venv
source .venv/bin/activate
pip install -e .

Training (CLI)

bash
# Train on a cleaned Amharic text corpus and save model
amh-tokenizer train /abs/path/to/cleaned_amharic.txt /abs/path/to/amh_bpe \
  --num-merges 50000 --verbose --log-every 2000

# Example using relative paths
amh-tokenizer train cleaned_amharic.txt amh_bpe --num-merges 50000 --verbose --log-every 2000

Training (Python)

python
from amharic_tokenizer.tokenizer import AmharicTokenizer

tokenizer = AmharicTokenizer(vocab_size=5000, num_merges=2000)
tokenizer.train(corpus_text, verbose=True, log_every=100)
tokenizer.save("amh_bpe_model")
tokenizer = AmharicTokenizer.load("amh_bpe_model")

Quick Usage (Python)

python
from amharic_tokenizer import AmharicTokenizer

# Load a trained model
tok = AmharicTokenizer.load("amh_bpe_v0.2.6")

text = "ኢትዮጵያ ጥሩ ናት።"

# Tokenize
tokens = tok.tokenize(text)
print(tokens)  # variable-length subword tokens
# Tokens to ids
ids = tok.encode(text) # or tok.convert_tokens_to_ids(tokens)
decoded = tok.decode(ids)  # or tok.detokenize(tokens)

display_tokens = [t.replace('', '') for t in tokens if t != '']
print(display_tokens)

# Detokenize back to original text
print(tok.detokenize(tokens))

Example Script

bash
# Test a single string
python examples/try_tokenizer.py amh_bpe --text "ኢትዮጵያ ጥሩ ናት።"

# Test a file
python examples/try_tokenizer.py amh_bpe --file cleaned_amharic.txt

Tip: If running examples directly by path, ensure the package is installed (pip install -e .) or run as a module from the project root:

bash
python -m examples.try_tokenizer amh_bpe --text "..."

API

python
AmharicTokenizer(num_merges=50000)
  • train(corpus_text, verbose=False, log_every=1000) -> int
  • tokenize(text) -> list[str]
  • detokenize(tokens) -> str
  • save(path_prefix) / load(path_prefix)
  • is_trained() -> bool

Notes

  • Longer, more diverse corpora and higher num_merges produce longer subwords.
  • Training and tokenization work over decomposed fidel; detokenization recomposes the original Amharic characters.

Troubleshooting

  • ModuleNotFoundError inside the repo: install in editable mode (pip install -e .) or run scripts from outside the repo to avoid shadowing the installed package.
  • TestPyPI installs: resolve build dependencies from PyPI:
bash
pip install -i https://test.pypi.org/simple/ \
    --extra-index-url https://pypi.org/simple amharic-tokenizer

License

This project is licensed under the MIT License – see the LICENSE file for details.

Issues· 1 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Pythonafrican-languagesamharicamharic-tokenizeramharictokenizer

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类AI 编程
定价开源

> 相关工具

G
GitHub Copilot
GitHub 官方 AI 编程助手,覆盖补全、Chat 与 Agent 模式。
C
Cursor
AI 原生代码编辑器,对话改代码、多文件 Agent 与规则体系是其核心。
S
skills
Skills for Real Engineers. Straight from my .agents directory.