AI Compass
Compass

The maths AI actually needs

A map: which four areas of mathematics genuinely turn up inside AI systems, what each one is used for, and which ones you can safely skip.

·3 min read·By Fachredaktion Technik
DETAIL
3 sections

What this is about

A language model is, at heart, a very long chain of multiplications and additions. No single step in it is hard. What is hard is the quantity: a mid-sized model performs a few billion such operations for every single word.

That makes maths useful here in an unexpected way. You do not need it to do the arithmetic; you need it to understand which quantity depends on which. Once you have that, you can predict what happens when a model is made larger, fed different data, or run on weaker hardware.

The four areas

AreaAnswers the questionShows up in
Linear algebraWhat is being computed?Every layer, every embedding, every similarity search
Calculus (derivatives)How does learning happen?Training, gradient descent, backpropagation
ProbabilityHow certain is this?Output distribution, sampling, confidence, evaluation
Information and entropyHow good is this?Loss function, perplexity, compression

You can read each area on its own, but they hang together in a fixed order: linear algebra describes the forward path through the model, derivatives the way back, probability the output, and entropy the distance between output and intention.

What you can safely leave out

Understanding modern AI needs no differential geometry, no measure theory, no functional analysis and no complex numbers. Those appear in research papers, not in an explanation of what a model does.

What each area lets you actually compute

  1. 01

    Linear algebra: the size of a model

    A network with 32 layers, a width of 4096 and a feed-forward factor of 4 has roughly 32 × (4 × 4096²) ≈ 2.1 billion parameters in its feed-forward blocks alone. That number is pure matrix arithmetic, and it tells you directly how much memory you need.

  2. 02

    Derivatives, why training costs so much more

    The backward pass costs about twice the forward pass. Training is therefore roughly three times as expensive as inference per token, before anything has been said about the number of passes.

  3. 03

    Probability, what temperature does

    Temperature divides the logits before they become probabilities. At temperature 0 the most likely token always wins; at temperature 1 the model samples according to its own distribution.

  4. 04

    Entropy, what perplexity means

    A perplexity of 12 means, loosely: on average the model is as uncertain as if it had to choose between twelve equally likely continuations.

A learning path that works

  • Vectors and matrices first, until the dot product feels like an obvious similarity measure.
  • Then the chain rule, until it is clear why an error can travel back through many layers.
  • Then conditional probability and Bayes.
  • Entropy and cross-entropy last, because they bring the other two together.

All four areas in a single line

The entire training process of a language model fits into one line in which all four areas appear.

Training in one line

θ ← θ − η · ∇θ L(f(x; θ), y)

The new parameter set is the old one, shifted by the learning rate times the direction in which the loss falls fastest.

θ
the model parameters, several billion numbers
η
the learning rate, typically between 1e-5 and 1e-3
∇θ
the gradient: the derivative of the loss with respect to each parameter
L
the loss function, cross-entropy for language models
x, y
input and desired output from the training data
  • f(x; θ) is linear algebra: a chain of matrix multiplications.
  • ∇θ is calculus: the chain rule applied across every layer.
  • The output of f is a probability distribution.
  • L is information theory: cross-entropy between intent and output.

Estimating the cost

For a transformer with N parameters and D training tokens, the rule of thumb for floating-point operations during training is:

Training cost, rule of thumb

C ≈ 6 · N · D

Six operations per parameter per training token: two for the forward pass, four for the backward pass.

C
total cost in FLOPs
N
number of parameters
D
number of training tokens

Worked through for a 7-billion-parameter model on 2 trillion tokens: C ≈ 6 × 7e9 × 2e12 = 8.4e22 FLOPs. An accelerator delivering an effective 400 TFLOP/s (4e14 FLOP/s) would need about 2.1e8 seconds, roughly 6.7 years. With 1,000 cards at 50 % utilisation it is just under five days. That single calculation explains the structure of the entire market.

What this view does not give you

The rules of thumb say nothing about quality. Two models with identical cost can differ by orders of magnitude in usefulness, because data quality, curriculum and post-training are not in N and D. Maths bounds what is possible; it guarantees nothing.

Related courses and sources

BookFreeEN

Mathematics for Machine Learning

Exactly the mathematics machine learning needs and none of the rest. Linear algebra, calculus and probability in one volume, free as a PDF.

For anyone who wants exactly the mathematics machine learning needs and no more.

CourseFree2400 minEN

MIT 18.06 Linear Algebra

Gilbert Strang's lecture course, complete on video with problem sets. If you want to understand vectors, matrices and projections once and properly, this is the reference.

For anyone who wants to understand linear algebra properly once rather than look it up.

MIT OpenCourseWareGo to offer
Was this page helpful?
The maths AI actually needs