Frontend Labs
⋯

0.5 The tiny bit of maths you actually need

You need four ideas. Not calculus. Not linear algebra courses. Four ideas. Each is explained again in context when it appears, so skim now and come back.

Idea 1 — A vector is just a list of numbers

[0.2, -0.5, 0.9]

That's a vector with 3 numbers ("3-dimensional"). In AI, a word might be a list of 300 numbers. A vector is a point in space — 3 numbers = a point in 3D space; 300 numbers = a point in 300-dimensional space (you can't picture it, and you don't need to).

Idea 2 — Similar things point in similar directions

To measure how similar two vectors are, we check the angle between them.

Point A = [1, 0]      (pointing right)
Point B = [0.9, 0.1]  (almost right)     -> very similar to A
Point C = [0, 1]      (pointing up)      -> not similar to A

The formula, called cosine similarity, gives 1 for "same direction", 0 for "unrelated", -1 for "opposite". You'll use it constantly. In Python:

import numpy as np
def cosine(a, b):
    a, b = np.array(a), np.array(b)
    return (a @ b) / (np.linalg.norm(a) * np.linalg.norm(b))

print(cosine([1,0], [0.9,0.1]))   # 0.994  -> very similar
print(cosine([1,0], [0,1]))       # 0.0    -> unrelated

a @ b is the dot product: multiply matching positions and add them up (1*0.9 + 0*0.1 = 0.9). It's big when two vectors point the same way.

Idea 3 — A matrix multiply is "apply a bunch of weighted sums at once"

A matrix is a grid of numbers. Multiplying a vector by a matrix turns it into a different vector. That is all a neural network layer does.

input  [1, 2]            weights          output
                    [[0.5, 1.0],
   [1, 2]     x      [2.0, 0.0]]    =   [1*0.5 + 2*2.0,  1*1.0 + 2*0.0]
                                      =  [4.5, 1.0]

You will never do this by hand. NumPy and PyTorch do it. You only need to know what it means: mix the inputs together in a learned way.

Idea 4 — Softmax turns any list of numbers into percentages

Given scores [2.0, 1.0, 0.1], softmax makes them positive and sum to 1:

import numpy as np
def softmax(x):
    e = np.exp(np.array(x) - np.max(x))   # subtract max for numerical safety
    return e / e.sum()

print(softmax([2.0, 1.0, 0.1]))   # [0.659, 0.242, 0.099]  -> sums to 1.0

Every time an LLM picks a word, it does this: turn scores into probabilities.

That's it

Everything else — gradients, backpropagation, attention — is built from these, and this guide builds it up slowly. If you want more maths later, Appendix B has a "Math corner" and §Further Reading points to good, gentle courses.

Further reading (only if you want more maths)

  • Video: 3Blue1Brown, Essence of Linear Algebra (YouTube, ~2 h total) — the best visual explanation of vectors and matrices that exists. Watch episodes 1–4.
  • Video: 3Blue1Brown, Neural Networks series, episodes 1–2.
  • Book (free): Mathematics for Machine Learning (Deisenroth, Faisal, Ong) — mml-book.github.io. Reference, not a page-turner.
  • Interactive: Khan Academy — Linear Algebra, and Statistics & Probability.
  • Python refresher: Automate the Boring Stuff with Python (free online) or the official Python Tutorial, chapters 3–5.

Generated from real-life-ai-example-v1.md · 8 Oct 2026 16:36