ML Foundations
Data, parameters, loss, gradients, validation, and generalization.
TokenLab teaches how large language models are really made: tokenizer, embeddings, attention, and sampling, by letting you assemble and run tiny models right on your phone.
Lesson 12
Input
next-token prediction
Build block
Self-Attention
From tokens to transformer
Break text into tokens and map them to IDs, then back again.
Turn token IDs into vectors the model can actually reason over.
Let tokens weigh each other through Query, Key, and Value.
Convert logits into the next token with temperature and top-k.
Bite-size lessons
Short, precise lessons with the real math laid bare, then a quick check to make sure it stuck. Self-paced, no streaks, no pressure.
Chapter 3 / Lesson 3
softmax(Q x K^T / sqrt(dk)) x V
Quick check
What does a token's Query represent?
Model pipeline
Interactive builders
Stack tokenizer, embeddings, and attention blocks into a working architecture. Tap any block to inspect its shapes, weights, and what flows through it.
Playground
Choose a preset like Tiny GPT, Adapter, RAG, or Device Fit, then adjust the pieces that actually shape a small model: tokenizer, layers, embedding size, attention heads, context length, dataset size, training steps, eval split, temperature, top-p, and max tokens.
Each run shows estimated parameters, memory, latency, train loss, eval loss, pass rate, token flow, and pass/fail test results for training, alignment, RAG, or device readiness. Save runs as checkpoints, compare experiments, and keep the playground as your long-term model-building workspace.
Experiment 014
Run metrics
Params
1.8M
Memory
42 MB
Latency
18 ms
Train loss
1.72
Eval loss
1.91
Pass rate
86%
Test results
token flow
clean text to tokens to logits to sampled answer
Run real inference
Feed your model a prompt and see the next-token distribution live. Drag the temperature and watch a confident model turn playful in real time.
The cat sat on the ___
next-token prediction
18 core modules / 77 lessons
Start with the mechanics of a micro LLM, then move through post-training, retrieval, agents, evaluation, on-device deployment, robotics, and release readiness.
Data, parameters, loss, gradients, validation, and generalization.
Dataset preparation, tokenization, context windows, and next-token targets.
Progress from count-based models to neural networks and causal transformers.
Embeddings, attention, MLPs, residual connections, and normalization.
Configuration, batching, optimization, checkpoints, sampling, and debugging.
Prompting versus retrieval, full fine-tuning, LoRA, adapters, and serving.
Instruction training, preference data, reward models, DPO, and PPO-style RLHF.
Preference-data quality, reward calibration, DPO controls, and behavioral evaluation.
Embedding spaces, chunking, retrieval, reranking, and grounded generation.
Structured outputs, tool calling, routing, memory, state, and failure recovery.
Licensing, privacy, deduplication, contamination, filtering, and synthetic examples.
Golden evaluations, behavioral metrics, traces, regressions, and release gates.
KV caching, distillation, quantization, profiling, memory, latency, and Apple deployment.
Robot state, perception, control layers, feedback loops, and partial observability.
Scene grounding, spatial reasoning, skill planning, action representations, and VLA models.
Demonstrations, behavior cloning, policy fine-tuning, rewards, and offline learning.
Simulation, sim-to-real evaluation, independent safety limits, and human oversight.
Quality measurement, uncertainty, device constraints, privacy, model documentation, and release readiness.
Start with tokenization today. Free to begin, new lessons every month.
Download for iPhone