Jorge Cambra

Software Engineer

...Work in progress...

A hand-drawn loss curve on grid paper. A ball sits on a downhill slope with a red tangent line labeled slope = derivative and a blue arrow labeled step downhill.

Rookie calculus for machine learning


Say you have two classifiers. One says a post is 50% likely to be a threat. The other says 60%. You have to combine them into one answer. What would you do?

Average them? Maybe. But what if one is better than the other? Then you'd trust it more. How much more? You could try some weights, count how many posts you get right, and try again.

That works with two numbers. A real model has thousands of them, or billions. You can't try them all. You need a way to look at each number and know which way to move it, and by how much.

Here's one way. Take one number and move it a tiny bit. Did the answers get better or worse, and by how much? Now you know which way to go. Do that for every number, over and over.

That tiny experiment, made exact, is a derivative. Newton and Leibniz worked it out in the 1600s to describe how things move. Machine learning borrowed it, because training a model is the same question: if I change this a little, how much does that change?

But, as big as machine learning has become, we only need tiny pieces of calculus for most of it. I'll go over those pieces, assuming a very low starting point.

1 - Derivatives: how fast does the output move?

Start with something you can picture. A square tile has sides of 3 meters, so its area is 3² = 9 square meters. Make each side 1 centimeter longer, 3.01 m. The area becomes 9.0601 m². It grew by about 0.06, six times as much as the side did.

A square of side 3 m. Click to enlarge.

A model asks the same question. The input is one of its numbers, like how much to trust a classifier. The output is how many mistakes it makes. If I nudge this, how much does that move?

Let's give the tile's numbers names, because we'll see them everywhere.

The side grew by 0.01 m. Call that dx: a tiny change in the input.

The area grew by 0.06 m². Call that d(area): the tiny change in the output.

Divide one by the other: 0.06 / 0.01 = 6. That's d(area)/dx, the derivative.

The first 2, (dx , d(area)) are amounts. The derivative, its a rate: square meters of area per meter of side.

There's a book from 1910, Calculus Made Easy by Silvanus Thompson, that clears this up in one line: d "merely means 'a little bit of.'" So dx is a little bit of side. d(area) is a little bit of area. And d(area)/dx is how many little bits of area you get per little bit of side. Six, for our tile.

So why exactly 6? Look at the picture. When the side grows by dx, the area grows by two thin strips, each x long and dx wide, plus a tiny corner. The corner is dx times dx, a tiny amount of a tiny amount, so small it doesn't count. That leaves 2 · x · dx. Divide by dx and you get 2x. At x = 3, that's 6.

Grow the side by 0.001 m instead, and the area grows by about 0.006 m². Smaller amounts, same ratio: 6. That's why the rate is the number worth knowing.

2 - The chain rule: functions inside functions

Models are are functions nested inside functions.

Forward, the input becomes a prediction. Backward, each layer's weights get nudged. Click to enlarge.

Lets take sin⁡(x2)\sin(x^2)

• Inner: x² gets computed first.

• Outer: sin( ) is applied to whatever the inner produced.

Each step has its own derivative, and both are known:

  • The derivative of x2x^2 is 2x2x. That's the tile from section 1.
  • The derivative of sin⁡\sin is cos⁡\cos. At any point, sin⁡\sin changes at a rate of cos⁡\cos of that point. You can check it with a nudge, or look it up in any table of derivatives.

The chain rule says: multiply them, and measure each one at its own input.

ddxsin⁡(x2)=cos⁡(x2)⋅2x\frac{d}{dx}\sin(x^2) = \cos(x^2) \cdot 2x

The 2x is the inner's rate, measured at x. The cos(x²) is the outer's rate, measured at what the outer actually receives. sin never sees x. It sees x², so its rate is cos of x².

Why multiply? Nudge x a tiny bit. x² moves 2x times as much as x did. Then sin moves cos(x²) times as much as x² did. Two rates in a row multiply.

Move x a little and watch the nudge stretch at each step.

In general, with u=h(x)u = h(x) as the inner function:

dydx=dydu⋅dudx\frac{dy}{dx} = \frac{dy}{du} \cdot \frac{du}{dx}

3 - The number e

Open almost any machine learning formula and you'll find an e or an ln in it. e is a strange-looking number, 2.718… So why that one?

Start with something that doubles: 2ˣ. At x = 3 it's 8. Nudge x a tiny bit and measure the rate, like we did with the tile: it grows at about 5.55 per unit of nudge. That's 0.693 × 8.

Try it at other points and you get the same thing. 2ˣ always grows at 0.693 times its current size. Its derivative is:

ddx 2x=0.693⋅2x\frac{d}{dx}\,2^x = 0.693 \cdot 2^x

Every exponential works like this. The bigger it is, the faster it grows. The only difference between them is that number in front:

FunctionDerivative
2x2^x0.693⋅2x0.693 \cdot 2^x
10x10^x2.303⋅10x2.303 \cdot 10^x
exe^x1⋅ex\mathbf{1} \cdot e^x

e is the one base where the number in front is exactly 1. exe^x grows at exactly its own size. Its derivative is itself:

ddx ex=ex\frac{d}{dx}\,e^x = e^x

With base 2, the 0.693 follows you into every formula you ever differentiate. With e it disappears

So do we need e? Not really. A model built with base 2 would learn just as well, and its weights would quietly absorb the 0.693.

So e buys you clean formulas, and little more.

ln (natural logarithm)

Every exponential has a log that undoes it. log⁡2\log_2 undoes 2x2^x: log⁡2(8)=3\log_2(8) = 3, because 23=82^3 = 8. log⁡10\log_{10} undoes 10x10^x. The one that undoes exe^x is called the natural log, ln⁡\ln.

Logs have the same problem as exponentials, flipped around. Take x = 4 and nudge it a tiny bit:

FunctionValue at x = 4Rate at x = 4Derivative
log⁡2(x)\log_2(x)20.3611/(0.693⋅x)1 / (0.693 \cdot x)
log⁡10(x)\log_{10}(x)0.6020.1091/(2.303⋅x)1 / (2.303 \cdot x)
ln⁡(x)\ln(x)1.3860.251/x\mathbf{1 / x}

It's the same 0.693 and 2.303 from before, now dividing instead of multiplying. Only ln comes out clean:

ddxln⁡(x)=1x\frac{d}{dx}\ln(x) = \frac{1}{x}

At x = 4, that's 1/4. No stray number.

Models measure their mistakes with ln, and this 1/x is what makes the math come out simple.

4 - Linear models

A linear model predicts a target value by calculating a weighted sum of input features plus a bias term (turns several inputs into one answer: multiply each input by a weight, add them up, and add one more number).

Say you want to guess an apartment's monthly rent from two things, its size and how far it is from the center. A linear model would look like this:

rent=10⋅size−30⋅distance+200\text{rent} = 10 \cdot \text{size} - 30 \cdot \text{distance} + 200

Each square meter adds $10. Each kilometer from the center takes away $30. The $200 is where you start before looking at anything. That's the bias.

A 50 m² apartment 2 km out: 10 · 50 − 30 · 2 + 200 = $640.

Each input pushes the answer up or down by a fixed amount, its weight, no matter what the other inputs are doing. That's what "linear" means here. Bigger apartments always add the same $10 per square meter, whether they're downtown or far away.

In ML models, the weights are normally learned by the models themselves. Usually there are too many weights to be able to manually define them in a way that is useful.

Lets explore the following flavors :

  • linear regression
  • logistic regression

Linear regression

The rent model is linear regression. It takes some inputs and predicts a number.

To keep things simple, look at apartments that are all 2 km from the center. Distance is fixed, so the model becomes:

rent=10⋅size+140\text{rent} = 10 \cdot \text{size} + 140

(That's the 200 minus 30 · 2 from before.)

Here's what that looks like next to real apartments:

Linear regression: the miss for one apartment, and its square. Click to enlarge.

Each dot is an apartment. The line is the model's guess for every size. Most dots don't sit exactly on the line. The gap between a dot and the line is the miss.

Wait, it never gets one right? In the picture, the line doesn't hit a single apartment exactly. That's fine. Rent depends on things the model can't see, like the floor, the view, the landlord. No line through size alone could hit them all. What matters is how close it gets. The line misses by about $49 on a typical apartment. If you had no model and just guessed the average rent, $766, for everything, you'd miss by about $194. The line is about four times better than guessing, and its weight tells you something real: each square meter adds about $10.

How wrong is the model?

Take the 50 m² apartment. The model guesses 10 · 50 + 140 = $640. The real rent is $700. The model missed by $60.

To score a miss, we square it: 60² = 3,600. That's the amber square in the picture.

Why square it? Two reasons:

A miss of 60 too high and a miss of 60 too low should count the same. Squaring makes both positive. Big misses should count much more than small ones. A miss of 10 scores 100. A miss of 60 scores 3,600.

Do this for every apartment, take the average, and you get one number that says how wrong the model is. It's called the mean squared error. In the picture, it's the average area of the amber squares.

Training

Training means finding the weights that make that number as small as possible. In the picture, that's moving the line until the squares are as small as they can get.

So which way should each weight move? Here's where the first two sections come in.

The score for one apartment is the miss, squared. From the tile in section 1, the rate of something squared is 2 times that something. So the rate of the squared miss is 2 · miss.

For our apartment the guess was $60 too low: 640 − 700 = −60. The rate is 2 · (−60) = −120. Raising the guess lowers the error.

But we can't change the guess directly. We can only change the weights. That's a chain: weight → guess → squared miss. From section 2, rates along a chain multiply:

How much the guess moves per unit of the size weight: the size itself, 50.

How much the squared miss moves per unit of the guess: −120.

Together: 50 × (−120) = −6,000.

Negative means raising the size weight lowers the error. Nudge it from 10 to 10.001, and the squared miss drops from 3,600 to about 3,594. That's a drop of 6, just as −6,000 × 0.001 predicts.

The bias works the same way, except the guess moves by exactly 1 per unit of bias, so its rate is just −120.

That's one apartment. Real training does this for every apartment, averages the rates, and moves each weight a small step in the direction that lowers the error. Then it repeats. That's gradient descent, which gets its own section later.

Try it: drag the weight, or press Step, and watch the dot roll down the bowl while the line moves toward the apartments.

Logistic regression

Some questions don't have a number or long text as an answer. They have a yes or a no. Is this email spam? Will this customer cancel? Is this post a threat?

A program that answers a question like that is called a classifier. It sorts things into classes: spam or not spam, threat or not threat. Most classifiers don't just say yes or no. They give a score between 0 and 1, roughly "how sure am I that it's a yes".

So why would you have two classifiers for the same question? Because you can make them look at things differently, so in the end they help you get a better sense of what you are trying to accomplish.

Take spotting threats in social media posts with two different tools:

-One reads the meaning. You hand the post to a large language model and ask, "Is this a threat?" It understands context and sarcasm, and it notices a threat even with no obvious keywords.

-One counts words. A simpler model learns which words show up more in threats than in normal posts ("missile", "strike", "attack") and scores each post by how many of them it contains. A common way to do that is called TF-IDF. It's fast and consistent, but literal: it misses a threat written without those words, and it gets fooled by "this recipe is the bomb".

Each one can be right where the other is weak. If you combine them well, you get fewer mistakes than with either one alone. The question is how to combine them. Average them? Trust one more? How much more?

Logistic regression answers that. It starts exactly like linear regression, with a weighted sum plus a bias. Call the two scores zs (zero-shot) and tfidf:

z=w1⋅zs+w2⋅tfidf+bz = w_1 \cdot zs + w_2 \cdot tfidf + b

The weights say how much to trust each classifier, and training finds them. Say training ends with these:

z=2.52⋅zs+5.53⋅tfidf−3.79z = 2.52 \cdot zs + 5.53 \cdot tfidf - 3.79

Take a post where zero-shot says 0.5 and TF-IDF says 0.6. Then z = 2.52 · 0.5 + 5.53 · 0.6 − 3.79 ≈ 0.79.

Here's what training does to these weights. For now, just read each dot as “how likely the model thinks this post is a threat”. How a score turns into that probability comes next.

5 Scores -> Probabilities , Loss Function

The weighted sum gives each post a score z. To train, we need two more things: turn that score into a probability, and measure how wrong that probability is.

The sigmoid

A score can be any number: −40, 0.79, 12. A probability has to be between 0 and 1. The sigmoid squashes one into the other:

σ(z)=11+e−z\sigma(z) = \frac{1}{1 + e^{-z}}

You don't need to remember the formula. You need its shape:

The sigmoid: any score in, a probability out. Click to enlarge.

A very negative score gives almost 0%. A score of 0 gives exactly 50%. A very positive score gives almost 100%.

Our post, with a score of 0.79, gets 69%: the model thinks it's more likely a threat than not.

The e in the formula is the one from section 3, and it's there for the same reason: it keeps the derivative clean. How fast the probability moves when the score moves turns out to be:

dpdz=p⋅(1−p)\frac{dp}{dz} = p \cdot (1 - p)

It's built only from p, which you already have.

Where p(1 − p) comes from

Write σ(z) as (1 + e⁻ᶻ)⁻¹. The outer step is "1 over something", whose rate is −1/(something)². The inner step is 1 + e⁻ᶻ, whose rate is −e⁻ᶻ. Multiply them (chain rule):

σ′(z)=e−z(1+e−z)2=11+e−z⋅e−z1+e−z=σ(z) (1−σ(z))\sigma'(z) = \frac{e^{-z}}{(1 + e^{-z})^2} = \frac{1}{1 + e^{-z}} \cdot \frac{e^{-z}}{1 + e^{-z}} = \sigma(z)\,(1 - \sigma(z))

How wrong is a probability?

We need a score that moves a little every time a weight moves a little. The standard one is log loss: take the probability the model gave to the true answer, and score it with −ln.

loss=−ln⁡(probability given to the true answer)\text{loss} = -\ln(\text{probability given to the true answer})
Probability given to the true answerLoss
0.9, confident and right0.11
0.5, no idea0.69
0.01, confident and wrong4.61

Being right costs almost nothing.

Shrugging costs a bit.

Being confidently wrong costs a lot, and it keeps growing as the probability heads toward 0.

Why ln?

Why score a probability with −ln, and not something simpler? Three reasons:

  • It has the right shape. ln⁡(1)=0\ln(1) = 0, so a model that gives the true answer 100% pays nothing. As the probability heads toward 0, −ln shoots up without limit. That's exactly the "confidently wrong costs a lot" behavior from the table.
  • It turns multiplying into adding. How likely a model is to get every post right is the product of its probabilities: 0.9 × 0.8 × 0.95 × … With thousands of posts, that product is so tiny a computer rounds it to zero. ln turns the product into a sum: ln⁡(a⋅b)=ln⁡(a)+ln⁡(b)\ln(a \cdot b) = \ln(a) + \ln(b). So instead of multiplying thousands of tiny numbers, you add up thousands of ordinary ones. Averaging those is the loss.
  • Its derivative is clean. From section 3, the rate of ln⁡(p)\ln(p) is just 1/p1/p. Combined with the sigmoid's p(1−p)p(1 - p), most of the math cancels out during training, as you'll see.
Why −ln: its shape punishes confident mistakes, and it turns a vanishing product into a readable sum. Click to enlarge.

Why ln and not log⁡2\log_2? Same shape, same behavior. ln just keeps the derivative free of the stray 0.693, for the same reason e beat 2 in section 3.

It shouts loudest about the worst mistakes.

Say our post really is a threat. The model gave it 69%, so its loss is −ln⁡(0.69)≈0.37-\ln(0.69) \approx 0.37. If it weren't a threat, the true answer would be "no", which got 31%, and the loss would be −ln⁡(0.31)≈1.17-\ln(0.31) \approx 1.17.

Written for a label y that's 1 (threat) or 0 (not a threat), both cases fit in one formula:

L=−[ yln⁡p+(1−y)ln⁡(1−p) ]L = -\bigl[\, y \ln p + (1 - y) \ln(1 - p) \,\bigr]

When y = 1, only the first part is left: −ln⁡(p)-\ln(p). When y = 0, only the second: −ln⁡(1−p)-\ln(1 - p). Average it over every post, and you get one number that says how wrong the model is.

6 - Partial derivatives

So far, every rate had one input and one output. A real model has many weights, and its loss depends on all of them at once.

The rent model has two (size and bias). The threat model has three. An LLM has billions.

So the question becomes: if I nudge one weight and leave all the others alone, how much does the loss move? That's a partial derivative.

For the 50 m² apartment from section 4:

  • nudging the size weight moves the squared miss at a rate of −6,000
  • nudging the bias moves it at a rate of −120

Each time, one weight moved and the other stayed put. That's what "partial" means here: one at a time.

The notation

It gets a curly d, written ∂ and read "partial":

∂L∂w\frac{\partial L}{\partial w}

Read it as "how fast L moves when only w moves". It means the same as d/dx. The curly d is just a reminder that other things exist, and they're being held still.

The gradient

Put the partial derivatives for every weight in one list, and you get the gradient, written ∇L\nabla L:

∇L=(∂L∂w1, ∂L∂w2, … )\nabla L = \left( \frac{\partial L}{\partial w_1},\ \frac{\partial L}{\partial w_2},\ \dots \right)

For the apartment, it's (−6,000, −120)(-6{,}000,\ -120).

Here's a way to picture it. With two weights, imagine a landscape. Each spot on the ground is one choice of the two weights, and the height there is the loss. The gradient is an arrow on the ground pointing in the direction where the ground climbs fastest. Its length says how steep that climb is.

We want the loss to go down, so we walk the other way: minus the gradient points downhill.

Try it: drag the point around the map and watch the gradient, minus the gradient and the two partial derivatives change. Press "Step downhill" to take one step.

7 - Who gets the blame?

When a model gets a post wrong, how does each weight "know" how much to change? Its own partial derivative tells it.

Take the threat model from section 4. A post goes through a chain:

weight → score zz → probability pp → loss

From section 2, rates along a chain multiply. So the partial derivative for one weight is three rates multiplied together:

  • How the loss moves with pp: −1/p-1/p. That's the clean 1/x1/x from ln, in section 3.
  • How pp moves with zz: p(1−p)p(1 - p). That's the sigmoid's rate, from section 5.
  • How zz moves with the weight: that weight's input. If a weight multiplies a score of 0.6, nudging it moves zz by 0.6 per unit.

Multiply the first two, and something nice happens:

−1p⋅p (1−p)=−(1−p)=p−1-\frac{1}{p} \cdot p\,(1 - p) = -(1 - p) = p - 1

The pp's cancel. For a real threat (y=1y = 1), what's left is p−1p - 1. Do the same for a harmless post (y=0y = 0) and you get p−0p - 0. Either way, it's the prediction minus the truth: p−yp - y.

Where one rate explodes, the other shrinks. Multiplied, they become p − y. Click to enlarge.

This is why sigmoid and log loss always come as a pair. On its own, the sigmoid's rate shrinks to almost nothing when the model is very sure, so a confidently wrong model would barely learn. The loss's rate blows up exactly there and makes up for it. What's left is a simple, honest signal.

So the partial derivative for each weight is:

∂L∂w=(p−y)⋅that weight’s input\frac{\partial L}{\partial w} = (p - y) \cdot \text{that weight's input}

Each weight is blamed in proportion to how wrong the model was, times how much its own input took part.

Some examples

Example 1: a real threat the model was unsure about. Zero-shot says 0.5 and TF-IDF says 0.6, so the model says 69%. The truth is y=1y = 1, so p−y=−0.31p - y = -0.31.

WeightIts inputBlame: (p−y)×input(p - y) \times \text{input}
zero-shot0.5−0.16
TF-IDF0.6−0.19
bias1−0.31

All negative: raising every weight lowers the loss and pushes pp toward 100%. TF-IDF gets a bit more of the push, because its input was bigger.

Example 2: a harmless post that fooled TF-IDF. "This recipe is the bomb." Zero-shot says 0, TF-IDF says 1, so the model says 85%. The truth is y=0y = 0, so p−y=+0.85p - y = +0.85.

WeightIts inputBlame: (p−y)×input(p - y) \times \text{input}
zero-shot00
TF-IDF1+0.85
bias1+0.85

Positive: lowering these weights lowers the loss. TF-IDF and the bias get pushed down. Zero-shot gets no blame at all. It said 0, so it had no part in the mistake.

No weight changes at random. Each one moves by exactly its share. Put the three blames side by side, and that's the gradient for this post: (−0.16, −0.19, −0.31)(-0.16,\ -0.19,\ -0.31) for the first one. Average it over every post, step against it, and you're training. That's the next section.

8 - Gradient descent

We know which way is downhill: minus the gradient. The last question is how far to step.

Training is a loop:

Compute the gradient. Take a small step against it. Repeat.

As a formula:

w←w−η⋅∇Lw \leftarrow w - \eta \cdot \nabla L

  • ww: one weight of the model, the number we are adjusting.
  • ←\leftarrow: the arrow means "replace ww with". The new value takes the old one's place.
  • η\eta: the step size η\eta (the Greek letter eta) is the learning rate. It says how big a step to take.
  • ∇L\nabla L: the gradient from section 6, the arrow that points uphill on the loss. Minus it points downhill.

Picture it with one weight

Take a loss with one weight: L=(w−3)2L = (w - 3)^2. Look at it from the side. Left to right is the weight ww. Height is the loss. It's a valley, and the bottom is at w=3w = 3.

The gradient lives on the floor, on the weight's axis. With one weight it can only point left or right, and it always points toward the higher wall of the valley.

Why the higher wall? The gradient measures what happens to the loss when the weight goes up. At w=0w = 0 it's 2(0−3)=−62(0 - 3) = -6. Negative means raising ww lowers the loss, so lowering ww is what raises it. The arrow points left, up the left wall. At w=5w = 5 it's +4+4: raising ww raises the loss, and the arrow points right, up the right wall. Either way, it points to where the loss climbs.

The update is the amber arrow, and it always goes the opposite way:

w←w−η⋅gradientw \leftarrow w - \eta \cdot \text{gradient}

At w=0w = 0: 0−0.1⋅(−6)=0.60 - 0.1 \cdot (-6) = 0.6. Subtracting a negative number moves the weight right, toward the bottom, and the loss drops from 9 to 5.76. At w=5w = 5: 5−0.1⋅4=4.65 - 0.1 \cdot 4 = 4.6. The weight moves left, toward the bottom again.

So the gradient and the update are never independent. The update is the gradient flipped and scaled by the learning rate.

Press Step a few times from w=0w = 0. Each step closes 20% of the gap to 3: 0, then 0.6, 1.08, 1.46… The steps shrink on their own, because the valley gets flatter near the bottom, so the gradient gets smaller.

Now move the learning-rate slider:

  • η=0.1\eta = 0.1: steady progress.
  • η=1\eta = 1: the weight jumps from 0 to 6, back to 0, then 6, forever. It overshoots by exactly as much as it was off.
  • η=1.1\eta = 1.1: each jump overshoots further than the last, and the weight flies off the chart.

That's why the learning rate is the first thing anyone tunes. Too small and training crawls. Too big and it bounces or explodes.

With more weights it's the same picture, except the floor is a map instead of a line. Each weight gets its own number, and together they make the arrow you saw in section 6.

Valleys, saddles and getting stuck

Gradient descent only feels the slope where it stands. Picture a ball rolling downhill in fog: it stops in whichever valley is nearest, even if a deeper one sits over the next hill. So in principle, it only finds a local minimum, not the best one.

In practice, that's rarely a problem for big models, for three reasons:

  • Noise. Real training computes each step from a random handful of examples, a mini-batch, not the whole dataset. So each step's slope is slightly off. That jiggle shakes the ball out of shallow dips.
  • Momentum. Most optimizers (like Adam) remember their recent steps and keep rolling in the same direction, coasting over small bumps.
  • Many dimensions. To trap the ball, the ground has to curve up in every direction at once. With millions of weights, that's very unlikely. Most flat spots are saddles: uphill one way, downhill another. Sooner or later, the ball finds the way down.

Many examples, one step

The loss is an average over all the training examples, so each step is a compromise. Every example "votes" for how each weight should move, using the blame from section 7, and the step follows the average vote.

One full pass through every example is called an epoch. Training usually runs many epochs.

The training figure in section 4 was made exactly this way. It started with all weights at 0, used η=2\eta = 2, and took 600 steps. Each step averaged the blame over all 60 posts and moved every weight against it.

What to read next ?

Neural networks and backpropagation

A single neuron can only draw a straight line, so it can't learn XOR. Put neurons in layers, with the outputs of one layer feeding the next, and it can.

But now the chain from a weight to the loss runs through many layers. The blame for a weight deep inside depends on the blame of everything above it. Backpropagation is the chain rule from section 2, organized so each layer passes its blame down to the layer below, and no rate gets computed twice. It's how every neural network is trained. (you ll find its own post on this same blog, shortly after)

Attention and LLMs

LLMs read text as a sequence of words, and each word needs to know which other words matter for it.

Attention gives every pair of words a score, then turns the scores into weights with softmax, an e-based cousin of the sigmoid from section 5. Those scores come from weights too, and they're trained exactly like everything here: a loss, a gradient, and steps downhill. It also gets its own post.

Look inside: linear probes

When an LLM reads a post, it turns it into long lists of numbers inside itself, one list per layer. Nobody labels what those numbers mean. A linear probe asks: is "threat or not" written in there somewhere?

To find out, run many labeled posts through the model, collect those internal numbers, and train a logistic regression on them. That's exactly section 4, with the loss from section 5 and the steps from section 8. The only change is the inputs: instead of two classifier scores, the probe gets hundreds or thousands of the model's internal numbers.

If the probe can tell threats from non-threats, the model already knows the difference, stored along one straight direction inside it.

It's also cheap. The model reads each post once, writes nothing, and the probe on top is just a weighted sum. That's far less work than asking an LLM "is this a threat?" and waiting for an answer, post after post. When you have millions of posts, that difference matters.

That's the next post.