← Latest papers
💬 NLP

How Do Transformers Learn to Associate Tokens: Gradient Leading Terms Bring Mechanistic Interpretability

This paper provides a mechanistic interpretation of how transformers learn semantic associations by deriving closed-form expressions for early-stage weights as compositions of bigram, token-interchangeability, and context mappings based on training gradient dynamics.

Original authors: Shawn Im, Changdae Oh, Zhen Fang, Sharon Li

Published 2026-05-14
📖 4 min read☕ Coffee break read

Original authors: Shawn Im, Changdae Oh, Zhen Fang, Sharon Li

Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer

Imagine a Transformer (the brain behind modern AI chatbots) as a giant, blank notebook. When we start training it, the pages are empty. The paper you're asking about asks a simple but profound question: How does this notebook learn to connect words like "bird" and "flew" just by reading millions of sentences?

Instead of looking at the finished, complex AI, the authors decided to zoom in on the very first few moments of learning. They used a mathematical "magnifying glass" to look at the first few steps the AI takes when it starts updating its memory.

Here is the breakdown of their discovery using simple analogies:

1. The "First Step" Shortcut

Training an AI is like trying to predict the next word in a sentence. Usually, the math behind how the AI updates its memory is incredibly messy and complex.

The authors realized that at the very beginning, the AI doesn't need to do complex calculus. It just needs to follow the strongest, most obvious signal in the data. They call this the "leading term." Think of it like a hiker starting a journey up a mountain. At the very start, the path is obvious and straight. It's only later, as they get higher, that the path gets twisty and complex. The authors proved that for a surprisingly long time, the AI's "memory weights" stay very close to that simple, straight initial path.

2. The Three Building Blocks

The paper reveals that the AI's memory isn't a random mess. Instead, it is built by stacking three specific types of " Lego blocks" (which the authors call basis functions). These blocks are derived directly from the statistics of the text the AI reads:

  • The "Next-Word" Block (Bigram Mapping):

    • Analogy: Imagine a child learning that "The" is almost always followed by a noun like "cat" or "dog."
    • What it does: This block simply records: "If you see word A, what is the most likely word B to come next?" It captures simple, immediate connections.
  • The "Swappable" Block (Interchangeability Mapping):

    • Analogy: Think of a thesaurus. If you can swap "car" with "truck" in a sentence without breaking the grammar, they are "swappable."
    • What it does: This block learns that certain words play the same role. If "red" usually describes a "car," and "fast" also describes a "car," this block helps the AI realize that "red" and "fast" might be related because they both hang out with the same words. It groups words by their function, not just their immediate neighbors.
  • The "Context" Block (Context Mapping):

    • Analogy: Imagine reading a story about a "fish." Even if the word "pond" isn't right next to "fish," the story might mention "water," "lake," or "boat" earlier.
    • What it does: This block looks further back in the sentence. It learns that if a word appears in a specific context (like a story about nature), it is likely to be associated with other words from that same context, even if they are far apart.

3. How They Work Together

The paper shows that the AI's internal "weights" (the numbers that determine how it thinks) are just combinations of these three blocks.

  • The Output Layer (the part that guesses the next word) is mostly just the Next-Word Block. It's the AI saying, "Based on what I just saw, what comes next?"
  • The Attention Layer (the part that decides what to focus on) is a mix of the Swappable and Context blocks. It's the AI saying, "I see the word 'fish.' I should look back at the word 'pond' because they often appear together in similar stories, even if they aren't touching."

4. The Proof: It Actually Works

The authors didn't just write equations; they tested this on real AI models.

  • They trained a small AI on a dataset of children's stories.
  • They compared the AI's actual learned memory against their mathematical formula.
  • The Result: The match was incredibly close (over 99% similarity in some cases). Even when they looked at a massive, real-world AI (Pythia-1.4B), the same patterns held true. The AI was indeed organizing its memory using these three simple statistical building blocks.

The Big Takeaway

The paper argues that we don't need to view AI as a mysterious "black box" that magically understands language. Instead, at its core, it is simply statistically organizing the world by:

  1. Noting what usually follows what.
  2. Grouping words that do the same job.
  3. Linking words that share a background story.

By understanding these three simple rules, we can finally see how the machine learns to associate "bird" with "flew" and "country" with "capital." It's not magic; it's a very structured way of summarizing the text it has read.

Drowning in papers in your field?

Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.

Try Digest →