Don Stephenson Don Stephenson

Warp, Shift, Fold

What one layer does to space

The large language models behind modern AI are trained, not programmed. No one writes the rules for answering a question, summarizing a report or translating a sentence. Instead, a model is shown a vast amount of text and adjusted, by small increments, until its predictions come out right. What is adjusted is an artificial neural network: a stack of simple, identical stages called layers. The network is the model's memory. Everything it has learned is stored there, not as facts in a table but as hundreds of millions of numbers that determine how each layer transforms its input. This station examines a single layer and shows what it does. The answer is surprisingly physical: a layer moves points around in space.

Everything is a point

A network never sees words or pictures, only lists of numbers, and every list of numbers is a point in space. Two numbers define a point on a plane. The language model behind this site represents each piece of text as a list of 896 numbers: a point in a space with 896 directions. That space cannot be pictured, but the rules that move points within it are exactly the rules this station demonstrates on a plane.

The task, seen as geometry

Suppose some points are labelled "yes" and others "no". The simplest possible decision is a single straight cut, with everything on one side "yes" and everything on the other "no". Often no straight cut suffices, because the two kinds of point are intermingled. The essential work of a network is to move the points until a straight cut does suffice, with each layer carrying them further toward that arrangement. For a language model the question is not yes or no but "which token comes next?", and step 7 shows that it is answered in the same way.

Three moves per layer

Every layer transforms space in exactly three ways, always in this order:

  • Warp: stretch, rotate, slant or flip the whole plane, keeping every straight line straight.
  • Shift: translate every point by the same amount.
  • Fold: crease the plane so that some regions land on top of others.

The first two belong to long-established mathematics. The third is what makes a network a network, and the station shows why it cannot be omitted.

Two different times: training and answering

Much writing about networks does not say which of two very different phases it refers to, and explanations often falter on that ambiguity. This station states the phase at each point.

  • Answering (formally, inference) occurs every time a model is used. Its numbers are fixed. Text goes in, every layer applies its warp, shift and fold, and a prediction comes out. Every move in this station is something that happens during answering.
  • Training occurs before a model is released, and it is slow and expensive. The model processes training text, its predictions are compared with what actually followed, and every number is adjusted slightly so that the prediction would have been better. Training never introduces new kinds of move. It only chooses the numbers within them: how far to warp, how far to shift.

In this station you take both roles. Dragging a slider performs training's task by hand, choosing the numbers; watching the grid move is answering, the application of those numbers. The Training or answering? notes mark the distinction where it matters.

Where the idea comes from

The single straight cut is Rosenblatt's perceptron (1958). Minsky and Papert (1969) proved that a single cut cannot solve some very simple problems, and that result shaped the field for more than a decade. The remedy, layers that move the points before the cut is made, became practical with the spread of backpropagation in the 1980s and is the basis of every network in use today.

The claim under test

One warp, one shift and one fold suffice to take three clusters in a row (blue, orange, blue), which no straight line can separate, and make them separable by a single straight cut. Step 6 asks you to do it by hand and then shows what that straight cut looks like on the original plane. It is no longer straight.

The route

  1. The warp: drag two arrows, and the whole grid follows.
  2. The shift: move the origin, and follow one point's arithmetic as it lands.
  3. Stack them: whether chaining warps and shifts can ever bend anything.
  4. The fold: several kinds of fold, and how each creases the plane.
  5. Origami: the three moves combined to separate the clusters.
  6. The real model: the language model behind this site doing the same thing, live.
  7. Name it: the standard terminology and the one-line formula.
  8. Check yourself: four short questions.

How to use this station

Each step offers something to drag, play or try. Experiment first, then read the notes beneath, which interpret what the panel showed. Hovering over any button describes what it does. Everything runs in the browser except step 7, which sends the text you type to a live model on our server. The strip above records which steps you have visited, and the steps may be taken in any order.

Before this that a vector is a list of numbers, drawn as a point or an arrow (Matrices lab)
You'll leave with linear map · affine map · activation (ReLU) · layer · logits
Time about 25 minutes

A warp is determined entirely by where it sends two arrows. Every point on this grid is a pair of numbers (x, y), and two arrows serve as the reference: î is the point (1, 0) and ĵ is (0, 1). Drag their tips, and the whole grid follows.

Drag the arrow tips

Faint grid: where the points started. Teal grid: where they land. Violet: the unit square.

Matrix W = [ î ĵ ]
Area of the square
1.00
Or pick a kind of warp

What the panel shows

The two columns of the matrix are exactly where î and ĵ landed. That is all a matrix is: a record of where the reference arrows go. Everything else follows from it.

It is also why the grid never bends. The point (x, y) always lands at x copies of î plus y copies of ĵ. When î moves, every point moves by its own x copies of that change, so straight lines remain straight and parallel lines remain parallel.

Two cases are worth trying. Point î and ĵ in the same direction, and the area falls to 0 as the plane collapses onto a line. Exchange them, and the area becomes negative: the grid has been flipped. Throughout, the origin never moves.

Why "warp" and not "shear"?

A shear is one particular warp: it slides one direction sideways and turns squares into slanted parallelograms, as the Shear button shows. A matrix can also stretch, rotate, flip or collapse the plane, or combine those, and the whole family needs one name. "Warp" is the term used here, in the same sense as in image processing, where OpenCV's warpAffine is this operation plus the shift introduced in the next step.

The family is simpler than it looks: no warp is more complicated than rotate, stretch along two perpendicular directions, rotate again, with a flip if the area comes out negative. Even a shear decomposes this way. Every warp in this step keeps straight lines straight; bending is a different move, and it arrives in step 5.

Training or answering? Both, in different ways. Where î and ĵ point is what training chooses; in a real model those are numbers stored in the network. Moving every point of the grid with them is answering: once the arrows are set, the same warp is applied to every input, every time.

Going further

The rotate-stretch-rotate decomposition is the singular value decomposition, found independently by Beltrami (1873) and Jordan (1874). The two stretch factors are the singular values, and their product is the absolute value of the determinant, the area shown above. In a trained network the singular values of each weight matrix are a useful diagnostic: a matrix whose stretches vary enormously amplifies some directions and nearly erases others, which is one reason training can become unstable.

A warp can never move the origin, since 0 copies of î plus 0 copies of ĵ is still 0. A second ingredient removes that limitation: a vector b added to every point, which slides the whole warped grid. Drag the yellow origin to shift and the arrow tips to warp. The warp from step 2 carries over.

Warp, then shift

Yellow: where the origin goes (that is b). White: where the point (1, 2) lands.

Where (1, 2) lands (live)

              
[ W | b ]

What the panel shows

That sum, so many copies of î plus so many copies of ĵ plus the shift, is the entire computation inside a neural-network layer apart from the fold introduced in step 5. Real layers differ only in using longer lists. In Qwen2.5-0.5B, the model behind this site's live labs, each token is a list of 896 numbers, so W has 896 columns instead of 2. The principle is unchanged.

A warp followed by a shift is called an affine map (a linear map plus a shift). It is the term used throughout the literature, and step 8 states it formally.

Training or answering? As with the warp: training chooses b, and answering adds it to every input.

A real network is not one layer but a stack of them, each passing its points to the next. Before adding anything new, it is natural to ask whether enough warps and shifts in sequence could bend the grid into any shape required. Below, a small square of grid passes through two warp-and-shift maps in turn. Follow it from left to right with one question in mind: does any line ever curve?

Two maps, or one?

Read left to right. Panels 2 and 3 take the square through map 1, then map 2. Panel 4 skips the middle: it applies one single map, once, straight to the start. Press Play to watch 3 and 4 move together.

1 Start
2 After map 1
3 Then map 2
4 One single map, from the start
Map 1 [ W₁ | b₁ ]
Map 2 [ W₂ | b₂ ]
The single map

What the panels show

No grid line curves, whatever pair is tried. The first map keeps lines straight, so the second receives straight lines and keeps them straight in turn. Panels 3 and 4 always end identical: two maps in sequence equal one single map, whose numbers appear in the third box. One warp and one shift do the work of both.

Why this matters

A hundred warp-and-shift maps in sequence still amount to one. A hundred-layer network built only from them could separate two groups of points only with a single straight line, and would be no more capable than one layer. Something must break the straightness, and that is the role of the fold.

Training or answering? Neither, strictly: this is a property of the maps themselves. It explains why training a deep stack of maps without folds would gain nothing.

Going further

Panel 4 rests on a standard device. Writing each point as $(x, y, 1)$ turns a warp-and-shift into a single 3×3 matrix, $\begin{bmatrix} W & \mathbf{b} \\ 0 \;\, 0 & 1 \end{bmatrix}$. These are homogeneous coordinates, introduced by Möbius and Plücker in the nineteenth century and brought into computer graphics by Roberts (1965). With them, chaining maps is plain matrix multiplication, and graphics and motion-control software rely on this heavily: a whole chain of transforms is collapsed once into a single 4×4 matrix and then applied to millions of points.

Neural networks do not do this, and this step shows why. Collapsing works only when nothing stands between the maps, and a network places a fold between every pair. Implementations therefore keep W and b separate and compute $W\mathbf{x} + \mathbf{b}$ directly; on a GPU the addition of b is merged into the multiplication at almost no cost. The Affine Transforms lab works through the homogeneous version.

The most common fold is also the simplest: max(0, v), applied to each coordinate separately. Negative numbers become 0 and positive numbers pass through unchanged. It has a standard name, given in step 8; here it is simply the fold below. Colors show the quadrant in which each dot started.

Try different folds

Pick a fold and the grid updates. Each dot (x, y) is sent to (fold(x), fold(y)).

Choose the fold

One whole layer
1. warp and shift:  (x, y)   → (x′, y′)
2. fold each one:   (x′, y′) → (fold(x′), fold(y′))
Top-right: distinct spots
—
Top-left
—
Bottom-left
—
Bottom-right
—

Distinct spots / dots started: how many different places each quadrant's 36 dots end up. 36 / 36 means nothing was lost; 1 / 36 means the whole quadrant was crushed to one point.

What the panel shows

With max(0, v), both coordinates of every bottom-left dot become 0, so the whole quadrant lands on (0, 0) and its counter falls to 1 / 36. The top-left and bottom-right quadrants are flattened onto the axes, and only the top-right is left untouched. The fold discards information, and that proves to be exactly what makes it useful.

The other folds

|v| mirrors instead of flattening: the bottom-left lands on the top-right, so nothing is lost, but two quadrants now overlap. tanh squeezes instead of folding: lines curve, but no two points merge. v changes nothing. And 0.5v + 1 is itself a warp-and-shift, so the grid remains a grid: a fold that is a straight line is no fold at all.

Training or answering? Answering. The fold has no numbers of its own for training to choose; it is fixed when the network is designed.

Going further

Smooth, S-shaped folds such as tanh and the logistic function dominated early networks, partly by analogy with the graded response of biological neurons. max(0, v) appeared in Fukushima's work of 1969 but became standard only after Nair and Hinton (2010) and Glorot, Bordes and Bengio (2011) showed that it made deep networks markedly easier to train. The reason is visible in the panel: for positive inputs it passes values through unchanged, so the signal used in training does not shrink as it travels back through many layers, as it does with folds that flatten at both ends.

One layer can make a straight cut possible where none existed. An orange group lies between two blue groups, and no straight line can place all the orange on one side and all the blue on the other: the best line classifies little more than two-thirds of the points correctly, as the score below records. The task is to send the points through one layer, a warp, a shift and a fold, and then look for a straight cut. The guided moves below divide the task into four small goals, and Step pauses after each part of the layer to show its effect.

Fold the plane

Your job: find one layer that lets a single straight line separate orange from blue. Nobody will do it for you: you set the layer yourself with the four sliders below. Warp turns and stretches the plane, Shift slides it, and the fold is always the same max(0, v) from step 5. Every slider updates the right-hand panel as you drag, so move one, watch where the points go, and adjust. The four moves below break the job into small goals; the sliders that matter for each move are highlighted in yellow.

Before the layer. The points where they start. The shading shows which side of the cut each spot ends up on, drawn back onto the original plane.

Through the layer. The same points as they're warped, shifted and folded. Red corner: the fold zone. Yellow line: the best straight cut, found by trying every line, not by training.

Straight-line score, before the layer
—
Straight-line score, after your layer
—

What the scores mean. Draw one straight line, call everything on one side orange and everything on the other side blue, and count how many of the 72 points are labelled correctly. The score is that count for the best line there is (the page tries every angle and position). Before the layer, the best line slices off one blue group and clips a few stray points of the other: about 71%. After your layer, 100% means one straight line now separates orange from blue perfectly.

The origami view

Once the cut succeeds, consider the left panel. The cut is straight after the fold, but drawn back onto the original plane it is bent, just as a straight cut through folded paper becomes a bent line when the paper is opened. Each fold contributes a bend. With more layers the bends multiply, which is how a network can draw almost any boundary.

Rotation alone often suffices here: many angles reach 100% without any shift. That works because the orange group sits at the origin, so a rotation sends the two blue groups out along different axes while the orange remains bunched in the corner. With the data off-center, the shift would usually be needed as well. Real models obtain much of that effect by other means, and most of their warps have no shift at all; the notes at the end of step 7 show what a layer actually contains.

Training or answering? Moving the sliders until the score reached 100% was training, performed by hand: a search for good numbers. Pressing Play or Step with the sliders left alone is answering: the numbers stay fixed and the points are carried through the layer. A real network has hundreds of millions of such numbers, and no one chooses them by hand. Training finds them automatically, by adjusting every number in whichever direction improves the score, and it is the subject of its own station.

Going further

A network built from warps, shifts and max(0, v) divides its input space into regions, within each of which it acts as a single affine map; the boundaries between regions are the creases. Montúfar and colleagues (2014) showed that the number of such regions can grow exponentially with the number of layers, while it grows only polynomially with the width of a single layer. This is one precise sense in which depth is more economical than width: each layer can fold the creases already made by the layers before it.

Moving points until one straight cut separates them is the whole task of a network, and a language model performs the same task at a vastly larger scale. The table sets the model behind this site beside the Origami exercise:

In OrigamiIn the language model on this site
A point on a plane: 2 numbersThe text so far, turned into a point: 896 numbers
Two groups, orange and blue151,936 groups: one for every token it could say next
One layer: warp, shift, fold24 layers, each one warping and folding, with only a few shifts left (see below), plus attention, which mixes in information from the other words and comes later in the journey
One straight cut, scored 71% → 100%151,936 straight cuts at once, one per token. Each gives a score, and the highest score is the model's best guess for the next word
Your four slidersAbout half a billion numbers, set by training rather than by hand

The last straight cuts, live

Type any text and press Run. The model turns it into one point, and every possible next token gets a score: how far that point sits on the token's side of its straight cut. The scores are then turned into percentages, and the top ten are shown here.

Connecting to the model…

Reading the chart. Each row is one possible next token (a leading space is part of the token, so " Paris" is a different token from "Paris"). The bar is the chance the model gives it. The number on the right is the raw score from that token's straight cut; a higher score means the point sits further onto that token's side.

Layer by layer: when does the answer appear?

The same straight cuts, applied after every layer instead of only at the end. Each column is one layer; its height is the chance the cuts give the model's final answer at that point. Click a column to see that layer's top guesses.

before layer 1layer 24 (the end)

What the panels show

For most of the 24 layers, the point lies nowhere near the correct side of the correct cut. The layers continue to warp, shift and fold it, and only near the end does it arrive where a straight cut can select the answer. This is the Origami exercise's 71% → 100%, carried out in 896 dimensions instead of 2.

Training or answering? Everything in this step is answering. Pressing Run changes none of the model's half-billion numbers; they were fixed when its training ended. The same text run twice produces exactly the same chart. The model has learned nothing from the visitor; it has only carried the point through 24 layers it already had.

Limitations of this view

  • The fold is not exactly max(0, v). This model uses a smoother, gated fold called SwiGLU (Shazeer, 2020). The principle is the same; the crease is softer.
  • Attention is the other half of each layer. Each layer also draws in information from the other tokens, which is how " France" comes to influence the prediction made at " is". Attention has its own station later in the sequence.
  • The layer-by-layer view is approximate. It applies the final cuts to points that are still in motion, a use the cuts were never trained for, which partly explains why the early layers look like noise. The technique is called the logit lens (nostalgebraist, 2020).

The Interpretability lab provides the full version: the lens at every token of the prompt, and what attention is doing.

Going further: what is inside one layer

Each of the 24 layers holds the same set of matrices; only their numbers differ. A matrix's columns count the numbers that go in, and its rows the numbers that come out.

Part of the layerIts matrices (rows × columns)Shift (b)?
Attention: draws in the other tokensQ 896×896 · K 128×896 · V 128×896 · output 896×896On Q, K and V only
Warp and fold (called the MLP)up 4,864×896 · gate 4,864×896 · down 896×4,864None

The second row reads like the Origami exercise. up warps the 896-number point up into 4,864 numbers. The fold happens there, in the wider space: gate determines how much of each of those numbers passes through. down then warps the result back to 896. Folding in a wider space gives the creases far more room, with 4,864 directions to crease along instead of 896.

The last column is notable. The warp-and-fold part has no shift at all, and most recent models (Llama, for one) have dropped most of their shifts as well. They can do so because a layer does not replace the point; it adds its output to it, an arrangement called a residual connection (He and colleagues, 2015). The point arriving at each layer is the running total of everything before it, already far from the origin, so the creases still fall in useful places. The rotation-only Origami solution illustrates the same effect on a small scale.

In total: about 15 million numbers per layer, times 24 layers, plus 136 million in the table that turns each token into its first point. That accounts for the half billion.

Every idea on this page has already appeared in the steps above. The table gives the standard names, which open the research literature, and the symbols, which are shorthand for the same operations.

What you didIts nameWritten
Dragged î and ĵ; the grid followedLinear map; the matrix's columns are where î and ĵ land$W\mathbf{x}$
The area of the squareDeterminant (0 = collapsed, negative = flipped)$\det W$
Slid the originAffine map: linear plus a shift; b is the bias$W\mathbf{x} + \mathbf{b}$
Two maps became oneComposition of affine maps is affine $W_2(W_1\mathbf{x}+\mathbf{b}_1)+\mathbf{b}_2 = (W_2W_1)\mathbf{x} + (W_2\mathbf{b}_1+\mathbf{b}_2)$
Folded each coordinate with max(0, v)Activation function; this one is ReLU, the rectified linear unit$\sigma(v) = \max(0, v)$
Warp, shift, then foldOne layer$\mathbf{h} = \sigma(W\mathbf{x} + \mathbf{b})$
Folded the paper so a straight cut workedA network: layers stacked, then a final linear read-out $y = \mathbf{w}^\top \sigma(W\mathbf{x} + \mathbf{b}) + c$
One straight cut per token, each giving a scoreThe output layer; its scores are logits$z_i = \mathbf{w}_i^\top \mathbf{h}$
Scores turned into percentagesSoftmax $p_i = e^{z_i} / \sum_j e^{z_j}$

What this does not yet explain

  • Who chooses W and b? In the Origami exercise, you set them by hand: six numbers in all. Real networks have millions or billions, found by training. Every formula in the table runs during answering; training is a separate process that runs them, measures the error, and adjusts $W$ and $\mathbf{b}$ (Gradient Descent lab).
  • How many folds does a shape need? With enough layers and units, a network can approximate almost any boundary. This is the universal approximation theorem (Cybenko, 1989; Hornik, 1991), and it is the subject of the next station.
  • What about 896 dimensions? Everything here works identically with longer lists, but intuition about high-dimensional space requires a station of its own.

Go deeper

Four questions on the station's central ideas. Each should be answerable without referring back.

1 A network has 50 layers but no activation functions. What's the most complicated boundary it can draw between two groups of points on a plane?

2 You drag î and ĵ until they point in exactly the same direction. What happens?

3 ReLU sends the point (−2, 3) to:

4 Why could one layer separate the blue–orange–blue row when no straight line could?

Next, because…

In this station six numbers were chosen by hand. A real network has millions, and they are found automatically, by adjusting each one in the direction that makes the answers less wrong. Continue to Gradient Descent →