Jack Sparse'Row and the shape of Beliefs

TL;DR: In this notebook, we replicate and extend the work of Shape of Belief (Sarfati et Al, 2026).
It is well established that numbers in activation space are represented on a non-linear manifold, which can be detected using linear and categorical probes. This work shows that higher-level statistical concepts like the mean and variance of a time series have a similar representation. Additionally, it shows that existing steering techniques cannot change the belief of a model without changing it's uncertainty, and compare different steering methods that respect the manifold curvature. We extend this work by applying it to geographical data.

Introduction

Feel free to jump directly to Experimental setup
You are currently on Tensor Bay, a small but very popular island near the coasts of Silicium Valley. Among the farmers, the fishermen and the sea entrepreneurs, you try to find your way. Suddenly, you see before you a particularly dense crowd of people. They are all gathered around a stall and shouts ring out.
« 50 coins for the one among you that finds the exact number of beads in this jar ! » — 1438! — 800! — 1540! — 910! ...
Near the crowd, you immediately notice someone. He is tall and has a mechanical parrot on his shoulder. He does not even look at the jar. He smiles at you. A few moments later, after everyone made the predictions and the calm started to come back, he comes to the jar, takes the parrot off his shoulder and says, "I think Gemma wants to try."
Silence. Everyone is looking at the mechanical parrot. I noticed something and I think I am not the only one. The parrot seems to have no eyes at all.

— "863 ± 13.5"


After an even longer silence, I see, dumbfounded, the merchant hand the 50 gold coins to the stranger and his parrot. Intrigued, I walked straight to him and asked him who he is.
— Hi! I'm Captain Jack Sparse'Row, pirate of the activation space, explorer of the manifolds. To be honest, I'm quite a legend here, and not without reason. I can steer any enemy with one-neuron attacks. I reverse engineer vessels from their wrecks. I survived a gradient overflow by hiding in the KV cache, losing one eye for it.
You seem to be quite interested in my stochastic parrot, Gemma. It is a LLM, very good at speech, but still a bit dumb for vision. As you noticed, Gemma has no eyes, but very good hears. And it is very good at modeling uncertainty, even though it was not designed for it. I just discovered yesterday that it had this skill ! It's very easy to reproduce: take any LLM, pick any number ||(x||), generate a sequence of numbers with ||(x||) as the mean (typically using a gaussian distribution with some standard deviation ||(\sigma||)) and convert the sequence to text.
530,396,575,594,305,370,513,468,498,415,588,578,507,613,547,414,537,404,588,495
Can you tell which x was used in this example? It was generated with ||(x=500||) and ||(\sigma=100||)
Then, feed the first ||(K||) numbers in the sequence to your LLM, and look at which number it predicts next.
Note For stability, we don't just look at the number the LLM predicts with the highest probability, but we consider the M top predicted numbers and weight them using the model's probability.
You can even make the task harder and change the mean and ||(\sigma||) value mid-way:
I'm still investigating how Gemma is able to do that, and it's actually super interesting. You seem to be the kind of person that is curious and like adventure. Ready for the ride ?

How to probe LLMs

I assume you already met that kind of beast before, right ? Gemma is a tiny one compared to the monumental god-like species that you see in the ports, like CrabGPT or Clawde, but they work in the same way inside. Let's start with the basics to make sure we're on the same boat. A LLM (Large Language model) is trained to predict tokens (pieces of text, often words) with a very generic architecture. Picture it like this: the words are floating at the top, they are embedded in the network (i.e, they become vectors), and one layer after the other, the vectors for each of the words are updated to get richer meaning. Let me draw you a diagram on the sand:
diagram_e1 = mo.ui.anywidget(
    Excalidraw.from_file("assets/llm-intro.excalidraw", height=600)
)
diagram_e1
As you can imagine, we're mainly interested in the vectors associated with the last token, because that is what will be used to predict the next word. The interesting part starts here: how do you go from a word to a representation so complex that you can write the next word of a book, find the right answer to a biology problem, or count beeds ? How do concepts form inside the LLM ? Don't expect me to answer this question. Thousands of pirates are working on the problem right now, chasing a treasure without knowing how far away it lies. But we've made some progress, thanks to a very simple trick: probes.
To create a probe, you need a few ingredients:
  • a concept you want to track. Let's say, the sentiment of a sentence
  • positive and negative examples of this concept
  • access to the activations of the model (the vectors of each token in between layers)
With these, you can create small detectors to know if the model is thinking about a specific concept. We feed Gemma short pirate sentences, positive or negative, look at the last token's activation vector, and learn the pattern. (note: the animation below requires a good internet connection, or to run the notebook locally. sorry)
ticker.step = 10
As you can see, making a probe is very easy mathematically: just a regression. You can even get a good approximation by calculating the average of the vectors in the 'positive' and 'negative' groups, and it usually works fine. You have no idea how many times these small measuring tools saved my life. With probes, you can detect the direction of refusal inside a model, its emotional behaviour, wether it is lying, etc. And importantly for us, we can even detect ... numbers !
Note Using a regression to train a probe has a major flaw: overfitting. Indeed, the activation vectors of a LLM typically have ||(2048||) coefficients or more. Because of the Curse of Dimensionality, we can perfectly fit a probe on up to arbitrary 2049 points, with arbitrary labels ! To fight overfitting, there are 2 main solutions:
  1. Compute the direction using the difference of the mean point of the 2 groups (it is a better estimator because it reduces noise, see The Geometry of Truth)
  2. Use L2 regularization during the regression.
It is not a detail: without these techniques, you can get a probe that is pretty much unusable. We will use solution 2., like the paper does.

Experimental setup

Here is the experiment: we will chose beforehand a few values ||(\mu_1||), ||(\mu_2||) ... and sample values around them. Then, we will convert them to text and fed it to the parrot. Since we want to know how Gemmma represent uncertainty, we will also vary the variability of the sequences we generate. Finally, we will extract the activation at a specific layer.
Note Which token: In order to get the vector, we have to chose the token we're looking at. We could chose the last of the sequence, doing the average of all tokens, or even more complex strategies. For better stability, the paper uses the last K tokens of the seqence, and average them.
In order to understand the basics, we will a simpler setup first: take any 3-digit number, embed it in a sentence, and look at the corresponding representation. Note that we chose random templates to add variability, and see the representation of the number in various situations.
diagram_e3 = mo.ui.anywidget(Excalidraw.from_file("assets/experimental-setup-simple.excalidraw"))
diagram_e3
#diagram_e3.save()
We'll first generate these vectors and store them (at each layer). Click to start !
Mu values Sigma values Sequences per (mu, sigma) Averaging window Random seed
simple_layer_embeddings = simple_embeddings_at_layer(model_name, simple_layer_slider.value)

Numbers and curves

Now, we have everything to start studying our LLM. Let's focus on the simpler setup: 3 digits numbers. Let's train a single probe to predict the magnitude of the number.
Note Usually, probes detect binary labels (presence or absence of a concept) but we can of course predict values directly ! But as we will see, that's not the best way to do it.
Well, it seems to work extremely well ! Note that we are working in dimension ||(2048||), it's pretty easy to fit pretty much anything in this space ... That's why we added some validation points, and they seem to hold up. So we can detect how big a number is. But that's not the only thing we could want to detect ! What about this: "does the number end with a ||(7||)" ? Let's see.
It works perfectly too ! Let's call the probes we build ||(P_{size}||) and ||(P_7||) I have a puzzle for you: «can you organize the numbers in space, such that you can detect ||(P_{size}||) in one direction, ||(P_7||) in another ?» What shape do you get ? Think about it.
And with a bit more of probes magic, we can find a basis in which the numbes have exactly this shape:
simple_layer_slider
If you can remember only one thing, let it be that inside LLMs, numbers are curvy. You may wonder:
«Chosing to detect magnitude and last digit was pretty arbitrary, does that mean we can chose the probes to represent any shape we want ? Or is there a fundamental shape underneath ?»
You are right to be careful: probes are really useful to understand one particular facet of the model. You chose one direction to look at among the ten of hundreds of possible directions. But probes can't completely make up reality : There are some concepts that probes just can't detect (see example below).
A probe can't detect wether the sum of the digits is even or odd

The beautiful world of manifolds

So far, each number we considered was associated with a signle point in the latent space (the space of activations). That was fine for the simple version of the experiment, but not for the version with mean and variability. Let's say we train a probe ||(P_{big}||): «Is this number big, according to a human ?». Of course, the answer will depend on context:
  • "204 km" will fire it
  • "204 cm" will not
This shows that we can't think about ||(204||) as a single point. Instead, it's a set, or a region. It's the same thing for our ||((\mu, \sigma)||) experiment: there is not such a thing as the "||(\mu=204||)" point in our latent space. Instead, we can think of it as the set of all points with "||(\mu=204||)", with different values of ||(\sigma||). It's worth trying to visualize what we mean by that.
ManifoldWorld(is_3d=True, autoplay=False, canvas_width=900, js="remote")
ManifoldWorldProjection(is_3d=True, autoplay=False, canvas_width=900, js="remote")
Each ||(\mu=\mu_0||) is called a submanifold: a smooth region of the latent space. There is one last thing to understand here: where are our probes in this ? Easy: it's any direction that can linearly separate the submanifolds.
Notice how much information the probe loses: we can't know if the blobs are aranged in a straight line, or if they form a very complex pattern. We could improve this by computing local probes, but more on that later. And that's what the next experiment will show: stering !

Steering

The next experiment is the most interesting one I think. We will use the probe to directly modify the LLM internal representations. In the previous figure, it corresponds to translating a point in the direction given by the probe. This concept is called steering, and it's used to brain-wash LLMs in very different ways 🏴‍☠️ Let's see that in action: take ||((\sigma, \mu)||), look at the model prediction, push the activation vector, and see how that changes the model behaviour. Let's start very naive and use a linear probe.
Note Since a LLM compute the next token from every previous token, we could either steer the activations for the last token, or for multiple tokens. We also have to chose the layer at which we steer. Unfortunately, the paper stays unclear about what it used and why. Looking at the original code, it used layer 15 with steering on multiple tokens. We tried different settings and we found that:
  1. Steering works broadly better when using the last token only. For this reason, that's what we do in this notebook.
  2. Layer 15 is the second to last layer, which is not always where the richest internal representation are. We tried with layers 12 to 15, and for layer 12, the conclusions of the paper do not hold !. We still use layer 15 in this notebook, but it's still an open problem to know why steering behaves differently in earlier layers.
LAYER = 15
steer_mu = 350.0  # most illustrative starting point: farthest from the probe direction's midpoint
steer_max_alpha = 1000
plot_alpha_mu_curve(steering_df, steer_mu, steering_layer, probe_accuracy[steering_layer])
It works ! When we steer stronger (we translate the latent vector further), the mean outputed by the model increases. We're able to change its thoughts. Interestingly, the effect of the steering depends on ||(\sigma||), but we're still able to change ||(\mu||) as much as we want. Something we can't see from this experiment is how uncertain the model is. When we use ||(\sigma=200||), are the predictions of the model more spread-out than when ||(\sigma=20||) ? We can easily check, and it is indeed the case. The model learns to predict ||(\mu||), but also the correct ||(\sigma||). But now, look at what happens when we steer:
plot_steering_curve(steering_df, steer_mu, steering_layer, probe_accuracy[steering_layer])
We wanted to brain-wash the model so that it thinks the numbers have mean ||(\mu_0||), but at the same time we completely disrupted ||(\sigma||). Now the model thinks the mean is higher than it really is, but also more spread-out. Remember the 2 truths about Manifold exploration:
  1. Paths are curvy
  2. Probes show you a tiny part of reality
Basically, we tried to travel in a straight line, in a wavy ocean. It did not work. Below, I represented the 3d PCA of all the points. Remember that like probes, PCA shows only a tiny part of reality !
Note We're taking a path that is uncharted. The probes have no idea what is there, because they were never trained with points from this region. The manifold is so curvy that there may be all other sigmas on that path.

Zoo of steering techniques

As we saw previously, steering in a straight line does not work well. Can we do better ? Ideally, we would like to steer while following the curvature of the manifold. There are 2 main ways to do it:
  • chosing the direction that goes from one centroid to the next (piecewise-linear probes)
  • fitting a spline through the centroids to have a more precise direction at each point. This is what is used in the paper
Warning Quick aside: I lied a little bit about the way we construct probes. It was not strictly necessary in order to understand representation and steering, but it's an important detail if you want to dig deeper later. We construct a set of probes, one for each ||(\mu||). The role of each probe is to detect it's assigned mu, and to react to nothing else. It's essentially a training trick. You train the probes ||(W_{\mu}||) such that ||(Softmax(W_{\mu} x_0)||) gives you almost one for the ||(\mu||) associated with ||(x_0||) and 0 for the other. It is not very different from computing the centroids of each blob and working on them for steering. One reason why multi-category probes seeems to work better is that in the activation space, the norm of the vector is often useless. We only care about which direction the blobs are in. The paper is not 100% clear on this subject. Quoting:
In practice, we find one-vs-rest probes [the straight direction] to be less efficient to separate a specific class from all others. Hence we rely on the multiclass probe in what follows.
and
The steering directions are calculated from differences of point-probes [i.e, straight direction].
That means multi-class probes were used for preliminary analysis, supposedly because it worked better to separate classes, but then don't use them for steering. It can be true, but it would be worth explaining the difference between the 2 geometrically.
steering_variant_sigma = mo.ui.dropdown(
    [str(s) for s in sorted(experiment_config.sigma_values)],
    value="50.0",
    label="σ",
)
steering_variant_sigma

Extensions

Now you know the state of the art pirate knowledge about steering in uncertainty. But we could go deeper, a lot deeper.

Steering using the gradient

First, the best steering method we found was still disrupting ||(\sigma||) a lot. Since we have a white-box access to the model, we can do far better: we can compute the gradient w.r.t the sigma value the model will predict, and steer orthogonaly from the gradient. So we take the previous 'straight' steering direction, but at each steering step, we project it so that it's orthogonal to the gradient at that point.
Let's see how curvy the trajectory was (respecting curvature was the entire point after all)
It's almost Flat !
Note It's a quite surprising result. After all this adventure, the steering technique that works best give an almost flat trajectory. Here is the interpretation: the manifold space is huge. There are hundreds of different directions you can use to change ||(\mu||), not just one path. Among all these paths, there is one that is straight AND does not change ||(\sigma||). But the hard part is finding it. Also, note that the path depends on your starting point. there is no universal way to move on the manifold to preserve sigma.

Geographical belief

Hopefuly, bold explorer, now you understand how LLMs represent uncertainty. But that's not the end of the journey, I have something left to show you ... The ||((\mu, \sigma)||) experiment was what I would call a toy model: the smallest experiment that shows the phenomenon. But uncertainty and belief shows up everywhere. I will not stop at toy models: That's not the kind of thing that Jack Sparse'Row does ! In the next experiment, I took 90 cities across the earth, with their position on the globe. I also collected some monuments for each of these cities. Then, I pick a city (let's say London). I construct one of 2 different prompts: Coordinate-based prompt I take a point near London (randomly in a radius of 500km), translate it to Latitude/Longitude, and create the prompt:
"Lat 50.6508, Long -0.7508 is near the city"
Monument-based prompt I pick one random monument in the city and craft:
"Eltham Palace is a famous landmark near the city"
Then, I forward the prompt to the LLM, and I extract the activation vector from the last layer. I train a multi-category probe (90 categories) to predict which city I created the prompt from. Once the probe is trained, I take a new monument the probe has never seen, and look at the probability distribution over all the cities. From this probability distribution, I can compute:
  • the mean position on the sphere
  • the uncertainty about this position (spread)
And I can even do this at different scales by varying the temperature of the softmax. The intuition is that if the model and the probe are well calibrated, and if you ask where the Monaco is, you will get around 0.5 for "Paris" and 0.5 for "Rome", which is enough to get an approximate position.
Model's top guess: Delhi

Additional material

Writing this notebook was a lot of experimentation, both with the experiences of the paper itself, extensions we wanted to add, and ways to explain the concept that did not end up in the final version. This is bonus content, enjoy 😉

Intrinsic dimension and curviness

On thing the paper did and not us was measuring the "curviness" of the ||((\sigma, \mu)||) space. One cool think they observed was that the curviness (measured by the number of PCA dimensions needed to reach 95% explained variance) increased with the layers, and then decreased near the end. We did not reproduce this result, because we did not use enough ||(\mu||) values.
A black cell means all points are aligned. A large gray band means the variance is spread out between many dimensions.

Probes in your eyeballs

At one point, I thought that the best way to explain probes was to go with an analogy with the human eye: you have 3 detectors, and you want to reconstruct a single wavelength from them.
[11/22/26 22:31:06] INFO     Writing                     tex_file_writing.py:110
                             \special{dvisvgm:raw }4\special{d                        
                             visvgm:raw } to                                
                             media/Tex/b6e1e0d35a22cf8a.                        
                             tex                                                
[11/22/26 22:31:07] INFO     Writing                     tex_file_writing.py:110
                             \special{dvisvgm:raw }0\special{d                        
                             visvgm:raw } to                                
                             media/Tex/ab0de9a363d86c5f.                        
                             tex                                                
                    INFO     Writing                     tex_file_writing.py:110
                             \special{dvisvgm:raw }5\special{d                        
                             visvgm:raw } to                                
                             media/Tex/80535c2a91306081.                        
                             tex                                                
[11/22/26 22:31:08] INFO     Writing                     tex_file_writing.py:110
                             \special{dvisvgm:raw }6\special{d                        
                             visvgm:raw } to                                
                             media/Tex/5353eb619e9288a9.                        
                             tex                                                
                    INFO     Writing                     tex_file_writing.py:110
                             \special{dvisvgm:raw }7\special{d                        
                             visvgm:raw } to                                
                             media/Tex/9babf744f1d8badf.                        
                             tex                                                
I wanted to use them to explain how the probes for M (green) and L(red) are not very different, and that you could merge them into a single detector without losing too much information. It's related to how you can do a PCA on multi-linear field probes to get the most important variations.
make_channel_grey_fig("./assets/parrot.png")

Limitations of linear probes

There are really good reasons why we don't use linear probes everywhere, and instead use more complicated stuff. Indeed, linear probes can find directions that are not optimal in the sense of "Maximum variance direction", ie the first axis of a PCA. Here is the example Claude came up with (I'm pretty sure it's a well-known fact in the litterature, but I did not check)
Here, you see that the network learns a direction that align the points well with their associated values, not the direction in which the points are most spread-out. It also illustrate why ||(L_2||) normalization works here: if you force the weights to be smaller, the network will converge to the dotted line.

The true shape of belief, steering lies and gradient approximation

This question of "what is the true shape of the ||((\mu, \sigma)||) space" has driven me mad. I tried different visualizations, different kind of probes, non-linear projections ... But I was not able to really understand why going off-manifold in a straight line caused this change. Quick answer: we're not going in a straight line. I suspected it in the "gradient steering" experiment. If the representation was mainly preserved betweenlayer 15 and the last layer (before the unembedding matrix), that means we could compute the gradient on the last layer instead (which is way easier) and apply it. But that does not work: there is something mysterious, and non-linear, going on in the last layer. Said differently, the "Lens Hypothesis" (The layers have the same representation basis) is clearly invalidated here. It would be a new paper alltogether to investigate this fact (probably an **attention head or the MLP block doing something weird), but I can at least illustrate why steering does not move in a straight line.
On this figure, you can see the 3 sigma paths, but this time in a different space: directly from the last layer. Let's be precise about what is going on:
  • we're intercepting the activations at layer 15 and 16
  • we're computing the steering direction in this space
  • we're applying the steering
  • we compute the resulting position (post-steering) at layer 16
And then we're plotting everything on layer 16. We're also adding the directions of increasing sigma as arrows, using the gradient. The plot on the left use a basis derived from the PCA of the points (more honnest about the "true" position in the space), the plot on the right uses the PCA of the gradients instead (more honnest about the real gradient direction and magnitude at each point). For me, these 2 plots give the full story. Here is my interpretation:
  • The "sigma" gradient vector field is very curvy indeed in the region we're interested in. Worse, it varies faster in some regions than in other.
  • the "straight" direction we chose was not orthogonal to the gradient. So obviously, it increased from the start. In comparison, the piecewise linear path (dotted path) deviated less from the target path.
  • both the straight and piecewise steering techniques produce a non-straight path on layer 16, i.e the layer applies a strong non-linearity.
  • For some reason, the straight steering produces a path that looks straight in the 2d PCA given by the gradients ‽‽‽
  • As we discussed earlier, the steering works less as we move into previous layers. That seems to indicate that the non-linearity accumulates rapidly with layers.
As often with research, more questions than answers ! But that's the interesting thing right ?

FAQ

How did you make the gorgeous 3D graphics and animations?

Most of the 2d plots were done with matplotlib. A good color scheme and a few layout tweaks really go a long way. The 3d scenes are all done using Manim. However, you may have noticed that they are not pre-recorded, and even that some of them are interactive. That's the project I've been working on for months: manim-widget. It's now in alpha, I hope you will love it.

How did you use AI?

We really care a lot about responsible AI use in this team. One of us work as a AI safety researcher, the other in explainable AI and advocacy (via pauseIA) But of course, we used AI extensively (with marimo-pair) for this project. We followed the following principle:
  • promote Human culture and fullfilment: no AI generated art, all images are hand-drawn
  • 0% AI writing. AI are so bad at writting and narrative work, when they don't clearly gaslight you
  • avoid code SLOP: review the core functions, be clear about architecture

Do you have suggestions to improve marimo?

Yes, a lot ! Currently you can't use #sectionName to jump to a header with marimo. that would be really cool if you could do that, to point to a specific section of the notebook with a url.

Style

The default style of marimo is good, not great. For this notebook we increased font size, font family and a few other tweaks. It usually works well with custom CSS sheets, but unfortunately it does not work on molab. And sometimes it makes more sense to have the style of an element be defined in your notebook directly. We hacked together a "style-injection widget", but it would be nice to have that kind of thing built-in to marimo.

Elements

In this notebook there are a few custom widget that could live inside wigglystuff or even marimo core elements.
  • the Ticker widget that reruns descendents a given number of times
  • a spoiler element that hides your widget before the user clicks 'reveal'

Core and animations

Better support for streaming animations ? I don't know what that could look like but being able to construct matplotlib animations easily would be great.

Who are you ?

We're 2 students, both aspiring researchers. Find us here: If by any chance you want to propose us an internship or a thesis, reach out at antonin.peronnet@telecom-paris.fr