← Latest papers
🤖 machine learning

Extracting Algorithms in Pre-trained LLMs: A Case on Hidden Markov Models

This paper bridges the gap between the in-context learning performance of pre-trained LLMs on Hidden Markov Models and their internal mechanisms by empirically narrowing down candidate algorithms, theoretically validating their Transformer implementation, and introducing a Principal Activations Probe to identify and causally manipulate the low-dimensional linear representations that drive these predictions.

Original authors: Yijia Dai, Zhaolin Gao, Yahya Sattar, Jennifer J. Sun, Sarah Dean

Published 2026-07-28
📖 6 min read🧠 Deep dive

Original authors: Yijia Dai, Zhaolin Gao, Yahya Sattar, Jennifer J. Sun, Sarah Dean

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 you are a detective trying to solve a mystery, but instead of looking for fingerprints, you are looking for the invisible "thoughts" inside a giant computer brain. This field of science is called mechanistic interpretability, and it asks a simple but tricky question: How does a machine actually think? To understand the mystery in this paper, we first need to know what the machine is trying to solve. It's playing a game called Hidden Markov Models (HMMs). Think of an HMM like a weather forecast where you can't see the sky. You only see the ground: is it wet or dry? Is the grass green or brown? The "hidden" part is the actual weather (sunny, rainy, cloudy) that you can't see, but which causes the ground to look the way it does. The computer's job is to look at a long history of wet grass and dry pavement and guess what the weather will be next.

For a while, scientists knew that giant Large Language Models (LLMs)—the super-smart AI chatbots we use every day—were incredibly good at this guessing game. As the context grew longer, their predictions approached the theoretical best possible performance (the "Oracle"), often matching or surpassing classical inference algorithms applied to the same data. But nobody knew how they were doing it. Did the AI secretly learn the rules of probability? Was it memorizing patterns? Or was it using some weird, brand-new trick? It was like watching a magician pull a rabbit out of a hat and having no idea if there was a hidden compartment, a second rabbit, or a magic spell. This paper is the first time researchers have successfully peeked inside the magician's hat to see exactly which trick the AI is using.

The researchers set up a massive experiment to figure out the AI's secret strategy. First, they tested the AI against a list of known "suspects"—different mathematical algorithms that humans use to solve this weather-guessing game. They found that no single human algorithm could explain the AI's behavior in every situation. Sometimes the AI acted like a simple pattern matcher, and other times it acted like a complex probability tracker. This narrowed the list of suspects down to three main types of strategies.

Next, the team asked a theoretical question: Could a Transformer (the specific type of AI architecture these models use) actually perform these three strategies? They proved mathematically that yes, it could. They even built a tiny, simple version of the AI and trained it on just one specific weather pattern. When they looked at this tiny AI's brain, they saw it had naturally learned to use a "finite-window" strategy—basically, it was looking at the last few clues (like the last 6 or 8 observations) to make its guess, rather than trying to remember the entire history of the universe.

But the real magic happened when they looked at the giant, pre-trained AI models (the ones that already know how to talk to us). They invented a new tool called the Principal Activations Probe (PAP). Imagine the AI's brain as a giant highway with 28 different lanes (layers). The PAP is like a sensor that can stop the traffic at any lane, check what information is flowing through, and even swap that information with a different scenario to see if it changes the AI's mind.

What they found was fascinating and a bit surprising. The AI doesn't use just one strategy all the time; it adapts its internal representation depending on how hard the puzzle is.

  • The Easy Mode: When the weather clues are very clear and the ground changes predictably (low "entropy"), the AI's behavior aligns with simple Bigram statistics. It effectively looks at the very last thing it saw to guess the next one.
  • The Hard Mode: When the clues are noisy and confusing (high "entropy"), the AI relies on a more complex strategy called Soft n-gram. It starts tracking a "belief" about the hidden state, integrating information over a short window of recent history. It's like realizing the ground is wet, but also remembering it was sunny yesterday, so it guesses "cloudy with a chance of rain."

Crucially, the researchers proved that the AI isn't just storing these beliefs; it's actually using them to make decisions. They did this by "patching" the AI's brain: they took the "belief" from a hard puzzle and pasted it into the brain while the AI was solving an easy puzzle. The AI's prediction immediately changed to match the hard puzzle's answer. This showed that the "belief" isn't just a side note; it's the engine driving the prediction. However, they also found a key distinction: in the "Hard Mode," the simple Bigram strategy is present in the early layers but is effectively bypassed by the model's downstream computation. The AI ignores the simple pattern in favor of the richer belief tracking only when genuine uncertainty requires it.

However, they also found a twist. In the early layers of the AI's brain, the "belief" information is there and easy to read, but the AI ignores it! It's like having a map on the dashboard but driving by looking out the window. The AI only starts using that map in the later layers of its brain. This means that just because you can find an idea inside a computer's brain doesn't mean the computer is actually using that idea to think.

In the end, the paper suggests that these giant AIs aren't running complex, perfect mathematical simulations of the world. Instead, they are learning to be very efficient approximators. They learn to look at a short window of recent history and update a "belief" about what's happening, much like a human might. They don't need to be perfect statisticians to be incredibly good at predicting the next word or the next weather event; they just need to be good at tracking the immediate past. This discovery helps us understand that the "magic" of these models is actually a very structured, understandable process of tracking patterns, which brings us one step closer to truly understanding how these digital minds work.

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 →