Gradient LabSign up free

Cheat sheets › Chapter 12

Generative models cheat sheet

Models that create new images, audio and text. Every lesson in one page: the key idea, the pseudocode and the terms.

Autoencoders

An autoencoder has two halves. The encoder (blue) squeezes an image through narrower and narrower layers.

encoder: image (784 numbers) → code (32 numbers)    # squeeze
decoder: code (32 numbers) → image (784 numbers)    # rebuild
loss = difference between the input and the rebuilt image

# the narrow bottleneck forces it to keep only what matters

Terms: autoencoder, bottleneck

Variational autoencoders

A plain autoencoder maps each image to one exact point, and the space between points can be meaningless. A variational autoencoder maps each image to a small cloud instead, and picks a random point inside it.

encoder: image → a small cloud (mean and spread) in latent space
sample a point from that cloud
decoder: point → image
loss = rebuild error + keep the clouds near the center    # a smooth space

generate: pick any point → decode → a brand-new image

Terms: latent space

GANs

A GAN has two networks. The generator turns random noise into fake images. The discriminator looks at an image and judges: real or fake?

generator: random noise → a fake image
discriminator: an image → "real" or "fake"?
repeat:
    train the discriminator to catch the fakes
    train the generator to fool the discriminator
# they push each other to improve

Terms: generator, discriminator

Diffusion models

Take a real image and add a little random noise. Then a little more, and more, until it’s pure static. This part is easy and needs no learning.

training:
    take a real image, add a little noise, again and again → pure static
    teach a network to predict the noise added at each step

generating:
    start from pure static
    repeat about 50 times: remove a bit of the predicted noise
    guided by the text prompt → an image appears

Terms: diffusion model

Revise with flashcards and quizzes. Free practice for every lesson in this chapter.

Open in the app