Skip to main content
QUICK REVIEW

[Paper 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 Science3 citations
TL;DR

This paper reveals that large language models (LLMs) perform an intrinsic detokenization process, reconstructing full word representations from sub-word tokens primarily in early-to-mid layers using a latent inner lexicon. By fusing multi-token word representations into single vectors and injecting them into the model's embedding space without fine-tuning, the method reduces input and output sequence length, cuts inference latency, and maintains or slightly improves model performance—offering a practical, parameter-free way to expand LLM vocabulary and boost efficiency.

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.

Motivation & Objective

  • To investigate whether LLMs internally reconstruct full word representations from sub-word tokens despite tokenization into sub-words.
  • To understand where and how this word-level detokenization process occurs across model layers.
  • To explore whether LLMs maintain a latent vocabulary beyond the tokenizer’s scope, including for out-of-vocabulary words and typos.
  • To develop a finetuning-free method to expand the model’s input and output vocabulary using fused word representations.
  • To evaluate the impact of vocabulary expansion on inference efficiency, sequence length, and model accuracy.

Proposed method

  • Probing hidden representations of multi-token real words and nonwords to detect divergence in middle layers, using k-NN classification to assess word recognition.
  • Using interpretability techniques to decode hidden states of the last token into natural language, demonstrating reconstruction of full words after 3–15 layers.
  • Analyzing feedforward network (FFN) updates to show that 85% of words have their full concept written to the last token’s residual stream before emergence.
  • Comparing attention patterns between single-token and multi-token words, finding increased attention to prior sub-words in early layers and decreased in later layers.
  • Learning linear transformations $T_{\ell,E}$ and $T_{\ell,U}$ to map fused representations into input and unembedding spaces, enabling use of new vocabulary entries without fine-tuning.
  • Expanding the model’s BPE vocabulary with fused representations and evaluating performance via top-1 accuracy and mean reciprocal rank, avoiding perplexity due to vocabulary mismatch.

Experimental results

Research questions

  • RQ1Do LLMs internally reconstruct coherent word representations from sub-word tokens, even when those words are out of vocabulary or split non-morphemically?
  • RQ2At which layers of the model does the detokenization process primarily occur?
  • RQ3Is there evidence of a latent inner lexicon in LLMs that extends beyond the tokenizer’s vocabulary?
  • RQ4Can fused representations of multi-token words be injected into the model’s embedding space without fine-tuning to improve inference efficiency?
  • RQ5Does expanding the vocabulary with fused representations reduce input and output sequence length while maintaining or improving model performance?

Key findings

  • A k-nearest neighbors classifier achieved 89% accuracy in distinguishing real words from nonwords based on hidden representations, indicating strong word-level representation in middle layers.
  • For 85% of evaluated words, the full word concept was written to the last token’s residual stream via FFN updates, suggesting retrieval from an inner lexicon.
  • The model attends significantly more to preceding sub-word tokens in layers 1–2 for multi-token words, but less in later layers, indicating initial aggregation followed by abstraction.
  • Using linear transformations $T_{\ell,E}$ and $T_{\ell,U}$, the model successfully utilized newly added fused representations as inputs and generated them with higher rank than original sub-word tokens in 7.1% of cases.
  • The method reduced input and output sequence length and inference cost with minimal to no loss in accuracy, and even showed slight performance improvements in language modeling tasks.
  • The model maintained performance on existing vocabulary words when new entries were added, confirming no negative interference.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.