Module 10 / 17
Generative AI & Large Language Models
Understand models that generate text, images, and code, and use them with controlled data.
01 Generative Models and Training Data
Discriminative models choose labels such as spam or not spam, while generative models learn data patterns to create new examples. Autoregressive LLMs predict the next token; diffusion models gradually remove noise to form an image. GPT, Llama, Mistral, and Stable Diffusion illustrate these two families.
02 How Transformers Work
A tokenizer such as Byte Pair Encoding turns text into tokens, which become embeddings. Self-attention measures which tokens matter to one another, while positional encoding preserves order. During pre-training the model reduces next-token prediction error; temperature and top-p change variety, not factual correctness.
03 RAG, Fine-Tuning, and Tool Use
Retrieval-Augmented Generation (RAG) retrieves relevant document chunks before the LLM answers. Embeddings from text-embedding-3 or BGE can be searched with FAISS, pgvector, or Chroma. Fine-tuning and LoRA stabilize repeated formats, while validated JSON schemas make function calling safer for stock or calendar APIs.
04 Evaluation, Cost, and Risk
Test normal cases, edge cases, and questions with no answer. Measure groundedness, citation accuracy, latency, tokens per request, and human escalation. Treat hallucination as a real failure mode, protect system instructions from prompt injection, restrict tool permissions, redact personal data, and keep logs free of secrets.