INTERACTIVE EXPLAINER · 01

What Does GPT
Actually Learn?

Build a tiny model, change its parameters, and watch learning happen—one mathematical step at a time.

Start the experiment ↓ ~12 min read · 4 live labs · Python included
THE WHOLE IDEA \(\hat{y}=wx+b\)
w controls directionb controls position
01

People often say that GPT has billions of parameters. The phrase sounds impressive—but what is a parameter, and what does it mean for one to learn?

We can understand the central idea without starting with billions. Let’s begin with only two, then carefully scale the same idea toward language models.

What you will understand by the end

This article is designed as a guided learning path, not just a collection of interactive widgets.

  • what a parameter is and why changing it changes model behavior;
  • how loss, gradients, and gradient descent make parameters learn;
  • how the scalar rule \(\hat{y}=wx+b\) becomes the vector-matrix rule \(\mathbf{z}=W\mathbf{h}+\mathbf{b}\);
  • how next-token scores become probabilities through softmax;
  • why a modern GPT model needs so many learned numbers.
1Change parameters and see behavior change.
2Train a tiny model and watch error fall.
3Connect scalar mathematics to GPT-style matrices.
4Turn scores into next-token probabilities.

Important: the tiny line model is not GPT. It is a teaching model that isolates the same core mathematical idea: learned numerical parameters control transformations, and training adjusts those parameters to improve predictions.

02
THE SMALLEST USEFUL MODEL

Two numbers can define a behavior

Imagine a tiny model that receives a number x and produces a prediction ŷ. Its complete behavior is controlled by a weight and a bias.

\[\hat{y}=wx+b\]

w weightb biasŷ prediction

For x = 2, w = 0.5, and b = 1, the prediction is 2. Increase only the weight to 1.5, and the prediction becomes 4. The model’s behavior changed because one parameter changed.

Experiment 1 · Change the parameters

Purpose of Experiment 1

Keep the input fixed and change only \(w\) and \(b\). This separates the role of the data from the role of the parameters. The printed outputs show that the same input can produce very different predictions when the learned parameters are different.

  • changing \(w\) changes how strongly the output responds to the input;
  • changing \(b\) shifts the baseline prediction;
  • a negative \(w\) reverses the direction of the relationship.
Python
def tiny_model(x, w, b):
    return w * x + b

x = 2
experiments = [
    {"w": 0.5, "b": 1},
    {"w": 1.5, "b": 1},
    {"w": 1.5, "b": 3},
    {"w": -1.0, "b": 1},
]

for experiment in experiments:
    y_hat = tiny_model(x, experiment["w"], experiment["b"])
    print(experiment, "→", y_hat)
EXPECTED OUTPUT{"w": 0.5, "b": 1} → 2.0 {"w": 1.5, "b": 1} → 4.0 {"w": 1.5, "b": 3} → 6.0 {"w": -1.0, "b": 1} → -1.0
Runs in your browser; first run may take a few seconds.
PAUSE & PREDICT

Before touching the sliders…

  1. What happens to the line when w becomes negative?
  2. Which parameter moves the line without changing its tilt?
03
HOW A PARAMETER LEARNS

Turn “wrong” into a direction

Suppose the hidden rule is y = 2x + 1, and we observe five examples: (0,1), (1,3), (2,5), (3,7), and (4,9). Our model begins badly at w = −1 and b = 0.

First, measure how wrong it is with mean squared error:

\[L(w,b)=\frac{1}{n}\sum_{i=1}^{n}(\hat{y}_i-y_i)^2\]

Then calculate the slopes of that loss—its gradients—and take a small step in the opposite direction:

\(w_{\text{new}}=w-\eta\frac{\partial L}{\partial w}\)
\(b_{\text{new}}=b-\eta\frac{\partial L}{\partial b}\)
Predict→Measure error→Compute gradient→Update↺

Loss

A single number that summarizes how wrong the model currently is. Lower is better.

Gradient

A derivative that tells us the direction in which a parameter would increase the loss. We move in the opposite direction.

Learning rate \(\eta\)

The size of each update. Too small can make learning slow; too large can make it overshoot or become unstable.

Epoch

One pass/update step in our small demonstration. More epochs mean more opportunities to adjust the parameters.

Experiment 2 · Train with gradient descent

Purpose of Experiment 2

Here the correct rule is hidden from the model. We provide examples generated by \(y=2x+1\), start from a poor guess, and let gradient descent discover parameter values close to \(w=2\) and \(b=1\). This is the key change from Experiment 1: we are no longer choosing the parameters manually; the optimization process is learning them from data.

Python
import numpy as np

# Training data generated by y = 2x + 1
x = np.array([0, 1, 2, 3, 4], dtype=float)
y = np.array([1, 3, 5, 7, 9], dtype=float)

# Deliberately poor starting guess
w, b = -1.0, 0.0
learning_rate = 0.05

for epoch in range(200):
    y_hat = w * x + b
    error = y_hat - y
    loss = np.mean(error ** 2)

    # Gradients of mean squared error
    dw = 2 * np.mean(error * x)
    db = 2 * np.mean(error)

    # Gradient-descent update
    w -= learning_rate * dw
    b -= learning_rate * db

print(f"learned w={w:.3f}")
print(f"learned b={b:.3f}")
print(f"final loss={loss:.6f}")
EXPECTED OUTPUTlearned w=2.000 learned b=1.000 final loss=0.000000
This executable version focuses on the mathematics; the live chart is shown in Live Lab 02 below.

Purpose

Watch optimization turn a poor starting rule into a better one. The line is the model; the teal points are the training data it is trying to fit.

How to use it

  • press Step a few times;
  • watch weight, bias, and loss change;
  • then use Auto train;
  • reset and try a different target rule.

Success signal

When learning is working, the loss should generally fall and the learned weight/bias should move toward the target slope and target bias.

LIVE LAB 02

Watch gradient descent learn

● LIVE
Epoch0
Weight-1.000
Bias0.000
Loss121.0000
Loss history
xy

target data learned line

⚗

Break it on purpose

Try \(\eta=0.005\) and watch learning slow down. Then push it toward \(0.2\) and watch the updates become more aggressive. Change the target to \(3x-2\) and reset: the model must discover a new weight and bias.

Connection to GPT: GPT also predicts, measures error, computes gradients by backpropagation, and updates parameters. The loss used for a language model is normally based on next-token probabilities rather than this simple squared-error loss.
04
FROM NUMBERS TO WORDS

GPT learns transformations, not sentences

A language model does not store a little dictionary of answers. It repeatedly transforms numerical representations, using learned matrices and biases.

Text→Tokens→Vectors→Scores→Probabilities
\[\mathbf{z}=W\mathbf{h}+\mathbf{b}\]

The same idea—now one vector is transformed by a whole matrix of learned weights.

Tiny teaching modelGPT-style versionMeaning
\(x\)\(\mathbf{h}\)A scalar input becomes a vector representation.
\(w\)\(W\)One weight becomes a matrix containing many learned weights.
\(b\)\(\mathbf{b}\)One bias becomes a bias vector.
\(\hat y\)\(\mathbf z\)One prediction becomes many scores, such as one score per vocabulary token.

Where do those learned matrices appear?

Inside a Transformer, parameters are distributed across several components. For example, attention creates query, key, and value representations:

\[Q=XW_Q,\qquad K=XW_K,\qquad V=XW_V\]

The matrices \(W_Q, W_K, W_V\) are learned parameters.

Attention then uses those representations to decide which parts of the context should influence one another:

\[\operatorname{Attention}(Q,K,V)=\operatorname{softmax}\!\left(\frac{QK^T}{\sqrt{d_k}}\right)V\]

This is a much richer transformation than \(wx+b\), but the underlying theme is the same: learned numbers control how information is transformed and combined.

What does “knowledge is in the parameters” really mean?

It does not mean that one parameter stores one fact. Useful behavior is distributed across many parameters, the network architecture, and the temporary activations produced for the current prompt. A model can also memorize some training sequences, but its normal operation is not simply a database lookup.

After the model produces a score zi for every possible next token, softmax turns the scores into probabilities:

\[P(i)=\frac{e^{z_i}}{\sum_j e^{z_j}}\]

During language-model training, the correct next token acts as the target. A common training loss is cross-entropy; for the correct token \(y\), the essential term is:

\[L=-\log P(y)\]

If the model assigns low probability to the correct token, the loss is large. Training changes parameters to make better next-token probabilities.

Experiment 3 · A three-token softmax

Purpose of Experiment 3

The raw model outputs are called logits or scores. They are not probabilities yet. Softmax converts them into positive values that sum to 1. This experiment shows why even a modest difference in scores can create a strong preference for one next token.

Python
import numpy as np

tokens = ["west", "east", "banana"]
logits = np.array([1.2, 3.8, 0.2])

shifted = logits - np.max(logits)  # numerical stability
probabilities = np.exp(shifted) / np.exp(shifted).sum()

for token, probability in zip(tokens, probabilities):
    print(f"{token:>6}: {probability:.3f}")
EXPECTED OUTPUT west: 0.067 east: 0.909 banana: 0.024
Change the logits in the code, then run again.

Purpose

See the final step that converts vocabulary scores into a probability distribution over possible next tokens.

Try this

  • make all three scores equal;
  • raise only east;
  • make banana the largest score.

What to observe

Equal scores give similar probabilities. Increasing one score steals probability mass from the others because all probabilities must sum to 1.

LIVE LAB 03

Turn scores into probabilities

● LIVE
west6.7%
east90.9%
banana2.4%
Interpretation: GPT does not need a stored sentence for every prompt. It uses its learned transformations to produce context-dependent scores, then converts those scores into probabilities for what may come next.
05
FROM TWO TO BILLIONS

Scale the same principle

Modern language models contain many kinds of learned numbers: token embeddings, attention projections, feed-forward layers, normalization scales, and output weights. The count grows quickly because high-dimensional vectors are repeatedly transformed by large matrices across many layers.

Why billions appear so quickly

If a layer maps a 4,096-dimensional vector to another 4,096-dimensional vector, one dense weight matrix alone contains \(4096\times4096\approx16.8\) million values. Repeat several matrices across many Transformer blocks and the total rapidly reaches billions.

Teaching simplification: the calculator below is intentionally simplified. A real Transformer also includes an attention output projection, many repeated layers, biases, normalization parameters, and architecture-specific choices such as tied or untied embedding/output weights.

Python
vocabulary_size = 10_000
model_dimension = 128
feedforward_dimension = 512

embedding = vocabulary_size * model_dimension
attention = 3 * model_dimension * model_dimension
feedforward = (
    model_dimension * feedforward_dimension
    + feedforward_dimension * model_dimension
)
output = model_dimension * vocabulary_size

total = embedding + attention + feedforward + output
print(f"{total:,} parameters")  # 2,740,224
EXPECTED OUTPUT2,740,224 parameters
Edit the dimensions above to see how the count changes.
06
THE TAKEAWAY

Learning is adjustment at scale

A parameter is just a number. But billions of jointly trained parameters can build rich representations of language and turn context into a probability distribution over what comes next.

Parameters→Transformations→Representations→Probabilities

So, what does GPT actually learn?

It learns a large distributed system of numerical transformations: how to represent tokens, how to combine information across context, how to build increasingly useful internal representations, and how to assign scores to possible next tokens. Training repeatedly adjusts those parameters so that the model gives higher probability to appropriate continuations.

The tiny line model showed the principle with two parameters. The Transformer scales the same learning idea to vectors, matrices, attention, nonlinear transformations, and many layers. The result is not “one fact per parameter,” but a large coordinated mathematical system whose behavior emerges from how many learned values work together.