Sohail Sarwar ← Back to Index

Algebra of AI

Sat, 24 Oct 2026

My take to understand how AI models actually work, in the simplest way possible.


It's predictable vs. unpredictable

It's predictable vs. unpredictable

Traditional software gives the same output for the same input. Most AI models don't. They learn patterns from data instead of following hand-written rules, so the same prompt can produce different answers.


Neural networks are just math

Neural networks are just math

A neural network is layers of simple units that pass numbers along, each applying learned weights. Given some text, the output is a probability for every possible next word. Under the hood it's linear algebra, calculus, and statistics.


Text becomes tokens

Neural networks are just math

Models can't read words, so text is split into small chunks called tokens and mapped to numbers. Splitting into subwords lets a model handle rare words and typos it has never seen.


Training is a big loop

Training is a big loop

Pretraining repeats four steps: make a prediction, measure the error, work out which parameters caused it, and nudge them to do better. Repeat that billions of times over huge amounts of text and the model gets good at predicting what comes next.


Transformers changed everything

Transformers changed everything

Self-attention lets a model look at a whole sentence at once and figure out which words relate to each other, like what "it" refers to. It also parallelizes well on GPUs, which is why models could scale so far.


Shaping the model

Shaping the model

After pretraining, fine-tuning adapts the model to a domain, and reinforcement learning from human feedback teaches it which answers people prefer. Distillation then shrinks it into something cheaper and faster to run.


Test it

Test it

Treat evals like tests for AI. If you don't measure what matters for your use case, you won't notice when quality slips.


P.S. none of this is magic. Understanding the pieces makes the tools you use every day easier to reason about.