What is Generative AI
Generative AI is a class of artificial intelligence models that create new content rather than just classifying or predicting. Think of it like the difference between a food critic who rates dishes versus a chef who creates entirely new recipes. Discriminative AI learns boundaries between categories, while Generative AI learns the underlying distribution of data to produce novel samples.
Generative AI vs Discriminative AI
The difference is easier to spot in terms of the question each model answers. A discriminative model reports which label belongs to a given input, so a photo classifier that answers "cat, 0.94" is discriminative even when it is a billion parameters deep. A generative model reports what an input could look like, so a sampler that emits a fresh 1024-pixel face from a random seed is generative even when the network is small. Both families train with gradient descent and both can share the same convolutional or transformer blocks. What separates them is the objective: discriminative training minimises label error on a fixed dataset, while generative training minimises the gap between a learned data distribution and the real one, so the model must be able to imagine inputs rather than merely sort them.
A Practical Decision Rule
Ask what your product returns to the user. If it returns a class, a score, or a ranked list drawn from existing items, you need the conditional label distribution P(y|x) and a discriminative model. If it returns a document, image, waveform, token sequence, or molecule that did not exist before, you need P(x) or P(x|y) and a generative model. Three checks settle most design arguments:
- Novelty requirement. A recommender ranks songs that already exist; a text-to-audio model invents new ones. Novelty pushes you toward generation.
- Label availability. Discriminative training needs annotated examples. Fifty thousand labelled images support a solid classifier, while a language model can be trained on raw text with no labels at all.
- Output shape. A fixed-size vector such as one probability per class fits a discriminative head. A variable-length output such as a paragraph or a 512-frame clip needs a generative decoder that can stop on its own.
Production systems usually combine both: a generative model proposes candidates and a discriminative model scores them, which is exactly the mechanism behind best-of-n sampling and reranking.
Generative AI Taxonomy
Picking a Generator Family
The taxonomy is not academic. Each family carries a characteristic strength and a characteristic failure, so choosing one is a matter of matching those to the product constraint.
| Family | Typical output | Strong when | Usual failure |
|---|---|---|---|
| Autoregressive transformer | token sequences | long coherent text with instructions | repetition and invented facts |
| Diffusion model | images, video, audio | high fidelity under a text prompt | slow sampling, weak fine print |
| GAN | images, super-resolution | sharp texture, single-pass latency | mode collapse, unstable runs |
| VAE | latent codes, molecules | smooth interpolation, cheap sampling | blurry average-looking samples |
| Normalising flow | exact likelihoods | anomaly detection and density fits | expensive architectures |
A useful shortcut: if the output is a discrete sequence and long-range coherence is the product, start with an autoregressive transformer. If the output is a pixel grid that must match a text prompt, start with a diffusion model. Reach for a GAN only when you need one-step generation or a specific texture that diffusion will not produce, and reach for a VAE when you care more about the representation than about pixel-level realism.
Training Pipeline
What a Training Run Actually Costs
Public reports give a usable order of magnitude for planning. Pre-training a 7-billion-parameter model on roughly 1.5 trillion tokens requires on the order of 10^23 floating-point operations; spread across 512 A100-class GPUs at 60 percent utilisation that is about two weeks of wall-clock time. Training a diffusion model for one epoch over 10 million images at 512 by 512 resolution takes several hours on eight GPUs, and because such models see tens of epochs, the realistic budget is days rather than minutes. Fine-tuning that same 7-billion-parameter checkpoint with LoRA on 50,000 instruction examples fits on a single 80 GB accelerator and finishes in under an hour.
The asymmetry drives sensible spending. Pre-training is a capital expense amortised across every downstream product, so it is only worth attempting when you hold a data advantage nobody else has. Evaluation sets, prompt work, and fine-tuning are cheap enough to rerun weekly, and they usually deliver more product improvement per GPU-hour than a bigger base model would.
How Generative Models Learn
Think of a generative model like an apprentice artist. First, they study thousands of paintings (pre-training) to understand style, color, and composition. Then they specialize in portraits (fine-tuning). Finally, a mentor provides feedback on which works look most realistic (RLHF). The model learns the statistical patterns that make data "look real" and can then create new samples that follow those patterns.
The key insight is that generative models learn a compressed representation of the data distribution. Instead of memorizing examples, they capture the underlying structure - like learning the rules of grammar rather than memorizing every sentence.
Python Example: Simple Text Generator
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
model_name = "gpt2"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)
def generate_text(prompt, max_length=100, temperature=0.7):
inputs = tokenizer.encode(prompt, return_tensors="pt")
outputs = model.generate(
inputs,
max_length=max_length,
temperature=temperature,
do_sample=True,
top_k=50,
top_p=0.95,
pad_token_id=tokenizer.eos_token_id
)
return tokenizer.decode(outputs[0], skip_special_tokens=True)
prompt = "The future of artificial intelligence is"
result = generate_text(prompt)
print(result)
Key Generation Parameters
| Parameter | Effect | Typical Range |
|---|---|---|
| Temperature | Controls randomness - lower is more focused | 0.1 - 1.0 |
| Top-k | Limits vocabulary to k most likely tokens | 10 - 100 |
| Top-p | Nucleus sampling threshold | 0.8 - 0.95 |
| Max tokens | Maximum output length | 50 - 2048 |
Applications
Text Generation
- Chatbots and virtual assistants
- Content creation and copywriting
- Code generation and documentation
Image Generation
- Art and design creation
- Photo editing and enhancement
- Medical imaging synthesis
Code Generation
- Automated programming
- Bug detection and fixing
- Documentation writing
Hands-on Project: Explore Generative AI
import torch
from transformers import pipeline
# Create different generative pipelines
text_generator = pipeline("text-generation", model="gpt2")
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
# Generate creative text
prompts = [
"In a world where machines can dream,",
"The scientist discovered that",
"Once upon a time in the digital realm,"
]
for prompt in prompts:
result = text_generator(prompt, max_length=50, temperature=0.8)
print(f"Prompt: {prompt}")
print(f"Generated: {result[0]['generated_text']}\n")
Measuring Whether Generation Is Good
Generation breaks the metrics you rely on for classifiers, because there is no single correct output to compare against. Four measurements cover most needs, and they catch different failures.
- FrΓ©chet Inception Distance (FID) fits a Gaussian to Inception features of real images and another to generated images, then measures the distance between them. Values of 10 to 20 on ImageNet-scale sets are considered strong, and a move from 30 to 15 is visible to reviewers. It scores distribution match, not prompt adherence.
- CLIPScore or a prompt-alignment judge checks whether the image matches the words. A model can win on FID while ignoring "red bicycle", so always report both numbers together.
- Perplexity under an independent language model reveals whether generated text is fluent. Perplexity far above the training distribution signals degenerate output; perplexity far below it suggests memorised training text.
- Human preference, or a calibrated LLM judge, is the tiebreaker. A pairwise win rate of 50 percent means parity, while 60 percent means a difference a person can reliably notice.
Track all four and you catch the three usual failure modes: poor quality, ignored instructions, and memorisation.
Common Mistakes to Avoid
Common Mistakes
Calling every deep model generative
Fix: Check the objective: label prediction is discriminative, sampling new inputs is generative
Judging a generator only on sample sharpness
Fix: Report distribution distance, prompt alignment, and a memorisation check side by side
Planning to pre-train before shipping anything
Fix: Start from a released checkpoint and spend first compute on data, evaluation, and fine-tuning
Summary
Generative AI represents a fundamental shift from analyzing data to creating it. By learning the underlying distributions of data, these models can produce novel content across text, images, audio, and more. The training pipeline - from data collection through pre-training, fine-tuning, and alignment - transforms raw data into powerful creative tools.
Next: We explore Diffusion Models, the architecture behind modern image generation systems like Stable Diffusion and DALL-E.
Key Takeaways
- Discriminative models estimate P(y|x) for labels, while generative models estimate P(x) so they can sample inputs that never existed
- The choice rule is novelty, label availability, and output shape: fixed labels need a discriminative head, open-ended output needs a generative decoder
- Every generative family pairs a strength with a failure: diffusion for fidelity but slow sampling, GANs for sharpness but mode collapse, VAEs for smooth latents but blur
- Pre-training is a capital cost measured in weeks of GPU time, while evaluation and fine-tuning are cheap enough to rerun weekly and usually pay off sooner