针对研究和生产优化的先进快速标记器
<br>
<a href="https://github.com/huggingface/tokenizers/blob/main/LICENSE">
</a>
<a href="https://pepy.tech/project/tokenizers">
</a>
Provides an implementation of today's most used tokenizers, with a focus on performance and versatility.
Performances can vary depending on hardware, but running the ~/bindings/python/benches/test_tiktoken.py should give the following on a g6 aws instance:
We provide bindings to the following languages (more to come!):
You can install from source using:
pip install git+https://github.com/huggingface/tokenizers.git#subdirectory=bindings/pythonor install the released versions with
pip install tokenizersChoose your model between Byte-Pair Encoding, WordPiece or Unigram and instantiate a tokenizer:
from tokenizers import Tokenizer
from tokenizers.models import BPE
tokenizer = Tokenizer(BPE())You can customize how pre-tokenization (e.g., splitting into words) is done:
from tokenizers.pre_tokenizers import Whitespace
tokenizer.pre_tokenizer = Whitespace()Then training your tokenizer on a set of files just takes two lines of codes:
from tokenizers.trainers import BpeTrainer
trainer = BpeTrainer(special_tokens=["[UNK]", "[CLS]", "[SEP]", "[PAD]", "[MASK]"])
tokenizer.train(files=["wiki.train.raw", "wiki.valid.raw", "wiki.test.raw"], trainer=trainer)Once your tokenizer is trained, encode any text with just one line:
output = tokenizer.encode("Hello, y'all! How are you ?")
print(output.tokens)
# ["Hello", ",", "y", "'", "all", "!", "How", "are", "you", "[UNK]", "?"]Check the documentation or the quicktour to learn more!
[BUG] | 词汇分析器的文档列表页面出现 404 错误
BpeTrainer 为出现零次的对发出合并 (通过 `as u64` 进行负数对数计数的拓展)
BertWordPieceTokenizer 在加载词汇表时忽略 wordpieces_prefix
[安全性] 加载恶意 tokenizer.json 时,加载时进程被终止(BPE 合并缓冲区溢出)
`PreTrainedTokenizerFast` 在带有标记的文本上行为不一致
添加 cp314t 测试,将扩展模块标记为兼容,并提供无螺纹轮
[RFC] 韩国文本分词: Jamo 分解作为前置分词器(构成性字符集的蓝图)
`Precompiled` 正则化器与 SentencePiece 不一致: 最短前缀匹配 + 静默丢弃剩余部分会丢弃代码点
[在 Windows 上构建] onig_sys/oniguruma 声明指定中包含两种或更多种数据类型
将 huggingface-hub 设置为可选依赖项(extras)