# ByT5

**ByT5** 是一系列预训练的、无需分词器的编码器-解码器 [Transformer](https://www.edgepedia.org/zh/transformer) 语言模型，它直接以原始 UTF-8 字节而非词或子词 token 来处理文本。该模型由 Linting Xue、Aditya Barua、Noah Constant、Rami Al-Rfou、Sharan Narang、Mihir Kale、Adam Roberts 和 Colin Raffel 在 2021 年 5 月的一篇 arXiv 论文中提出，并于 2022 年发表在《计算语言学协会会刊》上。它通过完全移除子词词表，扩展了 Google 的多语言 mT5 模型。<sup>[1](https://arxiv.org/abs/2105.13626)</sup><sup> • </sup><sup>[2](https://aclanthology.org/2022.tacl-1.17/)</sup>

| 关键事实 | 详情 |
|---|---|
| 输入表示 | 原始 UTF-8 字节；词表为 256 个字节值加 3 个特殊 token，无位置嵌入<sup>[3](https://github.com/will-thompson-k/tldr-transformers/blob/main/notes/byt5.md)</sup> |
| 架构 | 标准 T5 风格编码器-解码器，编码器更重（层数更多）以补偿无分词器设计；ByT5-Base 有 5.82 亿参数，18 层编码器，6 层解码器，d_model 1536，d_ff 3968<sup>[4](https://github.com/google-research/byt5/blob/master/byt5/gin/models/byt5.base.gin)</sup><sup> • </sup><sup>[3](https://github.com/will-thompson-k/tldr-transformers/blob/main/notes/byt5.md)</sup> |
| 发布规模 | Small 3 亿、Base 5.82 亿、Large 12 亿、XL 37 亿、XXL 130 亿参数，规模与 mT5 对应版本匹配<sup>[5](https://github.com/google-research/byt5)</sup> |
| 预训练 | 在 mC4 语料库上以跨度损坏式目标训练，平均跨度掩码为 20 个 UTF-8 字符，序列长度 1024，训练 1,000,000 步，批大小 1,048,576 个 token<sup>[6](https://huggingface.co/google/byt5-small)</sup><sup> • </sup><sup>[3](https://github.com/will-thompson-k/tldr-transformers/blob/main/notes/byt5.md)</sup> |
| 质量权衡 | 参数匹配的 ByT5 在多种任务上与 mT5 相当，在噪声文本及对拼写和发音敏感的任务上优于 mT5，但推理速度显著更慢，视任务不同可慢至 10 倍<sup>[7](https://github.com/google-research/t5x/blob/main/docs/models.md)</sup> |
| 许可与发布 | Apache-2.0 许可证，检查点发布于 Hugging Face 的 Google 组织下，2021-05-28 发布，2021-06-01 加入 Transformers<sup>[6](https://huggingface.co/google/byt5-small)</sup><sup> • </sup><sup>[8](https://huggingface.co/docs/transformers/v5.10.2/en/model_doc/byt5)</sup> |

## 动机：移除分词器

大多数预训练语言模型在对应于词或子词单元的 token 序列上运行，这要求分词器作为独立于模型的产物来构建。读取原始字节或字符的无分词器模型避免了这一流水线：它们开箱即可处理任何语言的文本，对噪声更加鲁棒，并且移除了作者称之为技术债务来源的易出错预处理。<sup>[1](https://arxiv.org/abs/2105.13626)</sup>

由于字节序列比 token 序列更长，早期的无分词器工作常常引入新架构来分摊在原始文本上运行的成本。ByT5 的核心结果是：标准 Transformer 架构只需极少的修改即可在字节上运行，并且当参数量、训练 FLOPs 和推理速度被明确刻画时，字节级模型与 token 级对应模型具有竞争力。<sup>[1](https://arxiv.org/abs/2105.13626)</sup>

## 设计与预训练

ByT5 沿用 mT5 的编码器-解码器设计和预训练目标，但将子词词表替换为 UTF-8 字节。词表为 256 个字节值加 3 个特殊 token；实现中存在一个词表外 token 但未被使用，因为每个 Unicode 字符都可分解为字节。模型只有 256 个 token 嵌入，没有位置嵌入。<sup>[3](https://github.com/will-thompson-k/tldr-transformers/blob/main/notes/byt5.md)</sup>

对于相同文本，字节序列的长度大约是子词序列的四倍，这减少了花在嵌入上的参数量。为保持比较公平，作者通过增加编码器深度（“重编码器”）并加宽模型和前馈维度，使每个 ByT5 规模的参数量与对应的 mT5 版本匹配。<sup>[3](https://github.com/will-thompson-k/tldr-transformers/blob/main/notes/byt5.md)</sup> 模型在 mC4 这一大型多语言语料库上预训练，采用跨度损坏（预训练任务：掩码并重建文本跨度）去噪目标，平均跨度掩码为 20 个 UTF-8 字符，训练 1,000,000 步，序列长度 1024，批大小 1,048,576 个 token。<sup>[6](https://huggingface.co/google/byt5-small)</sup><sup> • </sup><sup>[3](https://github.com/will-thompson-k/tldr-transformers/blob/main/notes/byt5.md)</sup> 由于模型仅在无监督数据上预训练，在下游任务使用前必须进行微调。<sup>[6](https://huggingface.co/google/byt5-small)</sup>

## 性能与权衡

**质量。** 参数匹配的 ByT5 模型在多种任务上与 mT5 相当，在涉及噪声文本或对拼写和发音敏感的任务上优于 mT5。<sup>[5](https://github.com/google-research/byt5)</sup> 模型卡给出了一个具体例子：google/byt5-small 在噪声文本基准 TweetQA 上显著优于 mt5-small。<sup>[6](https://huggingface.co/google/byt5-small)</sup>

**速度。** 字节级处理的代价体现在推理上。T5X 文档报告称推理比 mT5 显著更慢，视任务不同可慢至 10 倍。<sup>[7](https://github.com/google-research/t5x/blob/main/docs/models.md)</sup> 论文自身的测量显示这一代价因任务类型而异：在 Sigmorphon 2020 [字素到音素转换](https://www.edgepedia.org/zh/grapheme-to-phoneme-conversion)任务中（目标以[国际音标](https://www.edgepedia.org/zh/international-phonetic-alphabet)书写），ByT5 和 mT5 的推理速度相近；而在 Dakshina 音译任务上，ByT5 慢 1.5 至 2.6 倍。<sup>[9](https://doi.org/10.1162/tacl_a_00461)</sup>

**多语言性。** 字节级输入消除了共享子词词表在不同文字系统间引入的分词偏差，但并未消除各语言的成本差异：不同语言编码等价内容需要不同数量的字节，这一现象称为字节溢价。已报告的字节溢价包括缅甸语 3.51、宗喀语 3.64 和掸语 3.94，因此字节级分词器的溢价与其字节溢价相同。<sup>[10](https://openreview.net/pdf/ad885c101250e1c7b0540da17ae173dc4ed67e7c.pdf)</sup> 在 MASSIVE 多语言语义解析数据集的 51 种语言上，字节级 ByT5 与基于 wordpiece 的 mT5 在零样本、完整金数据和零样本加合成数据三种设置下进行了比较；在机器翻译样本上使用标签投影，将与用所有语言金数据训练的模型之间的精确匹配准确率差距缩小到仅 5 个百分点。<sup>[11](https://research.google/pubs/evaluating-byte-and-wordpiece-level-models-for-massively-multilingual-semantic-parsing/)</sup>

## 应用

ByT5 的噪声鲁棒性和文字无关输入使其成为字符级任务的常用基础模型。在大规模多语言字素到音素转换中，基于 ByT5 的模型在覆盖约 100 种语言的数据集上训练，显著优于基于 token 的 mT5；多语言 ByT5 模型通过跨语言联合学习，通常比单语言模型降低了音素错误率。<sup>[12](https://arxiv.org/abs/2204.03067)</sup> 在文本规范化方面，一个同时处理变音符号恢复和拼写纠错的 ByT5 模型在 13 种语言上达到超过 94% 的字母词准确率，尽管训练数据更少，其在基准数据集上的变音符号恢复效果与先前最佳水平相当。<sup>[13](https://arxiv.org/abs/2201.13242)</sup> 微调后的 ByT5 还被应用于楔形文字语言的词元还原和 OCR 后校正，其对这些任务的适用性正在于对字符级变化的容忍度。<sup>[14](https://aclanthology.org/2025.alp-1.26.pdf)</sup>

## 后续发展

主要局限——长字节序列——催生了后续工作。MrT5（MergeT5）是 ByT5 的更高效变体，在编码器中加入学习到的 token 删除门以动态缩短输入；在持续预训练中，它实现了推理运行时收益而对每字节比特数影响极小，能根据每种语言的正字法调整压缩率，并在 XNLI、TyDi QA 和字符级任务上匹配 ByT5 的准确率，同时将序列长度减少最多 75%。<sup>[15](https://arxiv.org/abs/2410.20771)</sup> 关于字节模型的比较研究强调，正确的评估取决于部署实际面临哪种约束，因为对于字节级模型，参数量、训练算力和延迟并不同步变化。<sup>[16](https://tensmag.com/byte-language-models-parameters-compute-latency-tradeoffs/)</sup>

## References

1. [Xue, L., Barua, A., Constant, N., Al-Rfou, R., Narang, S., Kale, M., Roberts, A., Raffel, C. (2021). ByT5: Towards a token-free future with pre-trained byte-to-byte models. arXiv:2105.13626.](https://arxiv.org/abs/2105.13626)
2. [Xue, L., et al. (2022). ByT5: Towards a Token-Free Future with Pre-trained Byte-to-Byte Models. Transactions of the Association for Computational Linguistics, 10:291–306.](https://aclanthology.org/2022.tacl-1.17/)
3. [will-thompson-k, tldr-transformers notes: byt5.md, GitHub.](https://github.com/will-thompson-k/tldr-transformers/blob/main/notes/byt5.md)
4. [byt5.base.gin, google-research/byt5, GitHub.](https://github.com/google-research/byt5/blob/master/byt5/gin/models/byt5.base.gin)
5. [google-research/byt5 repository README, GitHub.](https://github.com/google-research/byt5)
6. [google/byt5-small model card, Hugging Face.](https://huggingface.co/google/byt5-small)
7. [T5X models documentation, google-research/t5x, GitHub.](https://github.com/google-research/t5x/blob/main/docs/models.md)
8. [ByT5 documentation, Hugging Face Transformers.](https://huggingface.co/docs/transformers/v5.10.2/en/model_doc/byt5)
9. [ByT5: Towards a Token-Free Future with Pre-trained Byte-to-Byte Models, MIT Press DOI page.](https://doi.org/10.1162/tacl_a_00461)
10. [Paper on token premiums in subword and byte-level tokenizers, OpenReview PDF.](https://openreview.net/pdf/ad885c101250e1c7b0540da17ae173dc4ed67e7c.pdf)
11. [Nicosia, M., Piccinno, F. (2022). Evaluating Byte and Wordpiece Level Models for Massively Multilingual Semantic Parsing. Massively Multilingual NLU 2022 @ EMNLP.](https://research.google/pubs/evaluating-byte-and-wordpiece-level-models-for-massively-multilingual-semantic-parsing/)
12. [Zhu, J., Zhang, C., Jurgens, D. (2022). ByT5 model for massively multilingual grapheme-to-phoneme conversion. arXiv:2204.03067.](https://arxiv.org/abs/2204.03067)
13. [Stankevičius, L., et al. (2022). Correcting diacritics and typos with a ByT5 transformer model. arXiv:2201.13242.](https://arxiv.org/abs/2201.13242)
14. [Lemmatization of Cuneiform Languages Using the ByT5 Model, ACL Anthology 2025.alp-1.26.](https://aclanthology.org/2025.alp-1.26.pdf)
15. [Kallini, J., Murty, S., Manning, C. D., Potts, C., Csordás, R. (2024). MrT5: Dynamic Token Merging for Efficient Byte-level Language Models. arXiv:2410.20771.](https://arxiv.org/abs/2410.20771)
16. [Byte Models Need a Computing Budget, Not Just a Parameter Count, TENS Magazine.](https://tensmag.com/byte-language-models-parameters-compute-latency-tradeoffs/)

---
*Initially written Oct 15, 2026 · Edited: Oct 25, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 现代人工智能：基础模型、生成式人工智能与人工智能产业 › Model families and named models › Large language model families › Open-weight model families

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/byt5

English original: https://www.edgepedia.org/byt5
