Skip to content
Tutorials Center
My learning

Topics

Generative AI, LLMs and Prompt Engineering Tutorial

Learn Generative AI, LLMs and Prompt Engineering step by step: 53 lessons in 14 chapters with examples, quizzes, diagrams and projects.

Start learning →

of lessons completed

Getting Started

  1. 1 What Is Generative AI? Learn what generative AI is, how it differs from predictive models, what large language models can and cannot do, and build a tiny text generator in Python.
  2. 2 How LLMs Are Trained Understand how large language models are trained: next-token prediction, scale and data, instruction tuning, RLHF, base versus chat models, loss and perplexity.
  3. 3 The Model Landscape Compare closed and open-weight language models, model sizes, context windows, multimodal and reasoning models, licensing, and learn how to choose one.
  4. 4 Calling an LLM API Learn how LLM APIs work: messages and roles, system prompts, sampling parameters, streaming, error handling with retries, and keeping API keys safe.

Tokens and Embeddings

  1. 5 Tokens and Tokenization Learn why language models read tokens instead of words, how subword vocabularies work, what special tokens do, and why numbers and spaces behave oddly.
  2. 6 Byte-Pair Encoding from Scratch Build byte-pair encoding step by step: count pairs, merge the most frequent, train a tiny vocabulary, then encode and decode text, including byte-level BPE.
  3. 7 Counting Tokens and Estimating Cost Learn rules of thumb for tokens per word, why input and output tokens are priced differently, and how to budget prompts and estimate LLM API costs.
  4. 8 Embeddings: Meaning as Numbers Understand embeddings: how words and sentences become vectors, why similar meanings land close together, and build a tiny embedding with SVD in NumPy.
  5. 9 Cosine Similarity and Semantic Search Learn dot product, cosine similarity and Euclidean distance, then build a tiny semantic search engine in NumPy and see why approximate indexes like HNSW exist.

Inside the Transformer

  1. 10 A Language Model in 20 Lines Build a bigram and trigram language model in plain Python: count next-word probabilities, generate text, measure perplexity and see why n-grams fail.
  2. 11 Attention from Scratch Learn self-attention step by step: queries, keys, values, scaled dot-product, softmax weights and causal masking, built in NumPy with a heatmap.
  3. 12 The Transformer Block Assemble a transformer block: multi-head attention, positional encoding, residual connections, layer norm and feed-forward layers, with a NumPy forward pass.
  4. 13 Context Windows and the KV Cache Learn what a context window is, why attention cost grows with length, why models lose the middle, and how to compute KV cache memory yourself.

Sampling and Decoding

  1. 14 Logits, Softmax and Temperature See how a language model turns raw scores (logits) into probabilities with softmax, and how temperature trades determinism for creativity.
  2. 15 Top-k, Top-p and Min-p Sampling Learn how top-k, top-p (nucleus) and min-p sampling cut off unlikely tokens, how to combine them with temperature, and how seeds make runs repeatable.
  3. 16 Greedy Decoding, Beam Search and Repetition Penalties Compare greedy decoding, beam search and sampling, then learn repetition and frequency penalties, stop sequences and logit bias with a toy decoder.

Prompt Engineering

  1. 17 The Anatomy of a Good Prompt Learn the parts of a strong LLM prompt: role, task, context, constraints, format, examples and delimiters, with a live prompt builder in Python.
  2. 18 Zero-Shot, One-Shot and Few-Shot Prompting Learn in-context learning: when to use zero-shot, one-shot or few-shot prompts, how to pick and order examples, and what examples cost in tokens.
  3. 19 Reasoning: Chain of Thought and Beyond Learn step-by-step prompting, scratchpads, self-consistency voting and decomposition, and when reasoning models make explicit chain of thought unnecessary.
  4. 20 Getting Structured Output (JSON) Make LLMs return reliable JSON: prompt for a schema, learn constrained decoding, validate with json and dataclasses, and retry when the output is invalid.
  5. 21 Prompt Templates and Versioning Turn prompts into reusable templates: variables, few-shot slots, safe handling of untrusted input, prompts stored as files, and version tracking with diffs.
  6. 22 Debugging and Improving Prompts Debug prompts like code: classify failures, build test cases, fix ambiguity and instruction conflicts, weigh prompt length, and avoid common anti-patterns.

Retrieval-Augmented Generation (RAG)

  1. 23 RAG: Giving Models Your Data Understand retrieval-augmented generation: why models need outside data, the retrieve-augment-generate pipeline, RAG vs fine-tuning vs long context, with a toy pipeline.
  2. 24 Chunking and Preparing Documents Prepare documents for retrieval: clean text, compare fixed-size, sentence and semantic chunking, choose overlap and chunk size, and attach useful metadata.
  3. 25 Vector Retrieval in Practice Embed a corpus, run top-k retrieval, add metadata filters and keep an index up to date. Build a tiny vector store in NumPy and learn what real ones add.
  4. 26 Hybrid Search and Reranking Combine BM25 keyword search with vector search using reciprocal rank fusion, then improve results with rerankers, query rewriting and HyDE. Live Python.
  5. 27 Answering with Context and Citations Assemble retrieved chunks into a grounded prompt, require citations, handle missing or conflicting sources and stay inside a context budget. Live Python.

Tools and Agents

  1. 28 Tool Use and Function Calling Learn how LLMs call tools: JSON schemas, the call and result message loop, parallel calls, argument validation and error handling, with a live dispatcher.
  2. 29 Building an Agent Loop Build a think-act-observe agent loop with the ReAct pattern, stop conditions, step limits, loop detection and tracing. Live Python with a scripted model.
  3. 30 Memory, Planning and Context Management Manage short-term and long-term memory for LLM agents: summarization, scratchpads, context trimming, plan-then-execute and sub-agents. Live Python examples.
  4. 31 MCP, Workflows and Multi-Agent Systems Learn what the Model Context Protocol does, how workflows differ from agents, and how routing, orchestrator-workers and evaluator loops work, with live Python.

Evaluation

  1. 32 Evaluating LLM Applications Learn why vibe checks fail and how to build LLM evaluations: test sets, golden answers, exact, regex and semantic checks, regression suites and sampling noise.
  2. 33 LLM-as-Judge and Human Review Use a model to grade open-ended answers: write rubrics, run pairwise comparisons, spot position and verbosity bias, and measure agreement with Cohen's kappa.
  3. 34 Metrics: Retrieval, Benchmarks and Statistics Compute precision and recall at k, MRR and nDCG for retrieval, understand benchmark contamination, and put confidence intervals around your eval scores.

Safety, Risks and Responsibility

  1. 35 Hallucinations and How to Reduce Them Understand why language models make things up, then reduce hallucinations with grounding, verification, confidence signals and self-consistency checks.
  2. 36 Prompt Injection and LLM Security Learn direct and indirect prompt injection, data exfiltration and jailbreaks, and defend with least privilege, output sanitization and layered guardrails.
  3. 37 Bias, Privacy, Copyright and Responsible Use Understand training-data bias, protect personal data with PII redaction, handle licensing and memorization, and build human oversight into LLM apps.

Customizing Models

  1. 38 Fine-Tuning vs Prompting Decide between prompting, RAG and fine-tuning, build and validate a chat JSONL dataset, and learn how to evaluate, cost and avoid overfitting.
  2. 39 LoRA, Quantization and Efficient Models See how LoRA adds small low-rank matrices instead of retraining everything, how 8-bit and 4-bit quantization shrink models, and do the memory math.
  3. 40 Alignment: RLHF, DPO and Preference Data Learn how preference pairs, reward models, RLHF and DPO make models helpful and safe, with a toy Bradley-Terry reward model you can train yourself.

Beyond Text

  1. 41 How Image Generation Works Understand diffusion models: adding and removing noise, latent space, text conditioning, classifier-free guidance, image prompting and editing.
  2. 42 Audio, Video and Multimodal Models See how speech-to-text, text-to-speech, vision-language models and video generation work, using spectrograms, image patches and shared embeddings.

Production

  1. 43 Cost, Latency and Caching Learn what drives LLM latency and cost: time to first token, streaming, batching, prompt caching, response caching and model routing, with simulators.
  2. 44 Deploying and Monitoring LLM Apps Learn how to run LLM apps reliably: gateways, rate limits, retries with backoff, traces, model versioning, feedback loops and fallbacks, with simulations.
  3. 45 Running Models Locally Learn how open-weight LLMs run on your own machine: GGUF and quantized formats, local runtimes, memory sizing for weights and KV cache, and local APIs.

Projects

  1. 46 Project: A Chatbot with Memory Build a chatbot step by step: conversation state, a system prompt and persona, history trimming and summaries, tested with a rule-based fake model.
  2. 47 Project: Question Answering over Documents Build a small RAG pipeline in Python: chunk documents, index them, retrieve the best passages and answer with citations using an extractive fake generator.
  3. 48 Project: An Evaluation Harness Build a small evaluation harness: test case format, runners, scorers, a pandas report and a regression comparison between two prompt versions.
  4. 49 Project: A Tool-Using Agent Build a small agent in Python: a tool registry, a ReAct loop, safety limits, a readable trace and tests that run against a scripted fake model.
  5. 50 Project: A Tiny Character-Level Language Model Train a character-level language model from scratch in NumPy: a bigram baseline, a small neural network, a loss curve, overfitting and sampling.

Practice and Review

  1. 51 Exercises with Solutions 24 graded Generative AI exercises with solutions: tokens, embeddings, sampling, prompts, RAG and evaluation, all runnable in your browser.
  2. 52 Generative AI Interview Questions 32 Generative AI interview questions with concise answers on LLMs, attention, sampling, RAG, agents, evaluation, safety and fine-tuning.
  3. 53 Generative AI Cheat Sheet A one-page Generative AI cheat sheet: key terms, sampling parameters, prompt patterns, RAG and evaluation checklists and common LLM failure modes.