Book Deep Read · Generative AI System Design Interview · Ch 5

Image Captioning: seeing the picture is the entry fee — nobody can say what "described it correctly" means

Generative AI System Design Interview · Ch 5 · Ali Aminian, Hao Sheng & Alex Xu · 2024

中文 →

What is this chapter about?

You glance at a photo on your phone and instantly know what is going on. But for someone who cannot see the screen, and for a system that has to file away hundreds of millions of images, the picture first has to become a sentence. This chapter is about getting a machine to look once and say something human — not "dog, grass, frisbee", but "a dog catching a frisbee on the grass".

A strange thing first

Machines are good at labels: there is a person here, a dog, a frisbee — and they are usually right. But read those three words to a friend who cannot see the photo and they still have no idea what happened. Did the person throw the frisbee to the dog, or did the dog bring it back? Labels list the things and drop every relation between them. And the relations are usually the point of the picture.

Why the old way was hard

So stitch the labels into a sentence? What comes out reads like an inventory: "person dog frisbee grass". Worse, ten people shown the same photo will write ten different sentences that are all correct — one describes the action, one the weather, one how delighted the dog looks. There is no single right answer, which makes teaching the machine and checking its work hard at the same time.

How it is actually done

Two people work in relay. The first one looks at the picture. He writes nothing down in words; he chops the image into a few hundred small squares and keeps one scribbled card per square — this one is furry, that one is green grass. The second one does the talking. He never sees the picture, only the stack of cards, and he speaks one word at a time; before each next word he flips back through the stack and pulls out the few cards that matter right now. Saying "dog", he is holding the furry ones; saying "frisbee", a different few.

How are the two trained? On web pages. Countless images online ship with a line of caption text attached, which hands you hundreds of millions of "picture plus sentence" pairs for free. The catch is plain: most of that text is junk — "click to enlarge" and the like — and over half has to be thrown out before any of it is usable.

How do you know it got it right?

The crude way: have five people each write a reference sentence for the same photo, then see how much wording the machine's sentence shares with theirs. But a paraphrase gets unfairly marked down — "puppy" and "canine" do not count as a match. So there is a second trick: bring in a scorer that looks at the picture, one that never reads the reference sentences and answers only one question — do this sentence and this picture go together?

The one thing to remember

Seeing the picture is the entry fee; the hard part is that nobody can state what "described it correctly" means, so everything from training to sign-off runs on a stack of approximations propping each other up. And the dangerous failure is not silence — it is a fluent sentence naming something that was never in the picture, which the listener has no way to check.

Want the mechanisms, the notation and the diagrams? → Switch to the deep read