← TinyGPT · docs · devlog · roadmap · speedup
source: docs/learn/session-04-ml-paradigms.md · view on GitHub ↗

Session 4 — The taxonomy of ML approaches (and where transformers fit)

Closes the open question from Session 3’s model dive: “is there tree regression? RL? learning by doing? Transformers don’t use all of them, so what are the other kinds and why aren’t transformers used for those?”

Short answer: the premise mixes three orthogonal axes. Untangling them shows transformers ARE used across most paradigms, just not all model families. This session pulls the axes apart and then dives deep on transformers specifically.

The confusion: “ML approach” mixes three different things

When people say “supervised learning,” “neural net,” “gradient descent,” “RL,” “tree regression” — they’re naming things from three different axes that are mostly independent and freely combine. The single biggest clarifying move:

TRAINING SIGNAL × MODEL FAMILY × UPDATE ALGORITHM
   (what you      (what shape    (how parameters
    learn from)    the function     change)
                   takes)

Every actual ML system picks one from each axis. Most “X vs Y” debates people have are really about ONE axis while the other two are held constant.


Axis 1 — Training signal (what you learn FROM)

ParadigmSignal looks likeCanonical example
Supervised(input, correct answer) pairsspam classification with labeled emails
Self-supervisedlabel derived from input itselfnext-token prediction — label IS the next word
Unsupervisedno labelsk-means clustering, PCA, autoencoders
Reinforcementreward signal from environmentgame-playing agent, RLHF
Semi-supervisedmix of labeled + unlabeledrare in modern practice — replaced by SSL pretraining + supervised fine-tune

Self-supervised is the big shift of the last decade. Modern LLMs are self-supervised: the “label” for predicting the next word is just the next word that actually came in the training corpus. No human had to label anything; the data labels itself. This is what made LLM-scale pretraining possible — you can use the entire internet as training data without labeling effort.

Reinforcement learning has a different shape: instead of “here’s what you should have said,” the signal is “here’s how good what you did was.” The agent acts, the environment gives a reward, the agent learns to take actions that lead to more reward over time. Classical RL: game playing, robotics. Modern application: RLHF — the second training stage that turns a raw pretrained LLM into ChatGPT.


Axis 2 — Model family (what shape the function takes)

FamilyFunction shapeBest for
Linear regression / GLMsline / planetabular numeric prediction with small data
Decision treestree of yes/no splits on featuressmall tabular
Random forestsaverage of many treesmedium tabular
Gradient-boosted trees (XGBoost, LightGBM)sequence of trees each correcting prior errorstabular data — often beats neural nets
SVMsmargin-maximizing boundaryclassical classification, small data
k-NN”copy the nearest training examples”recommenders, image lookup
Bayesian methodsfull probability distributionswhen calibrated uncertainty matters
Neural networks: CNNshared-weight convolutionsimages
Neural networks: RNN / LSTMshared-weight recurrencesequences (replaced by transformers)
Neural networks: Transformershared-weight self-attentionsequences, the modern default for language/audio/video

Trees vs neural nets is the most underrated debate. On tabular data (rows × columns of features, like a CSV), gradient-boosted trees often beat transformers. The reason: trees have strong inductive biases that match how tabular data actually works — they handle missing values, categorical features, and non-monotonic relationships natively, without needing millions of examples to learn those tricks. Most Kaggle wins on tabular problems are XGBoost or LightGBM, not transformers.

Transformers vs everything else for sequential, high-dimensional data: basically no contest now. Language, audio, video, DNA — transformer variants have eaten the field.


Axis 3 — Parameter update algorithm (how the parameters change)

AlgorithmIdeaUsed for
Gradient descent / SGD / Adamstep against the gradient of lossanything differentiable (= almost all NNs)
Closed-form (normal equation)solve algebraically for the optimumlinear regression with MSE — 1805 math
Tree-building (CART, ID3)greedily pick best split at each nodedecision trees
Gradient boostingfit each new tree to residual errors of the prior ensembleGBT / XGBoost
EM (Expectation-Maximization)iteratively fill in missing labels and refitGaussian mixtures, HMMs
MCMC (Markov Chain Monte Carlo)sample from a probability distributionBayesian posterior inference
Policy gradient / Q-learning / Actor-Criticstep parameters to maximize expected rewardRL

The axes are mostly independent: you can pair any signal with any family with any update algorithm, as long as the math works out. The “works out” caveat is what differentiable models care about — gradient descent needs the model to be differentiable, which is why neural nets and SGD pair so naturally.


The matrix — what combinations are common

CombinationName people useExample system
transformer + self-supervised + SGDpretrainingGPT-4 base, your huge-base-v1.tinygpt
transformer + supervised + SGDSFT (supervised fine-tuning)InstructGPT phase 1
transformer + RL + policy gradientRLHF / RLAIFChatGPT, Claude, Llama-Chat
neural net + RL + variousdeep RLAlphaGo, AlphaStar, OpenAI Five
GBT + supervised + boostingXGBoostmost tabular Kaggle wins
linear + supervised + closed-formordinary least squaresmost statistical regression
Bayesian + supervised + MCMCBayesian regressioncalibrated uncertainty
autoencoder + self-supervised + SGDrepresentation learningSimCLR, MoCo, MAE

So the claim “transformers don’t use RL” was wrong. The combination transformer + RL is exactly RLHF, used in every modern frontier model. The model family stays transformer; the training signal changes from self-supervised next-token to reward-from-human-preference.


Deep dive: transformers across the matrix

The transformer is one model family, but it shows up in several training configurations. Worth knowing what each is for.

Pretraining (self-supervised, SGD)

The base layer of every modern LLM. The training task: given the first N tokens of a document, predict the (N+1)-th token. Loss is cross-entropy.

Why it works: predicting the next word forces the model to internalize a huge amount of knowledge about how language works, what facts are true, what reasonable arguments look like, etc. There’s no other way to predict “the capital of France is ____” correctly without knowing the capital of France.

Your huge-base-v1.tinygpt is this. 200,000 SGD steps over ~410M tokens of FineWeb-Edu. Loss went from 11.37 (uniform random) to 4.16 (good language model). At the end, the model knows English grammar, common factual associations, and basic reasoning patterns — purely from predicting the next token.

Encoder-only (BERT-style, masked language modeling)

Different self-supervised task: randomly hide some tokens in a sentence and predict the hidden ones from BOTH sides of context. The transformer sees the whole sentence at once, not just the past.

Use case: classification, retrieval, embedding. The encoder produces a rich representation of the sentence as a whole. Not used for generation — it can’t produce text token by token because it sees the future.

Examples: BERT, RoBERTa, MiniLM. Smaller than modern LLMs. Used heavily inside search engines and retrieval pipelines.

Decoder-only (GPT-style, causal language modeling)

What your model is. The transformer is masked so each token only sees tokens BEFORE it — never the future. This is what makes generation possible: you can produce one token at a time, and the model isn’t “cheating” by peeking ahead.

This is the modern default. GPT-2/3/4, Claude, Llama, Mistral, Qwen, DeepSeek, Phi — all decoder-only.

Encoder-decoder (T5-style)

The encoder reads the input fully; the decoder generates the output token-by-token, attending to the encoder’s representation. Used for sequence-to-sequence tasks where input and output are clearly distinct: translation (English → French), summarization (article → summary), code generation (description → code).

Examples: T5, BART, FLAN-T5. Mostly replaced by decoder-only models with prompting, but still common in production systems where the input/output boundary is clean.

Supervised fine-tuning (SFT)

Take a pretrained base model and continue training on (prompt, ideal response) pairs collected from humans. Same SGD on cross-entropy loss, but now the “label” is a human-written answer instead of “the next token that randomly came in web text.”

This is what gives the model a consistent assistant persona. After pretraining, the model knows everything but doesn’t know it’s supposed to be helpful; SFT teaches the pattern of “user asks → assistant answers helpfully and concisely.”

In TinyGPT terms: tinygpt sft is this. Most fine-tunes use LoRA so they only update a small fraction of parameters — see Lora.swift.

RLHF / RLAIF

Take the SFT’d model and continue training with reinforcement learning. A reward model (itself a transformer, trained on human preference pairs) scores the model’s outputs; policy gradient nudges the model’s parameters to produce higher-scoring outputs.

Why this stage exists: after SFT the model is helpful but still has lots of failure modes — preferring shorter responses when longer are better, saying things that sound right but aren’t, repeating itself. RLHF pushes the model toward outputs humans actually prefer in side-by-side comparisons.

This is the same transformer architecture, the same parameter set — trained with a different signal (reward vs cross-entropy) and a different algorithm (policy gradient vs vanilla SGD).


Why transformers won

Two reasons people usually give:

  1. Attention can model any-to-any token interaction in one layer. RNNs propagate information sequentially; the gradient has to flow through many timesteps to connect a token to one 200 positions earlier. Transformers attend directly. Long-range dependencies are O(1) hops instead of O(length).

  2. Transformers parallelize on GPU. RNNs are inherently sequential — you can’t compute step 100 until step 99 is done. Transformers process all tokens in parallel. This is the practical reason that scaling transformers up is feasible while scaling RNNs up wasn’t.

There’s also a sneakier reason: transformers’ inductive bias is weaker than RNNs or CNNs, which sounds bad but is actually good when you have enough data. CNNs assume spatial locality matters; RNNs assume temporal locality matters. Transformers assume neither. With small data this hurts (RNNs and CNNs win on tasks like small-image classification). With internet-scale data, it helps — the model learns whatever locality structure actually exists rather than having one baked in.


Where transformers are NOT the right tool

ScenarioBetter toolWhy
Tabular data (rows × columns)gradient-boosted trees (XGBoost)trees have right inductive bias for tabular structure
< 1000 training exampleslinear regression, SVMs, Bayesian methodsNNs need lots of data; simpler models with strong priors win
Need calibrated probabilityBayesian methods, Gaussian processesNN softmax probabilities are notoriously overconfident
Strict latency / tiny devicedistilled small NN, decision treestransformers are heavy; classical methods are fast
Tasks needing exact rules / guaranteessymbolic systems, constraint solversNNs are probabilistic, can be wrong

The transformer’s specific edge — sequential high-dimensional data with internet-scale training corpora — happens to match the most economically important AI problems of the last decade (language, vision, audio, multimodal). That doesn’t make it the right tool for everything.


Self-check

Don’t peek:

  1. Name a system that combines transformer + RL. What’s the training signal there, and how is it different from pretraining?
  2. You’re a data scientist with 5,000 rows of structured customer data and need to predict churn. What model family would you reach for first, and why?
  3. Why is “self-supervised” a misleadingly named paradigm? What’s the honest description of where the labels come from?
  4. Trap question: if transformers can theoretically model anything (a universal approximator), and we have infinite compute, do we still need trees, SVMs, Bayesian methods? Why or why not?

The trap question is the interesting one. Think about it before peeking at the answer below.


Trap answer (for #4)

Yes, we’d still need them. Three reasons:

  1. Inductive bias matters when data is limited. Even with infinite compute, you don’t have infinite data for every task. Simpler models with stronger priors generalize better from small datasets. Universal approximation doesn’t mean “best from small data.”

  2. Calibrated uncertainty. Neural nets are notoriously bad at “I don’t know.” Bayesian methods natively express uncertainty. For high-stakes decisions (medical, financial), the uncertainty estimate matters more than the point prediction.

  3. Interpretability. A decision tree’s reasoning is “if income > 50K and credit_score < 600, then deny” — directly readable. A transformer’s reasoning is buried in 22M floats. For regulated industries (insurance, lending), interpretability is mandatory.

Universal approximation is a statement about what’s expressible, not about what’s learnable from finite data, with calibrated confidence, in a human-checkable way. Those other axes still matter, and other model families still win on them.


Where this connects