datarekha
Section 7 chapters · 63 of 63 lessons

Generative AI

What an LLM is and isn't, the autoregressive loop, structured outputs, RAG that doesn't break, evals that mean something, and self-hosting at the edge of the GPU.

The Generative AI journey 0 / 63 completed
  1. Chapter 01

    Foundations

    12 lessons
  2. 01 What an LLM is A demystified, no-magic explanation of large language models — what they actually do, and what that implies for how you build with them. Beginner6 min
  3. 02 The autoregressive loop How an LLM actually generates text, one token at a time — and what that means for streaming, latency, and your UX. Beginner5 min
  4. 03 Sampling: temperature, top-k, top-p How the model actually picks the next token from its probability distribution, and when to use which sampling strategy in production. Intermediate6 min
  5. 04 Reasoning models & test-time compute o-series and R1-style models trade inference compute for accuracy by thinking longer before they answer. How test-time scaling works, when it's wor… Intermediate8 min
  6. 05 Structured outputs How to make an LLM emit valid JSON every time using Pydantic, JSON Schema, and constrained generation. Intermediate7 min
  7. 06 Constrained decoding How structured generation actually guarantees valid JSON — by masking illegal tokens at each decode step. The FSM/grammar trick behind XGrammar and… Advanced8 min
  8. 07 Mixture of Experts How do you get a trillion-parameter model that costs like a 13B one to run? Don't use all the parameters for every token. That's the MoE trick behi… Advanced8 min
  9. 08 Multimodal (vision & audio) LLMs How a model 'sees': a vision encoder turns an image into patch tokens that flow into the LLM alongside text. Why images cost so many tokens, and th… Intermediate8 min
  10. 09 Pretraining data: curation & dedup A model is what it eats. The internet is mostly junk, so the gap between a mediocre LLM and a frontier one is as much about the data pipeline — ext… Advanced9 min
  11. 10 Alignment: SFT, RLHF & DPO A freshly pretrained model completes text — it doesn't answer you. Three post-training stages turn that document-predictor into a helpful assistant… Advanced9 min
  12. 11 Direct Preference Optimization (DPO) RLHF aligns models with a reward model and a finicky RL loop. DPO throws both away — deriving, from the same preference data, a single classificati… Advanced10 min
  13. 12 Constitutional AI & RLAIF Training a model to be harmless usually means humans reading piles of toxic text to label it. Constitutional AI replaces that human feedback with t… Advanced9 min
  14. Chapter 02

    Prompting & Tools

    3 lessons
  15. 13 Prompt patterns that work Anthropic's priority-ordered prompt techniques — clarity, multishot, chain of thought, XML tags, document ordering, prefill, and prompt caching. Pl… Beginner7 min
  16. 14 Few-shot & chain-of-thought The two prompting techniques that still earn their keep — when to use few-shot examples, when to ask for reasoning, and when neither helps. Intermediate6 min
  17. 15 Function/tool calling How LLMs invoke functions — the schema contract, the request/response loop, and the production patterns for tool use. Intermediate8 min
  18. Chapter 03

    RAG & Adaptation

    10 lessons
  19. 16 Embeddings What an embedding actually IS — a point in semantic space. Distance metrics, dimensionality, and clustering short texts by meaning. Beginner6 min
  20. 17 Sentence embeddings: SBERT Embeddings as vectors showed what a sentence vector is; this is how you get a good one. BERT's cross-encoder is accurate for pairs but too slow to… Intermediate7 min
  21. 18 Vector databases Why a vector DB beats a numpy array at scale. HNSW, metadata filters, and the honest answer: most teams should start with pgvector. Intermediate9 min
  22. 19 RAG basics Retrieval-augmented generation: chunk, embed, store, retrieve, generate. The single most important pattern for any LLM app that touches private data. Intermediate8 min
  23. 20 Chunking for RAG RAG retrieves chunks — but where do chunks come from? You have to split documents first, and how you split is one of the highest-leverage decisions… Intermediate7 min
  24. 21 Advanced RAG Contextual retrieval (Anthropic's 49% recall win) plus the supporting techniques — hybrid retrieval with RRF, query rewriting (HyDE, multi-query),… Advanced9 min
  25. 22 Vectorless retrieval (PageIndex) Retrieval without embeddings — PageIndex turns a document into a tree the LLM reasons down. When it beats a vector database, and when it doesn't. Intermediate8 min
  26. 23 RAG evaluations How to actually measure RAG quality. Retrieval metrics (recall@k, MRR, hit rate) vs generation metrics (faithfulness, answer relevance, context pre… Advanced7 min
  27. 24 Fine-tune vs RAG: the decision RAG adds knowledge; fine-tuning changes behavior. The decision framework every team gets wrong, what LoRA/QLoRA actually change, and why 'we need t… Intermediate8 min
  28. 25 Fine-tuning: LoRA & QLoRA Full fine-tuning rewrites billions of weights you can't afford to store. LoRA freezes the model and trains a tiny low-rank 'diff' instead — here's… Advanced9 min
  29. Chapter 04

    Evaluation & Safety

    11 lessons
  30. 26 LLM evals & LLM-as-judge Vibes don't ship. How to build eval suites that catch regressions, when to use an LLM as a grader, and how to stop position, verbosity, and self-pr… Intermediate8 min
  31. 27 Hallucination & grounding Why models hallucinate, and how to measure faithfulness for real — decompose an answer into atomic claims and check each against the source. The me… Intermediate7 min
  32. 28 Prompt injection & guardrails Why LLMs can't tell instructions from data, the OWASP #1 risk, and the types of guardrails — input, output, instruction-hierarchy, and least-privil… Intermediate8 min
  33. 29 Guardrails & output validation An LLM is a probabilistic text generator wired into deterministic systems that expect valid JSON, no leaked PII, and on-policy answers. A guardrail… Advanced9 min
  34. 30 Llama Guard: safety classification The guardrails lesson named an 'ML-classifier tier' for safety. Llama Guard is that tier, concretely — a dedicated LLM fine-tuned to classify conte… Intermediate7 min
  35. 31 Reward hacking & Goodhart's law Alignment introduced reward hacking as the 'proxy risk' of preference training. This is the full picture: optimize any measurable proxy hard enough… Advanced8 min
  36. 32 Red-teaming LLMs Safety training and guardrails are defenses — red-teaming is how you find out whether they hold, by attacking your own system before anyone else do… Advanced8 min
  37. 33 A taxonomy of jailbreaks A jailbreak makes an aligned model do what its safety training forbids — and unlike prompt injection, the adversary is the user, attacking the mode… Advanced8 min
  38. 34 Watermarking AI content As machine-generated text and images flood the web, 'did an AI make this?' becomes a real question — for misinformation, academic integrity, and ke… Advanced8 min
  39. 35 Differential privacy for LLMs LLMs memorize their training data — and can be coaxed into regurgitating verbatim secrets, PII, and copyrighted text. Differential privacy is the m… Advanced8 min
  40. 36 Bias & fairness in LLMs Classical fairness is about a classifier's decisions — who gets the loan. LLMs add a second, language-shaped problem: they generate text, so they c… Advanced8 min
  41. Chapter 05

    Frontier safety

    7 lessons
  42. 37 Mesa-optimization & inner alignment Reward hacking is when your training objective is wrong. Mesa-optimization is subtler and scarier: even with a perfect objective, the trained model… Advanced7 min
  43. 38 Evidence for deceptive alignment Mesa-optimization predicted deceptive alignment — a model that fakes alignment during training. Is it real? Recent empirical work says the failure… Advanced7 min
  44. 39 AI control If a model might be deceptively misaligned and you can't be sure, alignment isn't the only lever. AI control takes a different tack: assume the mod… Advanced7 min
  45. 40 Scalable oversight RLHF works because humans can judge model outputs. But how do you supervise a model smarter than the humans supervising it? You can't reliably eval… Advanced7 min
  46. 41 Frontier safety frameworks How do labs decide a model is too dangerous to deploy — or even to keep training? Frontier safety frameworks turn that judgment into an if-then com… Advanced7 min
  47. 42 Recursive self-improvement Self-improving agents get better at a task. Recursive self-improvement is the scarier idea: a system that improves its own ability to improve, so g… Advanced7 min
  48. 43 Model welfare Every other safety topic asks whether AI is safe for us. Model welfare asks the inverted question: could an AI system itself be a moral patient — c… Advanced6 min
  49. Chapter 06

    Operations

    11 lessons
  50. 44 KV cache & continuous batching The KV cache is why LLM serving is memory-bound, not compute-bound. How caching keys and values makes generation fast, and how PagedAttention plus… Advanced8 min
  51. 45 KV cache offloading & memory tiers When the KV cache outgrows GPU VRAM, tier it across VRAM, CPU RAM, and SSD. Why the cache is working memory, and which tier to never use for live d… Advanced8 min
  52. 46 Cost & latency engineering Input vs output token economics, time-to-first-token, prompt caching, the router pattern, and semantic caching — the levers that move your bill by… Advanced7 min
  53. 47 Inference metrics: TTFT, ITL & goodput 'Fast' and 'high throughput' are different, often opposing numbers. To run an LLM service you need the operator's metrics — time-to-first-token, in… Advanced8 min
  54. 48 Model routing & cascades Most queries are easy. Routing only the hard ones to an expensive model — and cascading cheap-first — cuts LLM cost 45–85% at near-equal quality. T… Intermediate7 min
  55. 49 Self-hosting with vLLM When to run your own model and when to stay on an API. vLLM, quantization (GPTQ, AWQ, GGUF, bitsandbytes), VRAM math, and the honest break-even wit… Advanced8 min
  56. 50 Disaggregated serving (prefill/decode) Prefill is compute-bound, decode is memory-bound — yet a normal server runs both on the same GPU, where they fight. Disaggregated serving splits th… Advanced8 min
  57. 51 Quantization A 70B model needs 140 GB in full precision and zero consumer GPUs can hold it. Quantize it to 4-bit and it fits in 40 GB — for a few points of accu… Advanced8 min
  58. 52 GGUF & running LLMs locally Run LLMs on your own machine — the GGUF format, llama.cpp, and quantization tiers like Q4_K_M — with a tool that tells you which tier fits your RAM. Intermediate9 min
  59. 53 Distillation Quantization shrinks a model's weights. Distillation trains a brand-new, smaller model to copy a big one's behaviour — fewer layers, genuinely fast… Advanced9 min
  60. 54 Speculative Decoding LLMs generate one token at a time, which is slow. Speculative decoding lets a small model sprint ahead and a big model check its work in one shot —… Advanced8 min
  61. Chapter 07

    Systems Design at Scale

    9 lessons
  62. 55 Async vs sync — handling concurrency Why an LLM API serves 10,000 waiting requests on one thread — and when async helps, when it doesn't. Advanced9 min
  63. 56 System design boundaries Choose correctly between stateless and stateful services, Lambda and ECS, databases and caches, queues and streams, retrieval and reranking, and mo… Intermediate13 min
  64. 57 Load balancing LLM inference One GPU replica can't serve 10,000 users. How to spread LLM traffic across replicas — and why round-robin is the wrong default. Advanced9 min
  65. 58 Rate limiting & denial-of-wallet How to stop one client from running up a five-figure token bill on your inference API — the attack that targets your wallet, not your uptime. Advanced9 min
  66. 59 Caching: exact, semantic & prompt Your embedding API keeps answering the same question. Three kinds of cache that cut LLM cost and latency — and the one that can silently return wro… Advanced9 min
  67. 60 AI gateways The moment you call more than one model or provider, you have N SDKs, N auth schemes, N failure modes — and nowhere central for retries, rate limit… Advanced8 min
  68. 61 Queues & batch pipelines 50,000 documents won't go through your summarization pipeline in one request. How queues, workers, retries, and backpressure get the job done. Advanced9 min
  69. 62 Circuit breakers & resilience Your database (or model provider) goes down mid-query. How timeouts, retries, circuit breakers, and fallbacks stop one failure from taking down eve… Advanced9 min
  70. 63 LLM serving ops An LLM endpoint is still a production service — but GB-sized weights, minutes-long cold starts, GPU scarcity, and token-based capacity break the us… Advanced9 min
  71. End of section 0 / 63 complete

    Make it stick — pass every quiz.

    Each lesson has a short quiz at the bottom. Passing the quiz is what marks the lesson complete and counts toward your certificate.

FAQCommon questions

Generative AI — frequently asked questions

Straight answers to the questions people ask most about generative ai.

What actually is a large language model?

An LLM is a neural network (a transformer) trained to predict the next token in text. From that single objective, at scale, it learns grammar, facts, reasoning patterns, and style, then generates by predicting one token at a time. It doesn't look things up — it produces statistically likely continuations.

What is RAG and why use it?

RAG (Retrieval-Augmented Generation) retrieves relevant documents and feeds them into the model's context so it answers from your data instead of only its training. It reduces hallucination, lets you use private or up-to-date information, and avoids the cost of retraining the model.

Read the lesson
What do temperature, top-k, and top-p control?

They control randomness in generation. Temperature scales how sharply the model favors high-probability tokens — low is focused and near-deterministic, high is creative and riskier. Top-k and top-p (nucleus) limit sampling to the most likely tokens. Use low temperature for factual tasks, higher for brainstorming.

Read the lesson
Why does an LLM hallucinate, and how do I reduce it?

Because it generates plausible continuations rather than retrieving facts, it can state confident falsehoods, especially outside its training data. Reduce it by grounding answers with RAG, asking for citations, lowering temperature, and constraining the task — but you can't eliminate it, so verify critical outputs.

What's the difference between fine-tuning and RAG?

Fine-tuning adjusts the model's weights to change its style or specialise its behavior; RAG leaves the model unchanged and supplies knowledge at query time. Use RAG for facts that change or are private, and fine-tuning for consistent format, tone, or task behavior — they're often combined.

Skip to content