Skip to main content
QUICK REVIEW

[论文解读] From Tokens to Words: On the Inner Lexicon of LLMs

Guy Kaplan, Matanel Oren|arXiv (Cornell University)|Oct 8, 2024
Natural Language Processing TechniquesComputer Science被引用 3
一句话总结

本文揭示了大型语言模型(LLMs)执行一种内在的去分词过程,主要在早期到中期层通过潜在内部词典从子词标记重构完整词表示。通过将多标记词表示融合为单一向量并将其注入模型的嵌入空间(无需微调),该方法减少了输入和输出序列长度,降低了推理延迟,同时保持或略微提升了模型性能——提供了一种实用的、无需参数的扩展LLM词汇量并提升效率的方法。

ABSTRACT

Natural language is composed of words, but modern large language models (LLMs) process sub-words as input. A natural question raised by this discrepancy is whether LLMs encode words internally, and if so how. We present evidence that LLMs engage in an intrinsic detokenization process, where sub-word sequences are combined into coherent whole-word representations at their last token. Our experiments show that this process primarily takes place within the early and middle layers of the model. We further demonstrate its robustness to arbitrary splits (e.g., "cats" to "ca" and "ts"), typos, and importantly-to out-of-vocabulary words: when feeding the last token internal representations of such words to the model as input, it can "understand" them as the complete word despite never seeing such representations as input during training. Our findings suggest that LLMs maintain a latent vocabulary beyond the tokenizer's scope. These insights provide a practical, finetuning-free application for expanding the vocabulary of pre-trained models. By enabling the addition of new vocabulary words, we reduce input length and inference iterations, which reduces both space and model latency, with little to no loss in model accuracy.

研究动机与目标

  • 探究 LLMs 是否在将单词分词为子词后,仍能内部重构出完整的词表示。
  • 理解该词级去分词过程在模型各层中的发生位置与机制。
  • 探究 LLMs 是否在分词器词汇范围之外仍保持一个潜在词汇表,包括对 OOV(未登录词)和拼写错误词的处理。
  • 开发一种无需微调的方法,利用融合的词表示扩展模型的输入和输出词汇。
  • 评估词汇扩展对推理效率、序列长度和模型准确率的影响。

提出的方法

  • 通过 k-最近邻分类评估隐藏表示中多标记真实词与非词的差异,探测中间层中的偏离,以检测词识别能力。
  • 使用可解释性技术将最后标记的隐藏状态解码为自然语言,证明在第 3 至 15 层后可重构出完整单词。
  • 分析前馈网络(FFN)更新,显示 85% 的词在其最后一个标记的残差流中被写入完整概念,表明其来自内部词典的检索。
  • 比较单标记词与多标记词的注意力模式,发现早期层中对前序子词的注意力更高,而后期层中注意力降低,表明初始聚合后发生抽象化。
  • 学习线性变换 $T_{\ell,E}$ 和 $T_{\ell,U}$,将融合表示映射到输入空间和未嵌入空间,实现无需微调即可使用新词汇条目。
  • 通过融合表示扩展模型的 BPE 词汇表,并通过 top-1 准确率和平均倒数排名评估性能,避免因词汇不匹配导致困惑度偏差。

实验结果

研究问题

  • RQ1LLMs 是否能内部重构出连贯的词表示,即使这些词是未登录词或非词素分裂的?
  • RQ2该去分词过程主要在模型的哪一层发生?
  • RQ3是否存在 LLMs 中存在超越分词器词汇范围的潜在内部词典的证据?
  • RQ4能否在不进行微调的情况下,将多标记词的融合表示注入模型的嵌入空间以提升推理效率?
  • RQ5通过融合表示扩展词汇是否能减少输入和输出序列长度,同时保持或提升模型性能?

主要发现

  • k-最近邻分类器基于隐藏表示对真实词与非词的区分准确率达到 89%,表明中间层存在强烈的词级表示。
  • 在所评估的 85% 的词中,完整词的概念通过 FFN 更新被写入最后一个标记的残差流,表明其来自内部词典的检索。
  • 对于多标记词,模型在第 1–2 层对前序子词标记的注意力显著更高,而在后期层中注意力降低,表明初始聚合后发生抽象化。
  • 通过线性变换 $T_{\ell,E}$ 和 $T_{\ell,U}$,模型成功将新添加的融合表示用作输入,并在 7.1% 的情况下以更高排名生成这些表示,优于原始子词标记。
  • 该方法在几乎不损失准确率的情况下减少了输入和输出序列长度与推理成本,甚至在语言建模任务中表现出轻微的性能提升。
  • 在添加新条目后,模型对原有词汇词的性能保持不变,证实无负面干扰。

阅读本论文

在 Nubint 阅读器中打开原文,边读边就任意段落提问。

在 Nubint 中阅读本论文

本解读由 AI 根据论文原文生成,引用前请核对原文。