Learning outcomes
After this lesson, you will be able to:
- Distinguish generative and discriminative task formulations.
- Explain autoregression, VAEs, GANs, and diffusion models.
- Understand self-supervised learning and foundation models.
- Distinguish a generative model from RAG and tool-using systems.
- Evaluate output quality, diversity, factuality, and risks.
- Run an experiment with a simple autoregressive model.
1. What does it mean to generate?
Previous lessons covered models that classify objects, predict values, find groups, or select actions. A generative approach asks a different question: what regularities describe data, and how can we create a new example resembling the training data? A classifier may identify a technical document type; a generative model may draft a description. It does not know a specific object — it models data regularities.2. How a model builds a sequence
Text is usually split into tokens — words, subwords, characters, or other units. An autoregressive model estimates the next token given the current context, appends the selected token, and repeats.3. Four generative model families
Autoregressive models
They continue a sequence one element at a time. They suit text and other sequences, but generation is sequential and early errors can accumulate.Variational autoencoders (VAEs)
Generative adversarial networks (GANs)
Diffusion models
4. Foundation models and adaptation
5. RAG and tools: the model is not the whole system
6. Python practice: a character bigram model
Build a small model that counts which characters follow one another in sample phrases and generates new sequences. It is not a neural network or an LLM; it demonstrates conditional distributions.Environment: Python 3.10+, standard library only, no network access.
from collections import defaultdict, Counter
import random
corpus = [
"water is heated",
"water circulates",
"a pump creates flow",
"a sensor measures temperature",
"the system maintains a mode",
]
next_chars = defaultdict(Counter)
for text in corpus:
padded = "^" + text + "$"
for current, following in zip(padded, padded[1:]):
next_chars[current][following] += 1
def generate(max_length=80):
current, output = "^", []
for _ in range(max_length):
choices = next_chars.get(current)
if not choices:
break
chars, weights = zip(*choices.items())
current = random.choices(chars, weights=weights, k=1)[0]
if current == "$":
break
output.append(current)
return "".join(output)
random.seed(7)
for _ in range(5):
print(generate())The model learns local character transitions, not meaning. It may mix fragments, produce ungrammatical combinations, or repeat itself. Add sentences, change the seed, and check whether complete training phrases are copied.7. Practical assignment: choose an architecture
An engineering organization needs an AI service for four tasks: (1) classify requests; (2) draft technical descriptions from documents; (3) generate synthetic defect images; (4) answer questions using equipment diagrams and procedures. For each task, prepare a decision card: is generation needed; which approach fits (discriminative model, autoregression, diffusion, multimodality, RAG, or a combination); what data and rights are needed; two quality criteria; how to detect an error; and where a human is required. Deliver a four-row table with rationale. Choose the simplest sufficient approach, not the most complex one.Independent assignment
Submit a four-row decision table with rationale and limitations.
8. Quality, limitations, and risks
Evaluate task fit, factuality, diversity, consistency, controllability, cost, and latency. One good sample is not enough.9. Summary and boundaries of later lessons
Autoregression continues sequences; VAEs use probabilistic latent representations; GANs train generator and discriminator adversarially; diffusion models restore data from noise. Foundation models are reused across tasks, and multimodal models connect input types. RAG and tools can strengthen a system but are not synonyms for a generative model. Lessons 1.4.1–1.4.2 will examine models, parameters, training, and loss in depth; Theme 2 supplies mathematical foundations. Here the goal is to understand model families and their boundaries, not derive transformer architecture or tune an LLM.Sources and further reading
- Goodfellow et al. (2014), Generative Adversarial Nets
- Kingma & Welling (2013), Auto-Encoding Variational Bayes
- Ho et al. (2020), Denoising Diffusion Probabilistic Models
- Vaswani et al. (2017), Attention Is All You Need
- Brown et al. (2020), Language Models are Few-Shot Learners
- Bommasani et al. (2021), On the Opportunities and Risks of Foundation Models
- Lewis et al. (2020), Retrieval-Augmented Generation
Lesson glossary
Represents a data distribution and creates new examples.
Estimates a class or input-target relationship.
A unit of text after tokenization.
Step-by-step prediction of the next element from context.
A compact internal representation of data.
A probabilistic autoencoder with a latent representation.
An adversarial generator-discriminator system.
Generation by successive denoising.
A broadly pretrained model for many tasks.
Adding retrieved documents to context before generation.
Self-check
Question 1
What defines a generative model?
Question 2
How does autoregressive generation work?
Question 3
What is the VAE idea?
Question 4
What distinguishes a GAN?
Question 5
How does diffusion generation begin?
Question 6
What is a foundation model?
Question 7
What does RAG do?
Question 8
Which checks help evaluate a generative system? Select all.