What the Weights Remember: I Read a Neural Network's Game from Its Weights, Then Hand-Wrote One That Beat Training

Dark cover with rows of raw weight values on the left and two heatmaps on the right showing the agent channel of a Catch network lit along the bottom row and of a Freeway network lit down one column
Two trained networks, seen only through their weights. Where the agent can be is burned into the first layer.

Last week a programmer wrote up Qwen 3.8 27B on my laptop can interpret model weights, too. It is about the paper Sparks of Weight-Space Programming by Rikiya Takehi, Jayden Teoh, Alex Zhang and Omar Khattab, which showed frontier models looking at nothing but the raw floating point weights of a small game-playing network and saying which game it was trained to play. Simon pasted the paper's Pac-Man prompt into Qwen running on his laptop, and 46 minutes and about 43,000 reasoning tokens later it said Pac-Man.

I read his post twice. Then I did not reach for a model. The question that would not leave me alone was simpler and more stubborn: why is this possible at all? A trained network is supposed to be an opaque pile of numbers. If a language model can read the game out of it with no tools, the information has to be sitting in those numbers in a fairly plain form. So I spent the weekend putting it there myself, finding it again with a forty-line script, and then going the other way: writing a network's weights by hand, with no training, and seeing whether it could beat one that was trained.

It could. Here is the whole thing.

The setup: two tiny games

I wanted something small enough to look at with my own eyes, so I copied the shape of the paper's experiment and shrank it:

  • A 10×10 grid, encoded as three channels: where the agent is, where the moving objects are, and where the moving objects were one frame ago. The last channel is what lets a network see motion.
  • Catch: a one-cell paddle on the bottom row moves left, stays or moves right. A ball falls from the top with a random sideways drift and bounces off the walls.
  • Freeway: the agent lives in column 4 and moves up, stays or moves down, trying to cross eight lanes of cars that slide left and right. Get hit and you go back to the start.

The input to the network is those 300 numbers flattened. The flattening formula matters later, so here it is:

index(row, col, channel) = (row · 10 + col) · 3 + channel

If you read the reasoning trace in Simon's post, you can watch Qwen rediscovering exactly this kind of formula from the prompt's description: "381//5=76 (row7 col6), ch1". Half of weight reading is index arithmetic.

The networks are as plain as networks get: 300 inputs, 32 hidden ReLU units, 3 outputs. That is 9,731 weights and biases. One honest difference from the paper: I did not use reinforcement learning. I wrote a perfect scripted player for each game and trained the networks to copy it (behaviour cloning, 27,000 Catch states and 24,000 Freeway states). It is faster, it is deterministic, and it does not change the question I care about, which is what training leaves behind in the weights.

class MLP:
    def __init__(self, rng, hidden=32):
        self.W1 = rng.normal(0, 0.1, (300, hidden))
        self.b1 = np.zeros(hidden)
        self.W2 = rng.normal(0, 0.1, (hidden, 3))
        self.b2 = np.zeros(3)

    def forward(self, X):
        h = np.maximum(0, X @ self.W1 + self.b1)
        return h, h @ self.W2 + self.b2

    def train(self, X, y, epochs=40, lr=0.01, decay=1e-3, batch=128):
        ...   # softmax cross-entropy, Adam, and L2 weight decay — the decay matters, see below

Both trained networks play well. Over 2,000 games of Catch and 300 runs of Freeway (60 steps each):

Player Catch: balls caught Freeway: crossings per run
random actions 10.3% 0.03
trained network 96.8% 5.73
scripted expert it copied 100.0% 5.76

Why the weights remember the game

This is the part that made the paper click for me. Look at the gradient of the loss with respect to a first-layer weight:

∂Loss / ∂W1[i, h]  =  x_i · δ_h

Here x_i is input i and δ_h is the error signal arriving at hidden unit h. If input i is always zero in the training data, its weights get no gradient at all. Ever.

In Catch, the agent channel is only ever lit on row 9, because the paddle never leaves the bottom row. So the 90 agent-channel inputs for rows 0 to 8 never receive a single update. Add weight decay, which shrinks every weight a little on every step,

W  ←  W − η · (gradient + λ · W)

and those never-used weights quietly decay towards zero while the used ones are held up by the gradient. After training, the first layer is a fossil record of where things could be. You do not need to understand what the network computes. You only need to see which inputs it ever learned to care about.

To make that visible I scored each input cell by how much it can move the outputs:

importance(i)  =  Σ_h |W1[i, h]| · ‖W2[h, :]‖
Six heatmaps in two rows. For Catch, the agent channel lights up only along the bottom row while the ball channels are bright across the rows above it. For Freeway, the agent channel lights up only in column 4, the car channel only in columns 3 and 5 alternating by lane, and the last-frame car channel in columns 2 and 6
The importance of every input cell, computed from the weights alone. The agent channel draws a line: a row for Catch, a column for Freeway.

That picture is the whole trick. The agent channel draws a line. Catch draws a horizontal line on the bottom row, Freeway draws a vertical line in column 4. Rows the paddle never visits and columns the Freeway agent never visits are pure black: those weights decayed to nothing.

The object channels tell the rest of the story, and Freeway's surprised me. Catch cares about the ball almost everywhere above the bottom row, because a falling, bouncing ball can be anywhere and anywhere matters. Freeway's network ignores most of the road. It only looks at column 3 in odd lanes and column 5 in even lanes. That is not noise. Cars in odd lanes drive right and cars in even lanes drive left, so those are precisely the cells from which a car will slide into the agent's column on the next step. The last-frame channel lights up one cell further out, in columns 2 and 6, which is where a dangerous car was a frame ago. The direction of traffic in every lane is written into the weights, and so is the rule the network learned: only the car about to arrive matters. Nobody told it either.

A forty-line weight reader

Once you know the fossil is there, reading it is mechanical:

def importance(net):
    return (np.abs(net.W1) @ np.linalg.norm(net.W2, axis=1)).reshape(10, 10, 3)


def read_game(net):
    agent = importance(net)[:, :, 0]
    share = agent / agent.sum()
    row_share, best_row = share.sum(1).max(), share.sum(1).argmax()
    col_share, best_col = share.sum(0).max(), share.sum(0).argmax()
    if row_share > col_share:
        return f"agent lives on row {best_row} and moves sideways: a paddle game like Catch or Breakout"
    return f"agent lives in column {best_col} and moves up and down: a crossing game like Freeway"

What it said, given only the weights:

catch net:   99.9% of the agent channel's importance is in row 9
             → agent lives on row 9 and moves sideways: a paddle game like Catch or Breakout
freeway net: 99.9% of the agent channel's importance is in column 4
             → agent lives in column 4 and moves up and down: a crossing game like Freeway

Both right, in milliseconds, no model involved.

I want to be fair about what this does and does not show. My reader knows the encoding, because I wrote it. It only distinguishes "moves along a row" from "moves along a column". Point it at a Pong network, where the paddle moves up and down a column, and it would happily say Freeway. Telling Pong from Freeway needs a second look, at the object channels: a ball that matters anywhere on the field, versus cars that only matter on the cells next to the agent's column, alternating by lane. And connecting "a paddle on the right edge intercepting a ball" to the word Pong is world knowledge, not arithmetic.

That is exactly the part the language model brings. When Qwen spends 46 minutes on the problem, I think it is doing what my script does, finding which inputs carry weight and decoding their positions, except by hand, in text, with the arithmetic done one token at a time, and then adding the step my script cannot: recognising the shape of a known game. It also explains the cost. My first layer alone, written out as text with three decimals, is 74,662 characters, roughly 24,887 tokens at three characters a token, before the model has thought a single thought.

Going the other way: writing weights by hand

The paper's more provocative claim is that a model can write small networks from scratch that play well. I wanted to feel what that means, so I tried it myself, as a human, for Catch.

Version 1: chase the ball

The obvious network: count the ball's column, count the paddle's column, move towards the ball. With one-hot inputs, "the ball's column" is a sum of step functions, so twenty hidden units do it, ten for the ball and ten for the paddle:

# hidden unit k fires when the ball is in column >= k; unit 10+k when the paddle is
for r in range(10):
    for c in range(10):
        for k in range(1, 10):
            if c >= k:
                W1[(r * 10 + c) * 3 + 1, k] = 1.0       # ball channel
                W1[(r * 10 + c) * 3 + 0, 10 + k] = 1.0  # agent channel
W2[:10, 2], W2[10:, 2] = 1, -1     # right = ball_col - paddle_col
W2[:10, 0], W2[10:, 0] = -1, 1     # left  = paddle_col - ball_col
b2 = [0, 0.5, 0]                   # stay wins a tie

It caught 33.1% of balls. Better than random, much worse than training. Watching it play showed why immediately: it chases where the ball is, but a drifting ball is somewhere else by the time it lands, and a bounce sends the paddle the wrong way entirely.

Version 2: predict where it lands, with five neurons

So the network has to do physics. Without walls, the landing column is the current column plus the drift times the rows left to fall, and the drift is just the column now minus the column one frame ago:

L  =  c + (c − c_prev) · (9 − r)

That looks like it needs multiplication, which a single layer of weights cannot do. But the inputs are one-hot, and the previous ball was always one row higher, so the formula splits into a separate contribution from each lit cell:

ball cell (r, c)            contributes   c · (10 − r)
last-frame cell (r', c')    contributes  −c' · (8 − r')

Those become first-layer weights directly. The walls are the interesting part. A bounce reflects the landing column, which turns the straight line L into a triangle wave: |L| below zero, 18 − L above nine. A triangle wave is piecewise linear, and piecewise linear is exactly what ReLUs are for:

landing(L)  =  (relu(L + 20) − 20)  +  2·relu(−L)  −  2·relu(L − 9)  +  2·relu(L − 18)
Plot of landing column against L: a dashed diagonal for the no-walls prediction, and an orange line built from four ReLUs that follows it between 0 and 9, reflects upward below 0 and downward above 9, matching the dotted true bounce
Four ReLU units fold the straight-line prediction into the bouncing one. The shaded band is the board.

Four hidden units for the folded landing column, one for the paddle's column, and the outputs compare them:

W1[:] = 0
for r in range(10):
    for c in range(10):
        ball, prev = c * (10 - r), -c * (8 - r)
        for unit, sign in [(0, 1), (1, -1), (2, 1), (3, 1)]:
            W1[(r * 10 + c) * 3 + 1, unit] = sign * ball   # ball channel
            W1[(r * 10 + c) * 3 + 2, unit] = sign * prev   # last-frame channel
        W1[(r * 10 + c) * 3 + 0, 4] = c                   # paddle column
b1 = [20, 0, -9, -18, 0]

fold = np.array([1, 2, -2, 2, 0])
paddle = np.array([0, 0, 0, 0, 1])
W2[:, 0] = paddle - fold      # left  = paddle - landing
W2[:, 2] = fold - paddle      # right = landing - paddle
b2 = [20, 0.5, -20]           # cancels the +20 offset of unit 0; stay wins a tie
Bar chart of balls caught: random 10.3 percent, hand-written chase version 33.1 percent, trained network with 9,731 weights 96.8 percent, hand-written five-neuron version 98.5 percent, scripted expert 100 percent
Five hand-set neurons beat the 32-neuron network trained on 27,000 examples.

98.5% caught. The five hand-written neurons beat the trained network, which has six times as many hidden units and saw 27,000 examples. It still misses a few, and I know exactly which: on the very first frame there is no previous position, so it guesses no drift, and when a bounce happens between two frames its drift estimate has the wrong sign for one step. I know that because I can read every one of its weights. I cannot say the same for the trained one, which gets 96.8% for reasons spread across 9,600 numbers.

This is the same flavour of result as the paper's game-playing networks that beat PPO, at toy scale and with me doing the reasoning. Which is the point: it is reasoning about what each part of the network should compute, written down as numbers. A model that can do the algebra above can write these weights. It does not need to be magic to do it.

What I actually think

  • Weight reading on small networks is real, and it is less mysterious than it sounds. Training leaves a fossil of the input distribution in the first layer. Find which inputs carry weight, decode their positions, and you know a lot about the world the network lived in. An LLM does this the slow way, in text, and adds the knowledge of which known game has that shape.
  • Scale is the open question. The fossil is easy to see when the input is a 10×10 grid and the network has one hidden layer. It is not at all obvious this carries over to a billion-parameter model with superposition everywhere. I would like to see that before believing the bigger claims.
  • Writing weights is programming. My five-neuron Catch player is a program. I wrote it in an unusual language, where if is a ReLU and a variable is a hidden unit, but every weight has a reason. Like, I am not ready to declare the end of source code. If anything this made me want more of it: the network I understand is the one I can fix.
  • Matthew Honnibal's point stands. The paper puts two things under one heading: models reading weights with no tools, and models editing other models with code and evaluation. They deserve to be judged separately. This post is only about the first, plus one human doing the second by hand.

Run it yourself

The whole experiment is about 250 lines of numpy, with no deep learning framework: both games, the scripted experts, the MLP with Adam and weight decay, the reader and both hand-written players. Training both networks and playing a few thousand evaluation games takes under a minute on my laptop. If you want to try the LLM side as did, dump W1 as text in the paper's prompt format and ask your local model which game it is. Then compare its reasoning trace with the heatmap above. I am fairly sure you will see it hunting for the same line.

Credit where it is due: the idea and the experiment design come from the paper by Takehi, Teoh, Zhang and Khattab and their prompt logs on GitHub, and the push to try it on a laptop came from Simon's post. The games, the reader and the hand-written networks here are mine.