Ampharic语言(QQ)的Syllable-aware BPE符号器 – 快速,准确,可训练.
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.
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.
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.
…vocab_size property for inspecting model vocabulary.test_roundtrip_basic.py example script for verifying tokenizer round-trip behavior.python -m venv .venv
source .venv/bin/activate # Linux/Mac
.venv\Scripts\activate # Windows
pip install amharic-tokenizerVerify the CLI:
amh-tokenizer --helppython -m venv .venv
source .venv/bin/activate
pip install -e .# 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 2000from 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")
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))# 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.txtTip: If running examples directly by path, ensure the package is installed (
pip install -e .) or run as a module from the project root:
python -m examples.try_tokenizer amh_bpe --text "..."AmharicTokenizer(num_merges=50000)train(corpus_text, verbose=False, log_every=1000) -> inttokenize(text) -> list[str]detokenize(tokens) -> strsave(path_prefix) / load(path_prefix)is_trained() -> boolnum_merges produce longer subwords.pip install -e .)
or run scripts from outside the repo to avoid shadowing the installed package.pip install -i https://test.pypi.org/simple/ \
--extra-index-url https://pypi.org/simple amharic-tokenizerThis project is licensed under the MIT License – see the LICENSE file for details.
暂无开放 Issues,或尚未同步最近议题。