Intermediate

Generative Models

From diffusion models to GANs, explore the AI systems that create images, video, audio, 3D assets, and code from simple text prompts.

What Are Generative Models?

Generative models are AI systems designed to create new content that did not previously exist. Unlike discriminative models (which classify or analyze existing data), generative models learn the underlying distribution of their training data and produce novel outputs - images, videos, music, 3D objects, and code - that match the patterns they have learned.

The generative AI revolution began with GANs in 2014, accelerated with diffusion models in 2020-2022, and has since expanded to every creative modality. Today, generative models are among the most widely used and commercially impactful AI systems.

Image Generation

Diffusion Models

Diffusion models are currently the dominant approach for high-quality image generation. They work through a two-phase process:

  1. Forward diffusion: Gradually add random noise to an image until it becomes pure noise
  2. Reverse diffusion: Train a neural network to reverse this process - predicting and removing noise step by step until a clean image emerges

At generation time, you start with pure random noise and iteratively denoise it, guided by a text prompt through a mechanism called classifier-free guidance.

ModelCreatorQualitySpeedOpen/ClosedKey Feature
Stable Diffusion 3Stability AIExcellentFast (with optimizations)OpenMMDiT architecture, strong text rendering
DALL-E 3OpenAIExcellentModerateClosed (API)Tight text adherence, safety filters
Midjourney v6MidjourneyOutstandingModerateClosedAesthetic quality, artistic styles
FluxBlack Forest LabsExcellentFastOpen (some variants)Rectified flow, efficient generation
Ideogram 2.0IdeogramExcellentModerateClosedBest-in-class text rendering

GANs (Generative Adversarial Networks)

GANs were the first deep learning approach to produce photorealistic images. A GAN consists of two networks trained in opposition:

  • Generator: Creates fake images from random noise
  • Discriminator: Tries to distinguish real images from generated ones

This adversarial training pushes both networks to improve. While GANs have been largely superseded by diffusion models for general image generation, they remain relevant for specific applications like real-time face generation (StyleGAN) and super-resolution.

Historical note: GANs (introduced by Ian Goodfellow in 2014) dominated image generation from 2016-2021. StyleGAN could generate photorealistic faces that fooled humans. However, GANs were notoriously difficult to train (mode collapse, training instability) and struggled with diverse scenes. Diffusion models solved these issues while producing higher-quality results.

Video Generation

AI video generation has progressed rapidly, moving from short, low-quality clips to cinematic-quality videos lasting minutes.

ModelCreatorMax LengthQualityOpen/ClosedNotes
SoraOpenAI~60 secondsCinematicClosedSpatiotemporal patches, strong physics
Runway Gen-3 AlphaRunway~10 secondsHighClosedFast iteration, image-to-video
Kling 1.5Kuaishou~120 secondsHighClosedLong videos, good motion
Pika 1.5Pika Labs~4 secondsGoodClosedEasy to use, special effects
Wan 2.1Alibaba~5 secondsHighOpenOpen-source, competitive quality

Audio and Music Generation

Generative models now create music, sound effects, speech, and audio from text descriptions.

ModelTypeQualityOpen/ClosedHighlights
Suno v4Music + vocalsNear-professionalClosedFull songs with lyrics, multiple genres
UdioMusic + vocalsHighClosedStrong vocal quality, genre variety
MusicGenInstrumental musicGoodOpen (Meta)Text-to-music, melody conditioning
AudioCraftMusic + SFX + audioGoodOpen (Meta)Includes MusicGen, AudioGen, EnCodec
ElevenLabsSpeech synthesisExcellentClosedVoice cloning, emotional speech

3D Generation

3D content generation is one of the fastest-evolving areas, with models that create meshes, textures, and scenes from text or images.

  • Meshy: Text-to-3D and image-to-3D with PBR textures, suitable for game development
  • Point-E (OpenAI): Generates 3D point clouds from text, fast but lower quality
  • NeRF-based approaches: Neural Radiance Fields create photorealistic 3D scenes from 2D photos
  • Gaussian Splatting: Newer technique for real-time 3D scene reconstruction and rendering
  • Genie 2 (Google DeepMind): Generates playable 3D environments from single images

Code Generation Models

Code generation is one of the most commercially successful applications of generative AI. These models write, debug, explain, and refactor code across dozens of programming languages.

ModelCreatorLanguagesOpen/ClosedBest For
Claude CodeAnthropicAll majorClosedComplex reasoning, architecture, refactoring
GPT-4o + CodexOpenAIAll majorClosedGeneral coding, API integration
DeepSeek Coder V2DeepSeek300+ languagesOpenMulti-language, math + code
StarCoder 2BigCode600+ languagesOpenFill-in-the-middle, long context
CodeLlamaMetaMajor languagesOpenInfilling, instruction following
Qwen2.5-CoderAlibaba90+ languagesOpenStrong reasoning, efficient sizes

Prompt Engineering for Generative Models

Getting great results from generative models requires effective prompting. Each modality has its own best practices:

Image Prompts

  • Be specific about style: "oil painting," "photorealistic," "3D render," "watercolor illustration"
  • Describe composition: "close-up portrait," "aerial view," "rule of thirds"
  • Include lighting: "golden hour lighting," "dramatic rim light," "soft diffused light"
  • Specify quality: "highly detailed," "8K resolution," "professional photography"
  • Use negative prompts: Tell the model what to avoid (blurry, low quality, extra fingers)

Video Prompts

  • Describe motion: "camera slowly pans left," "person walks toward camera"
  • Set the scene: Include environment, time of day, weather, atmosphere
  • Keep it simple: Video models handle single scenes better than complex multi-shot narratives

Code Example: Generating Images with Stable Diffusion

Python - Image generation with Stable Diffusion via diffusers
import torch
from diffusers import StableDiffusion3Pipeline

# Load the Stable Diffusion 3 pipeline
pipe = StableDiffusion3Pipeline.from_pretrained(
    "stabilityai/stable-diffusion-3-medium-diffusers",
    torch_dtype=torch.float16,
)
pipe = pipe.to("cuda")

# Generate an image from a text prompt
prompt = (
    "A futuristic city at sunset, flying cars between glass skyscrapers, "
    "neon signs reflecting on wet streets, cyberpunk style, "
    "volumetric lighting, highly detailed, 8K"
)

negative_prompt = (
    "blurry, low quality, distorted, watermark, text overlay"
)

image = pipe(
    prompt=prompt,
    negative_prompt=negative_prompt,
    num_inference_steps=28,      # More steps = higher quality, slower
    guidance_scale=7.0,          # How closely to follow the prompt
    width=1024,
    height=1024,
    generator=torch.Generator("cuda").manual_seed(42),
).images[0]

image.save("futuristic_city.png")
print("Image saved successfully!")

# --- Batch generation with different seeds ---
images = []
for seed in range(4):
    result = pipe(
        prompt=prompt,
        negative_prompt=negative_prompt,
        num_inference_steps=28,
        guidance_scale=7.0,
        width=1024,
        height=1024,
        generator=torch.Generator("cuda").manual_seed(seed),
    )
    images.append(result.images[0])

# Save all variations
for i, img in enumerate(images):
    img.save(f"variation_{i}.png")

Ethical Considerations

Generative AI raises important ethical questions that practitioners must consider:

Deepfakes and Misinformation

Realistic image and video generation can be used to create convincing fake content of real people. This poses risks for fraud, political manipulation, and harassment. Many platforms now require AI-generated content to be labeled, and detection tools are actively being developed.

Copyright and Training Data

Generative models are trained on large datasets that may include copyrighted material. The legal landscape is evolving, with ongoing lawsuits from artists and publishers. Some models (like Adobe Firefly) are trained exclusively on licensed content to address this concern.

Consent and Likeness

Generating images or voices of real people without their consent raises legal and ethical issues around right of likeness. Many platforms prohibit generating content depicting identifiable individuals without permission.

Best practices: Always disclose when content is AI-generated. Avoid generating content that could deceive or harm others. Respect intellectual property and individual rights. Follow platform-specific policies and emerging regulations.

Use Cases Across Industries

  • Marketing and advertising: Generate product images, ad copy variations, social media content at scale
  • Entertainment: Concept art, storyboarding, music scoring, visual effects
  • Prototyping and design: Rapid UI mockups, architectural visualizations, fashion design concepts
  • Game development: Texture generation, NPC dialogue, level design, sound effects
  • Architecture: Generate photorealistic renders from floor plans and descriptions
  • Education: Create custom illustrations, diagrams, and interactive content
  • Software development: Code generation, test creation, documentation, debugging assistance

Comparison by Modality

ModalityTop ModelQualitySpeedTypical CostOpen Alternative
ImageMidjourney v6Outstanding~30 sec$0.01-0.04/imageStable Diffusion 3, Flux
VideoSoraCinematicMinutes$0.10-1.00/clipWan 2.1
MusicSuno v4Near-pro~30 sec$0.05-0.50/songMusicGen
SpeechElevenLabsExcellentReal-time$0.01-0.03/minBark, XTTS
3DMeshyGood~1 min$0.10-0.50/modelPoint-E, InstantMesh
CodeClaude / GPT-4oExcellentSecondsPer-token pricingDeepSeek Coder, StarCoder 2
Key takeaway: Generative models have democratized content creation across every medium. Understanding the strengths, limitations, and ethical implications of each modality is essential for leveraging these powerful tools responsibly.

Ready to Go Deeper?

Live instructor-led courses from our partners. Affiliate disclosure.