0:00Intro: MOFUSA Tech Academy
Welcome to MOFUSA Tech Academy. Beyond learning, towards mastery.
0:09Draw a blue mug from a sentence
Meera types a sentence: "A blue ceramic mug on a wooden table, in morning light." And out of static, that exact scene appears. Last episode, our diffusion model could generate mugs from noise, but it couldn't take instructions. To turn words into pictures, three more ideas are needed. A way to connect the meaning of text to the meaning of images. A way to make generation fast enough by working in a compressed space. And a way to steer the denoising towards the prompt: firmly, but not too firmly, as you can see from these three images.
Today: CLIP, latent diffusion, and guidance, the recipe behind modern text-to-image systems.
0:55Where we are: text-to-image
Season Three, Module Twelve, stop four: text-to-image.
1:01CLIP: words and pictures in one space
The first idea connects language to vision. It's called CLIP. CLIP has two encoders: one turns images into vectors, the other turns text into vectors, and both land in the same space. It's trained on a huge number of pictures paired with their captions, about four hundred million pairs in the original work. In each batch, it compares every image with every caption, forming a grid of similarities. The training pushes matching pairs, the diagonal of the grid, closer together, and mismatched pairs further apart. This is called contrastive learning.
Here's a toy version for Brightcart. The mug photo's vector has a cosine similarity of zero point nine nine with "a blue mug", but only zero point three six with "a desk lamp". The lamp photo matches "a desk lamp", and the kettle photo matches "a steel kettle". After dividing by a small temperature and applying softmax, each image puts nearly all its probability on the right caption. A space where words and pictures mean the same thing turns out to be enormously useful. It can classify images into categories it was never explicitly trained on, just by comparing the image with descriptions like "a photo of a teapot".
2:23Conditioning diffusion on text
Now we need to feed the meaning of the prompt into the diffusion model. A text encoder turns the prompt into a sequence of token vectors. Then, inside the denoising network, we add cross-attention layers, the same mechanism the original transformer used to connect its decoder to its encoder. Here, the queries come from regions of the image being denoised, and the keys and values come from the prompt's tokens. So each region can look up the words relevant to it: the mug's body attends to "blue" and "ceramic", the surface below to "wooden table", the highlights to "morning light".
The model is trained on huge numbers of images with captions, learning to predict the noise given the text. Now the text shapes every denoising step.
3:14Why image generation was slow
There's a practical problem. A five-hundred-and-twelve-pixel colour image contains almost eight hundred thousand numbers. Running a large network over all of them, for many denoising steps, for every image, is very slow and expensive. But much of that pixel detail is fine texture our eyes barely notice. What if we did the creative work in a much smaller, compressed space, and only filled in pixel detail at the end?
3:46Latent diffusion
That's latent diffusion. First, train an autoencoder, from episode forty-five, that compresses an image into a small latent grid: sixty-four by sixty-four by four, about sixteen thousand numbers, forty-eight times smaller than the pixels, and that can decode it back into a detailed image. Then run the entire diffusion process in that latent space: start from latent noise, and denoise it step by step, guided by the text. Only at the very end does the decoder turn the finished latent into a full-resolution picture. Working in a space forty-eight times smaller makes generation dramatically cheaper, enough to run on a good consumer graphics card.
This approach, published in two thousand twenty-two, became the basis of the widely used Stable Diffusion models.
4:40Classifier-free guidance
The third idea is guidance. Text conditioning alone often produces images that only loosely follow the prompt. We'd like to push harder towards it. The trick is called classifier-free guidance. During training, the caption is randomly dropped some of the time, so the same network learns two things: how to denoise with the prompt, and how to denoise without any prompt at all. At generation time, we compute both predictions. The difference between them points "towards the prompt". Then we exaggerate that difference by a guidance scale, w.
Here's one number. Without the prompt, the network predicts zero point two; with it, zero point five. At a guidance scale of one, we just use zero point five. At seven point five, we take zero point two plus seven and a half times the difference of zero point three: two point four five, pushed far further in the prompt's direction. It's a trade-off. Low guidance gives varied images that may drift from the prompt. Moderate guidance gives faithful images. Very high guidance gives harsh, oversaturated pictures with little variety.
Many tools expose this as a "guidance scale" setting.
6:02Practical controls: negative prompts and inpainting
In practice, artists and designers get a lot more control. A negative prompt, like "blurry, cluttered background", steers the image away from unwanted features. Image-to-image starts from a partly noised version of an existing photo, so the new image keeps its layout. Inpainting regenerates just a masked region: swap the wooden table for marble, leaving the mug untouched. Add-ons can steer composition using an outline, a depth map or a pose. And fine-tuning on a handful of photos teaches a model to draw one specific product consistently.
6:43Limits and responsibility
Text-to-image models still have limits. They can miscount objects, confuse "left of" and "right of", and historically struggled to draw legible text, though newer models have improved a lot. They can reproduce stereotypes from their training data: ask for "a CEO", and you may get a narrow picture of who that is. There are ongoing debates, and legal cases, about training on artists' work without permission. And realistic generated images raise questions of trust, which is why techniques for labelling and tracing AI-generated content are being developed.
For Brightcart, the rules are clear: label generated lifestyle images, and never show a product looking different from what customers will actually receive.
7:30Try it yourself: two more guidance scales
Same numbers as before: zero point two without the prompt, zero point five with it. What do we get with a guidance scale of zero, and with a scale of three? Pause. At zero, it's zero point two: the prompt is ignored completely, and the model draws whatever it likes. At three, it's zero point two plus three times zero point three: one point one. Low scales drift from the prompt; very high scales follow it so aggressively that images turn harsh and over-saturated. Most tools default to a moderate value in between.
8:12Pause & Predict: a close call for CLIP
Here's a close call for CLIP. A blurry photo scores zero point six two with "a blue mug", zero point six with "a blue jug", and zero point three with "a desk lamp". After dividing by a temperature of zero point zero seven, CLIP's starting value, and applying softmax, what are the probabilities? Pause.
About fifty-seven percent mug, forty-three percent jug, and almost nothing for the lamp. The temperature makes CLIP decisive, but here the top two are nearly tied, and a tiny change in the photo could flip the answer. When you use zero-shot classification, look at the margin, not just the winner.
8:59Writing a prompt
Sana needs a lifestyle image for a new mug. A good prompt is built in layers: the subject, "a matte sage-green ceramic mug"; the setting, "on a light oak table in a morning kitchen"; the lighting, "soft window light from the left"; and the style, "product photography, shallow depth of field". A negative prompt steers away from what she doesn't want, like text, watermarks or extra handles. Specific details beat long lists of buzzwords.
9:31Seeds, variations and settings
The seed controls the starting noise, so the same prompt, seed, model and settings give the same image again. Change only the seed, and you get a different composition from the same prompt. That suggests a good workflow: explore quickly with many seeds, pick a favourite, then refine it by adjusting the prompt or using more steps, while keeping that seed fixed so the composition stays put.
9:59Keep the real product real
For a shop, there's a crucial rule. A fully generated mug might get the handle shape or glaze colour slightly wrong, and that could mislead customers about what they're buying. So Brightcart photographs the real product, cuts it out with segmentation, and generates only the scene around it. Extra controls, like conditioning on the edges or depth of a reference image, keep the composition in check. Product images must show the product as it's actually sold.
10:30Classic failure modes
Text-to-image models have classic weaknesses, although newer models have improved on several. Text on packaging could come out garbled. Ask for three mugs and you might get four. Ask for a red mug and a blue plate, and the colours might swap. Hands and physical details can go strange. These failures come from weak links between particular words and particular parts of the image. So every generated image should be reviewed by a person before it's published. Keep in mind that details like these change fast. They were correct when this video was published, so treat them as a snapshot, not a permanent fact.
11:11Judging generated images
How do you judge generated images? CLIP can roughly score how well each image matches its prompt. FID, from the GAN episode, measures realism and variety across a large set. But for a brand, nothing replaces human review with a clear checklist: the right product, on-brand colours, no strange artefacts, and nothing misleading. Use automatic scores to handle scale, and people for judgement.
11:40Try it yourself: a patch reads the prompt
Let's see how the prompt actually reaches the picture. A patch on the mug's body asks its query, and compares it with the prompt's tokens, "sage", "green" and "mug". The scores are one point two, zero point four and two. After softmax, where does the patch look? Pause.
About sixty-one percent on "mug", twenty-seven on "sage", and twelve on "green". So this patch's update is mostly about being a mug, with some sage colour mixed in. Every patch does this at every denoising step, and if you map the attention for the word "mug" across the image, it lights up exactly where the mug is being drawn.
12:30Myth vs Fact
Myth: turning the guidance scale up always gives better images. Fact: it trades variety and natural appearance for faithfulness to the prompt. Too low, and the image wanders. Too high, and it looks harsh and repetitive. The best setting is usually somewhere in the middle, and depends on the model.
12:50Recap
Let's recap. CLIP learns a shared space where images and their descriptions land close together, using contrastive learning. Diffusion models are conditioned on text through cross-attention, so each image region can look up the words that concern it. Latent diffusion does all the denoising in a compressed latent space, forty-eight times smaller, and decodes at the end. Classifier-free guidance pushes predictions towards the prompt by a guidance scale. And practical controls, along with clear labelling, make these tools useful and responsible.
One sentence to remember: understand the words, work small, and steer firmly, but not too firmly.
13:36Next: speech, music and video
Mission complete. Meera's prompt becomes a picture: a blue ceramic mug on a wooden table, in morning light, clearly labelled as AI-generated. Next, generation beyond still images: synthetic voices, like the one you're listening to right now, plus music and video. How does a machine speak with expression, or keep a video consistent from frame to frame? That's the final stop in this module. See you on the map.