Skip to content
Tutorials Center
My learning

Topics

Large Language Models Tutorial

Learn Large Language Models step by step: 37 lessons in 9 chapters with examples, quizzes, diagrams and projects.

Start learning →

of lessons completed

Getting Started

  1. 1 What Is a Large Language Model? Learn what a large language model is, how it turns text into next-token predictions, why size matters, and what runs live in this course.
  2. 2 Next-Token Prediction Build n-gram language models in Python, measure them with probability and perplexity, and see why context length and data sparsity led to neural LLMs.
  3. 3 A Short History of LLMs Trace language modeling from n-grams and RNNs to the Transformer, BERT, GPT and instruction-tuned assistants, with a small RNN versus attention demo.
  4. 4 LLM Families and Model Sizes Compare encoder, decoder and encoder-decoder models, dense and mixture-of-experts designs, open and closed weights, and estimate memory from parameter count.

Tokens and Embeddings

  1. 5 Tokenization Basics See why LLMs split text into tokens, compare character, word and subword tokenizers in Python, and learn how tokens affect cost, context and odd model behavior.
  2. 6 Byte-Pair Encoding in Practice Train a byte-pair encoding tokenizer from scratch in Python: count pairs, learn merges, encode and decode text, and see how vocabulary size changes token counts.
  3. 7 Vocabulary, Special Tokens and Chat Templates Learn what special tokens like BOS, EOS and padding do, how chat templates turn messages into one token stream, and why template mistakes hurt output quality.
  4. 8 Token Embeddings Understand how an embedding table turns token ids into vectors, how cosine similarity measures meaning, and how vectors are learned from context, with NumPy demos.
  5. 9 Positional Encodings Why attention needs position information, and how learned, sinusoidal, rotary (RoPE) and ALiBi encodings work, with runnable NumPy demos you can plot.

Transformer Internals

  1. 10 Self-Attention Step by Step Compute scaled dot-product self-attention by hand: queries, keys, values, scores, softmax and weighted sums, with a NumPy implementation and a heatmap.
  2. 11 Multi-Head Attention and Masking Split attention into several heads, combine them with an output projection, and apply a causal mask so a decoder never sees future tokens. NumPy code included.
  3. 12 Feed-Forward Layers, Residuals and LayerNorm Learn the rest of a Transformer block: the feed-forward MLP with GELU or SwiGLU, residual connections, LayerNorm and RMSNorm, and pre-norm versus post-norm in NumPy.
  4. 13 The Decoder-Only Architecture End to End Assemble embeddings, causal attention, feed-forward layers and an output head into a complete decoder-only Transformer in NumPy, then count its parameters exactly.
  5. 14 Attention Variants: GQA, FlashAttention and Mixture of Experts Understand multi-query and grouped-query attention, FlashAttention tiling, sliding-window attention and mixture-of-experts routing, with runnable NumPy examples.

Training and Scaling

  1. 15 Pretraining Objective and Cross-Entropy Understand next-token cross-entropy loss, how to compute it from logits, how it relates to perplexity and bits per byte, and why teacher forcing allows parallel training.
  2. 16 The Training Loop and Gradient Descent Train a tiny bigram language model with gradient descent in NumPy, then learn about Adam, warmup and cosine schedules, gradient clipping, batches and mixed precision.
  3. 17 Data Pipelines for Pretraining See how pretraining corpora are built: crawling, cleaning, quality filters, exact and near-duplicate removal with MinHash, decontamination, data mixes and packing.
  4. 18 Scaling Laws and Compute Learn how loss follows power laws in parameters, data and compute, estimate training FLOPs, apply the Chinchilla token-per-parameter rule and fit a power law in Python.

Fine-tuning and Alignment

  1. 19 Fine-tuning vs Prompting Learn when to prompt, retrieve or fine-tune a large language model, what full fine-tuning costs in memory, and why a pretrained start beats training from scratch.
  2. 20 Supervised Fine-Tuning Understand instruction tuning: chat templates, special tokens, loss masking on assistant tokens, packing, data quality and the hyperparameters that matter for SFT.
  3. 21 LoRA and Parameter-Efficient Fine-Tuning See how LoRA adapts a frozen weight matrix with two small low-rank matrices, count the trainable parameters, train one in NumPy, merge it, and learn about QLoRA.
  4. 22 RLHF and DPO: Learning from Preferences Learn how LLMs are aligned with human preferences: Bradley-Terry reward models, the RLHF pipeline with a KL penalty, and DPO's closed-form loss, with NumPy examples.

Inference and Optimization

  1. 23 Decoding and Sampling Learn how a language model turns logits into text: greedy decoding, temperature, top-k, top-p (nucleus) sampling, repetition penalties and beam search, with NumPy code.
  2. 24 The KV Cache Understand why LLMs cache keys and values, verify in NumPy that caching gives identical outputs with far less work, and calculate KV cache memory for real model shapes.
  3. 25 Weight Quantization Learn how quantization shrinks LLM weights from 16 bits to 8 or 4: scales, zero points, per-channel and group-wise schemes, outliers, GPTQ and AWQ, with NumPy.
  4. 26 Serving, Batching and Speculative Decoding Learn how LLM servers balance latency and throughput: continuous batching, prefill vs decode, memory-bound math, speculative decoding speedups and key serving metrics.

Evaluation and Benchmarks

  1. 27 Perplexity and Language Metrics Compute cross-entropy, perplexity and bits per character from model probabilities, and learn exact match, token F1, BLEU-style overlap and when each metric misleads.
  2. 28 Benchmarks and Contamination Learn how LLM benchmarks work, how to attach bootstrap confidence intervals to accuracy, compute the unbiased pass@k estimator, and detect test-set contamination.
  3. 29 LLM-as-a-Judge and Human Evaluation Evaluate open-ended LLM answers with humans and model judges: rubrics, Cohen's kappa, position bias, pairwise comparisons, and Bradley-Terry or Elo rankings in NumPy.

Applications and Limits

  1. 30 Prompting Patterns Practical prompting for large language models: clear instructions, few-shot examples, chain-of-thought, self-consistency, structured JSON output with validation and retries.
  2. 31 Retrieval-Augmented Generation Build retrieval-augmented generation step by step: chunking documents, TF-IDF retrieval with scikit-learn, assembling grounded prompts, and measuring recall@k and failure modes.
  3. 32 Tool Use and Agents Learn how LLMs call tools: JSON schemas, the observe-act loop, argument validation, step limits and guardrails, with a runnable agent loop and a labelled scripted model.
  4. 33 Hallucinations, Bias and Safety Understand why language models hallucinate, how bias and calibration problems appear, and how prompt injection works, with runnable consistency checks and a defensive prompt demo.

Projects and Practice

  1. 34 Project: An Evaluation Harness Build a small evaluation harness for LLM prompts: test cases, graders, per-category scores, prompt comparison and regression checks, all runnable in your browser.
  2. 35 Project: Question Answering over Documents Build an end-to-end question-answering pipeline: chunk documents, retrieve with TF-IDF, abstain below a threshold, cite sources and measure accuracy, using a labelled stand-in generator.
  3. 36 Project: A Tiny Language Model Build a word-level bigram language model with NumPy: counting, smoothing, sampling with temperature and measuring perplexity, the same ideas behind full-size LLMs.
  4. 37 Practice: Exercises and Review Practice large language model skills with worked numeric exercises: token cost, KV cache size, LoRA parameter counts, quantization memory, perplexity and a final review quiz.