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

tokenizers

> 数据库
开源

针对研究和生产优化的先进快速标记器

10.9K stars0 点赞0 次浏览
访问官网GitHub

工具介绍

针对研究和生产优化的先进快速标记器


<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.

Main features:

  • Train new vocabularies and tokenize, using today's most used tokenizers.
  • Extremely fast (both training and tokenization), thanks to the Rust implementation. Takes less than 20 seconds to tokenize a GB of text on a server's CPU.
  • Easy to use, but also extremely versatile.
  • Designed for research and production.
  • Normalization comes with alignments tracking. It's always possible to get the part of the original sentence that corresponds to a given token.
  • Does all the pre-processing: Truncate, Pad, add the special tokens your model needs.

Performances

Performances can vary depending on hardware, but running the ~/bindings/python/benches/test_tiktoken.py should give the following on a g6 aws instance:

Bindings

We provide bindings to the following languages (more to come!):

  • Rust (Original implementation)
  • Python
  • Node.js
  • Ruby (Contributed by @ankane, external repo)

Installation

You can install from source using:

bash
pip install git+https://github.com/huggingface/tokenizers.git#subdirectory=bindings/python

or install the released versions with

bash
pip install tokenizers

Quick example using Python:

Choose your model between Byte-Pair Encoding, WordPiece or Unigram and instantiate a tokenizer:

python
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:

python
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:

python
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:

python
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!

Issues· 219 开放

查看全部 Issues在 GitHub 打开
  • #2236

    [BUG] | 词汇分析器的文档列表页面出现 404 错误

    Stale更新于 2026年9月18日
  • #2320

    BpeTrainer 为出现零次的对发出合并 (通过 `as u64` 进行负数对数计数的拓展)

    Stale更新于 2026年9月18日
  • #2412

    BertWordPieceTokenizer 在加载词汇表时忽略 wordpieces_prefix

    更新于 2026年9月16日
  • #2094

    [安全性] 加载恶意 tokenizer.json 时,加载时进程被终止(BPE 合并缓冲区溢出)

    更新于 2026年9月11日
  • #1663

    `PreTrainedTokenizerFast` 在带有标记的文本上行为不一致

    bug更新于 2026年9月4日
  • #1784

    添加 cp314t 测试,将扩展模块标记为兼容,并提供无螺纹轮

    更新于 2026年9月2日
  • #1975

    [RFC] 韩国文本分词: Jamo 分解作为前置分词器(构成性字符集的蓝图)

    Feature Request更新于 2026年8月25日
  • #2334

    `Precompiled` 正则化器与 SentencePiece 不一致: 最短前缀匹配 + 静默丢弃剩余部分会丢弃代码点

    更新于 2026年8月23日
  • #1581

    [在 Windows 上构建] onig_sys/oniguruma 声明指定中包含两种或更多种数据类型

    更新于 2026年7月30日
  • #1973

    将 huggingface-hub 设置为可选依赖项(extras)

    Feature Request更新于 2026年7月28日

> 标签

Rustbertgptlanguage-modelnatural-language-processing

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

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类数据库
定价开源

> 相关工具

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库