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.
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.
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.
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.
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)
Before touching the sliders…
- What happens to the line when w becomes negative?
- Which parameter moves the line without changing its tilt?
Purpose
Turn the formula into a visual object. You are seeing exactly how two parameter values control the position and direction of a prediction rule.
Try these settings
- \(w=0, b=2\): horizontal line
- \(w=2, b=0\): steep positive line
- \(w=-2, b=0\): downward line
- keep \(w\) fixed and change \(b\)
What to observe
The weight changes the tilt; the bias moves the line up or down without changing its tilt. These are two different kinds of control.
Move the parameters. Move the line.
Weight changes the tilt. Bias slides the line up or down.
Recreate Live Lab 01 in Python
The live sliders above are written in JavaScript so they respond instantly in the webpage. This Python version performs the same mathematical idea: choose a weight \(w\) and bias \(b\), calculate \(y=wx+b\), and draw the resulting line.
w and b in the code below, then press
Run Python here. Compare the Python-generated graph with Live Lab 01 above.
import numpy as np
import matplotlib.pyplot as plt
import io
import base64
# Try changing these two learned parameters
w = 1.0
b = 0.0
x = np.linspace(-5, 5, 100)
y = w * x + b
plt.figure(figsize=(7, 4))
plt.axhline(0, color="gray", linewidth=0.8)
plt.axvline(0, color="gray", linewidth=0.8)
plt.plot(x, y, linewidth=3)
plt.xlabel("x")
plt.ylabel("y")
plt.title(f"y = {w}x + {b}")
plt.ylim(-10, 10)
plt.grid(alpha=0.2)
# Send the plot back to the webpage
_buffer = io.BytesIO()
plt.savefig(_buffer, format="png", dpi=120, bbox_inches="tight")
plt.close()
_pmai_plot_data = base64.b64encode(_buffer.getvalue()).decode("utf-8")
print(f"Weight w = {w}")
print(f"Bias b = {b}")
print(f"For x = 2, prediction = {w * 2 + b}")
How to interpret the result
If you increase \(w\), the line becomes steeper. If \(w\) becomes negative, the direction reverses. Changing \(b\) shifts the line vertically. The Python graph therefore confirms the same lesson as Live Lab 01: parameters change model behaviour because they change the mathematical transformation.
Optional: make the Python version interactive in Google Colab/Jupyter
In Colab or Jupyter, ipywidgets can create Python sliders.
This is optional because the webpage already provides the live slider experiment.
import numpy as np
import matplotlib.pyplot as plt
from ipywidgets import interact, FloatSlider
def explore_model(w=1.0, b=0.0):
x = np.linspace(-5, 5, 100)
y = w * x + b
plt.figure(figsize=(7, 4))
plt.axhline(0, color="gray", linewidth=0.8)
plt.axvline(0, color="gray", linewidth=0.8)
plt.plot(x, y, linewidth=3)
plt.ylim(-10, 10)
plt.grid(alpha=0.2)
plt.show()
interact(
explore_model,
w=FloatSlider(min=-3, max=3, step=0.1, value=1),
b=FloatSlider(min=-5, max=5, step=0.1, value=0),
);
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:
Then calculate the slopes of that loss—its gradients—and take a small step in the opposite direction:
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.
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}")
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.
Watch gradient descent learn
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.
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.
The same idea—now one vector is transformed by a whole matrix of learned weights.
| Tiny teaching model | GPT-style version | Meaning |
|---|---|---|
| \(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:
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:
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:
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:
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.
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}")
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.
Turn scores into probabilities
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.
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
Purpose
Turn the formula into a visual object. You are seeing exactly how two parameter values control the position and direction of a prediction rule.
Try these settings
- \(w=0, b=2\): horizontal line
- \(w=2, b=0\): steep positive line
- \(w=-2, b=0\): downward line
- Keep \(w\) fixed and change \(b\)
What to observe
The weight changes the tilt; the bias moves the line up or down without changing its tilt. These are two different kinds of control.
TOTAL PARAMETERS
2,740,224
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.
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.