Textual Inversion
Textual inversion teaches a frozen diffusion model one new word, a learned embedding for your object, using three photos and zero weight updates.
Why Does This Exist?
Every personalization method before it moved millions of weights. Fine-tuning a UNet for one teapot risks the model, the storage, and the setup time, all for a concept expressible as one word the model never learned. The heavy machinery exists for hard cases; most users need a light word, not a rebuilt brain.
Textual inversion learns exactly one embedding vector, numbers, for a placeholder token like S*. Everything else freezes. Three photos and a few thousand steps later, an oil painting of S* renders your teapot in any style the base model knows. The full-model alternative is DreamBooth, which trades weight updates for stronger identity.
Think of It Like This
Adding one entry to a dictionary
A library owns every book ever printed but its dictionary lacks the word for your family's stew. You do not rewrite the library; you slip one new dictionary card into the drawer defining your stew. Every reader, every recipe, every menu in the building can use the word immediately because the meaning plugs into existing language.
The embedding is the dictionary card and the frozen model is the library. It fails when one card must carry a whole cuisine: complex multi-object concepts overflow a single vector, which is why multi-embedding variants exist.
How It Actually Works
Introduce placeholder string S* mapped to a learnable vector . Freeze the UNet, the VAE, and the text encoder body; only receives gradients. Training minimises the standard diffusion denoising loss over – concept photos with neutral prompts like a photo of S*:
is the conditioning built from the learned vector. Because the loss is the model's native objective, optimisation needs no new machinery, just – steps on the tiny photo set. At inference, S* composes freely: S* on the moon, a statue of S*, each rendered with the base model's full stylistic range.
Worked example
Vector holds numbers versus million frozen UNet weights: the learned fraction is under one-millionth. Initialise from the embedding of the word teapot; initial loss on your teapot photos sits percent above the model's average photo loss, and converges to within percent after steps. The file on disk is KB, emailable, swappable, and stackable with other learned words.
Code
Learnable-token training loop in miniature, showing what freezes and what moves.
def train_step(v: list[float], grad: list[float], lr: float = 0.005) -> list[float]: """Update only the placeholder embedding; the model never moves.""" return [a - lr * g for a, g in zip(v, grad)] # UNet, VAE, text encoder frozen
v = [0.0] * 768 # placeholder embedding S*print(len(v) * 8) # -> 6144 bytes in float64, about 3 KB in float32Watch Out For
Underfitting complex subjects with one vector
A single -number vector carries limited identity. Ornate subjects, patterned fabrics, multi-part objects reconstruct approximately: right category, wrong details. Users blame the photo count and add more images that cannot fix a capacity ceiling.
Match capacity to subject: one vector for simple objects, two or three learned tokens for detailed ones. If likeness plateaus while loss keeps falling, capacity, not data, is the wall.
Neutral prompts that smuggle in style
Train with a painting of S* and the embedding absorbs painterliness along with identity; later a photo of S* still renders painterly. The placeholder soaks up everything constant across training captions.
Keep training prompts neutral and varied in background: a photo of S*, a cropped photo of S*. Reserve style words for inference.
The Quick Version
- Textual inversion learns one -number embedding for a placeholder like
S*. - The UNet, VAE, and text encoder stay completely frozen throughout training.
- Three photos and about steps close the loss gap from percent to percent.
- The result is a KB file composing freely with any prompt the base model handles.
- Single vectors underfit ornate subjects, and styled training captions leak style into identity.