---
title: "Token (LLM) — 词元"
source: "https://systems-analysis.info/int/Token_(LLM)_%E2%80%94_%E8%AF%8D%E5%85%83"
wiki: "systems-analysis.info/int"
article: "Token_(LLM)_—_词元"
language: "zh"
categories:
  - "Category:Chinese"
  - "Category:Large language models"
  - "Category:LLM core concepts"
  - "Category:Machine learning"
revision_id: 8118
wiki_created_at: 2026-09-07T01:12:36Z
wiki_modified_at: 2026-09-07T01:12:36Z
downloaded_at: 2026-09-07T23:23:27Z
---

# Token (LLM) — 词元

**词元 (token)** — 是大型语言模型 (LLM) 能够处理的最小文本单位。任何文本在被 LLM 处理之前，都会先被转换成一个词元序列，这些词元随后被转换为数字表示，以便于模型进行分析和处理。

根据所使用的词元化策略，词元可以是：

- 整个词（例如，“房子”）
- 词的一部分或词根（例如，“run” 在 “running” 中）

<!-- -->

- 单个字符或标点符号（例如，“,”，“!”）

使用词元使语言模型能够有效地学习和再现文本结构、识别模式，并理解文本的语义和语法。

## 词元化过程

**词元化** (tokenization) — 是将原始文本分割成词元，并随后将其转换为模型可理解的数字标识符的过程。

这一阶段对于大型语言模型的运作是必不可少且基础的。通过词元化，LLM 能够：

- 分析语法 — 文本的结构以及元素（词和短语）的排列；
- 提取语义 — 文本的深层含义以及元素之间的相互关系。

词元化有几种主要方法，其中包括：

- **Byte Pair Encoding (BPE)**: 一种迭代算法，它将最常见的字符对替换为新的词元，从而能够有效处理罕见词和词形变化。
- **WordPiece**: 用于 BERT 等模型，将单词分解为子词单元，这有助于处理未知词汇。
- **SentencePiece**: 一种将文本视为字符序列的方法，并应用基于 BPE 或 Unigram 的模型进行词元化。

词元化方法的选择会影响模型的性能、其处理不同语言的能力以及训练效率。

## 特殊词元

除了基本词元外，模型还使用特殊词元来表示文本的功能性元素，例如：

- `[CLS]` (class) — 序列开始词元，常用于文本分类任务；
- `[SEP]` (separator) — 分隔文本的不同部分（例如，问题和答案、句子或段落）；
- `[MASK]` — 用于表示模型需要预测的词的特殊词元（在 BERT 和其他掩码语言模型中使用）；
- `[PAD]` (padding) — 用于将文本填充对齐至相同长度。

这些特殊词元帮助模型更准确地感知所处理文本的结构和上下文。

## 词元与上下文窗口

**上下文窗口** (context window) — 是模型在生成文本时能够同时考虑和处理的最大词元数量。

例如，GPT-3 模型的上下文窗口大小为 2048 个词元。这意味着在生成文本时，模型最多可以同时考虑包含在 2048 个词元中的信息。上下文窗口的大小影响：

- 模型可用的最大信息量；
- 生成答案的质量和连贯性；
- 模型理解长文本并在词元之间保持远距离上下文的能力。

## 参考文献

- Sennrich, R.; Haddow, B.; Birch, A. (2016). *Neural Machine Translation of Rare Words with Subword Units*. <a href="https://arxiv.org/abs/1508.07909" class="external text" rel="nofollow">arXiv:1508.07909</a>.
- Kudo, T.; Richardson, J. (2018). *SentencePiece: A Simple and Language-Independent Subword Tokenizer and Detokenizer for Neural Text Processing*. <a href="https://arxiv.org/abs/1808.06226" class="external text" rel="nofollow">arXiv:1808.06226</a>.
- Kudo, T. (2018). *Subword Regularization: Improving Neural Network Translation Models with Multiple Subword Candidates*. <a href="https://arxiv.org/abs/1804.10959" class="external text" rel="nofollow">arXiv:1804.10959</a>.
- Devlin, J. et al. (2019). *BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding*. <a href="https://arxiv.org/abs/1810.04805" class="external text" rel="nofollow">arXiv:1810.04805</a>.
- Song, X. et al. (2021). *Fast WordPiece Tokenization*. \*EMNLP 2021\*. <a href="https://aclanthology.org/2021.emnlp-main.160.pdf" class="external text" rel="nofollow">ACL Anthology</a>.
- Mielke, S. J.; Dalmia, S.; Cotterell, R. (2021). *A Brief History of Open-Vocabulary Modeling and Tokenization in NLP*. <a href="https://arxiv.org/abs/2112.10508" class="external text" rel="nofollow">arXiv:2112.10508</a>.
- Xue, J. et al. (2022). *ByT5: Towards a Token-Free Future with Pre-trained Byte-to-Byte Models*. <a href="https://arxiv.org/abs/2105.13626" class="external text" rel="nofollow">arXiv:2105.13626</a>.
- Limisiewicz, T.; Balhar, J.; Mareček, D. (2023). *Tokenization Impacts Multilingual Language Modeling: Assessing Vocabulary Allocation and Overlap Across Languages*. <a href="https://arxiv.org/abs/2305.17179" class="external text" rel="nofollow">arXiv:2305.17179</a>.
- Pourmostafa Roshan Sharami, J.; Shterionov, D.; Spronck, P. (2023). *A Systematic Analysis of Vocabulary and BPE Settings for Optimal Fine-tuning of NMT*. <a href="https://arxiv.org/abs/2303.00722" class="external text" rel="nofollow">arXiv:2303.00722</a>.
- Batsuren, K. et al. (2024). *Evaluating Subword Tokenization: Alien Subword Composition and OOV Generalization Challenge*. <a href="https://arxiv.org/abs/2404.13292" class="external text" rel="nofollow">arXiv:2404.13292</a>.
- Chai, Y. et al. (2024). *Tokenization Falling Short: On Subword Robustness in Large Language Models*. <a href="https://arxiv.org/abs/2406.11687" class="external text" rel="nofollow">arXiv:2406.11687</a>.
