Generative AI
Intermediate 14 min read Generative AI

Generative Models Overview

From memorizing data to sampling from it

Generative models learn to produce new examples that resemble the training distribution — text, images, audio. At the core are density learners (LLMs by next-token, diffusion by denoising) that turn a corpus into a sampling engine.

generative modelLLMdiffusiondistributionsamplinglikelihood
Before we start

What you will learn

  • Distinguish discriminative vs generative modeling
  • Describe what likelihood-based training does
  • Compare LLMs, diffusion and autoregressive music/audio generators
Introduction

What is this?

A generative model learns the probability distribution of the training data well enough to draw NEW samples from it. Discriminative models answer 'which class does x belong to'; generative models answer 'what does a plausible x look like'. Text: next-token (LLM). Images/speech: diffusion or GAN-style denoising. All share the same trick — train on a giant corpus, then sample the learned distribution at inference.

Motivation

Why do you need it?

  • One pretrained generative model performs many tasks because tasks are just conditioned sampling.
  • Generating is different from classifying: it needs a full density/sampling machinery, not a decision boundary.
  • Scale and compute turned fitted distributions into the most capable general systems in ML.
  • Product value: anything you can sample, you can automate — drafts, art, voice, code, summaries.
Think about it

Mental model

Imagine

A forger studying thousands of master paintings

Think of

A generative model on its training distribution

The forger never copies a canvas wholesale; they absorb the palette, brushwork, composition — the 'distribution' — and then paint new canvases that could plausibly hang in the same museum. As long as the style pays, the forger succeeds.

Mechanics

How it works

  • Choose a model family whose outputs are samples: text (token sequence), image (pixels), audio (frames).
  • Train to maximize data likelihood: LLM maximizes P(next token | prefix); diffusion maximizes the denoising score.
  • Neural nets act as samplers with different mechanics — autoregression, denoising, score flow.
  • Conditioning narrows the sampling: prompt, class label, or image mask direct the distribution.
  • Inference draws one sample per call; randomness gives variation, seeds make it reproducible.

Training fits a distribution; inference samples from it.

Corpus
Likelihood fit
Learned distribution
Prompt / cond
New sample
Real world

In production

  • Text: assistants, code completion, summarization, translation (LLM + sampling).
  • Image/speech: diffusion for art, avatars and voice synthesis.
  • Enterprise: sales drafting, RAG answers, synthetic data for testing classifiers.
Guidelines

Best practices

  • Treat the model as a sampler: control temperature/top-p, never as a deterministic database.
  • Cache and template prompts for cost and latency first; model choice second.
  • Define an evaluation — groundedness, factuality — before roll-out, not after.
  • Pin the model version and seed for reproducibility in tests.
Watch out

Common mistakes

  • Querying an LLM for facts with zero grounding (no RAG) and treating output as truth.
  • Measuring success by sample flavor instead of task metrics.
  • Over-fitting to one sampling parameter combo instead of evaluating across them.
  • Assuming bigger always equals faster/better answers — latency and cost scale too.
Root cause analysis

Common issues

Error
Model gives identical outputs for every prompt
Root cause

Temperature 0/greedy with over-fitting or collapsed output space

Fix

Raise temperature, verify sampling path, and check the prompt is actually reaching the model.

Error
Quality drops after switching models
Root cause

Different tokenizer/template shifting the intended task

Fix

Port the exact chat template/system prompt; re-tune decoding on the new model.

Error
Latency spikes under burst traffic
Root cause

Autoregressive generation serializes per token; concurrent fans multiply memory

Fix

Batch requests, quantize, and use smaller context plus streaming.

When things break

Debugging tips

  • Reproduce a published demo with a fixed seed before changing anything.
  • Compare same prompt across temperatures — variance tells you about model uncertainty, not bugs.
  • Log the exact input tokens and system prompt; most 'model behavior' mysteries are prompt mysteries.
  • Use a held-out checklist of hard cases to catch regressions each release.
Interviews

Interview checkpoint

Test yourself

Quick quiz

0/2
1

A generative model's training objective is fundamentally about:

2

LLMs and diffusion models use the same exact inference procedure.

Go deeper

Official documentation