00 ยท Essential Math & Intuitive Foundations
You do not need abstract pen-and-paper proofs or a 4-year degree in pure mathematics to master modern AI. You need 4 intuitive, applied math pillars that explain every vector, attention matrix, gradient step, and probability curve in LLMs.
Think of the LLM as a "Wise Scholar in a Library"
Imagine an elder scholar who spent years reading 100,000 books. When you ask them a question, there are two distinct ways they answer:
The scholar closes their eyes and speaks from compressed memory formed during years of study.
- Strength: Instant intuition, broad concepts, reasoning across themes.
- Weakness: Fuzzy on exact numbers/dates; might hallucinate false details.
You hand the scholar an exact open textbook page on their desk (the Context Window).
- Strength: 100% accurate quotes, latest numbers, verified citations.
- Weakness: Limited by desk size (Context Window token budget).
Linear Algebra: Vectors, Matrices & Tensors
The Language & Memory of Neural Networks
Computers cannot read characters like 'apple' or 'dog'. Neural networks operate exclusively on continuous numbers arranged in geometric dimensions:
- Scalar (0D): A single number (e.g. learning rate $\eta = 0.001$, loss $\mathcal{L} = 2.45$).
- Vector (1D): An array of numbers representing a concept in coordinate space (e.g. a token embedding with $d_{\text{model}} = 4096$).
- Matrix (2D): A grid of numbers representing linear projections, weight layers ($W_Q, W_K, W_V$), or token sequences ($[N \times D]$).
- Tensor (3D+): Multi-dimensional batches (e.g. $[\text{Batch}, \text{Heads}, \text{SeqLen}, d_k]$).
๐ Behind-the-Scenes: Why GPU Tensor Cores Dominate AI
Calculus & Optimization: How Models Learn
Gradients, Loss Functions & BackpropagationWhen an LLM is first initialized, its weights are completely random noise. How does it learn grammar, coding, and reasoning? Through Optimization Calculus:
- Loss Function ($\mathcal{L}$): A mathematical scoring metric (e.g. Cross-Entropy Loss) comparing the model's predicted probability distribution against the true target token.
- The Derivative / Gradient ($\nabla \mathcal{L}$): Tells us the slope: "If I increase weight $w_{i,j}$ by a tiny fraction, will the error go up or down?"
- Backpropagation (Chain Rule): Propagates errors backward through hundreds of Transformer layers via calculus chain rule $\frac{\partial \mathcal{L}}{\partial x} = \frac{\partial \mathcal{L}}{\partial y} \cdot \frac{\partial y}{\partial x}$.
- Gradient Descent & AdamW: Updates weights in the opposite direction of the gradient: $W_{\text{new}} = W_{\text{old}} - \eta \cdot \nabla \mathcal{L}$.
Probability & Statistics: How Models Decide
Softmax, Temperature, Sampling & EntropyAn LLM never outputs plain text directly; its final layer produces a vector of raw unnormalized scores called Logits across the entire vocabulary (e.g. 128,000 floats). Probability theory turns those logits into text:
- Softmax Normalization: Exponentiates logits to ensure positive values and divides by the sum: $P(y_i) = \frac{e^{z_i / T}}{\sum_j e^{z_j / T}}$, converting scores into a probability distribution summing to 1.0 (100%).
- Temperature ($T$): Scaling factor controlling distribution flatness. Low $T$ ($\to 0.1$) sharpens probabilities for deterministic factual answers; high $T$ ($\to 1.2$) flattens the curve for creative diversity.
- Top-$k$ & Top-$p$ (Nucleus) Sampling: Pruning the probability tail to avoid incoherent low-probability hallucinations.
Prompt context: "The sky is full of dark ____"
High-Dimensional Geometry: Similarity & Distance
Vector Space, Cosine Similarity & Metric SearchOnce text is embedded into vectors, semantic meaning becomes spatial geometry. Words or documents with similar meanings point in similar directions in multi-thousand-dimensional hyperspace:
- Dot Product ($\vec{a} \cdot \vec{b} = \sum a_i b_i$): Measures directional alignment and magnitude combined (used inside Self-Attention).
- Cosine Similarity ($\cos \theta = \frac{\vec{a} \cdot \vec{b}}{\|\vec{a}\| \|\vec{b}\|}$): Measures the angular angle between vectors regardless of text length (normalized between $-1.0$ and $+1.0$).
- Euclidean Distance ($L_2 = \sqrt{\sum (a_i - b_i)^2}$): Straight-line geometric distance between vector endpoints.
- The Curse of Dimensionality: In 1536 dimensions, all vectors tend to become orthogonal unless specifically trained into tight semantic manifolds.