liveBook · Manning

Vector arithmetic

As explained in Learn Generative AI with PyTorch

The manipulation of latent vectors by weighted averaging to interpolate between generated attributes in latent space.

Vector arithmetic interpolates between generated attributes by taking weighted averages of noise vectors in latent space. In a conditional GAN, the generator turns these interpolated vectors into images that transition between two instances, such as male and female faces. section 5.0 section 5.5.2

It differs from label arithmetic: vector arithmetic changes the selected noise vectors, while label arithmetic changes conditioning labels. Combining both lets a generator vary independent characteristics at once, such as facial gender and eyeglasses. section 5.5.3 section 5.6

Interpolating between two faces

Start with z_male_ng and z_female_ng, then choose weights 0, 0.25, 0.5, 0.75, and 1. For each weight w, calculate z = w*z_female_ng + (1-w)*z_male_ng. Reshape z to (1, z_dim, 1, 1), concatenate it with a label reshaped to (1, 2, 1, 1), and pass the result to the trained generator. The resulting five images progress from male features toward female features. Replacing labels_ng with labels_g repeats the interpolation with eyeglasses. section 5.5.2

Varying two characteristics

Use six interpolation values for the noise vector and six for the label to create a 6×6 grid. Moving down the columns changes the face gradually from male to female; moving across the rows makes eyeglasses gradually fade. section 5.5.3

How Learn Generative AI with PyTorch covers it

How deep it goes
Explains weighted averages, tensor preparation, generator inputs, and combined interpolation, but does not derive latent-space geometry.
Examples
Demonstrates male-to-female face interpolation, eyeglasses variation, and a 6×6 grid combining both transitions.
What it assumes
Assumes a trained conditional GAN, saved noise vectors, labels, a generator, and basic tensor reshaping.
What you can do after
Apply vector arithmetic by interpolating noise tensors and feeding them with labels into a trained generator.
How it connects
Connects latent space, conditional GANs, label arithmetic, and image generation.

Also explained in

Compare how 2 books explain vector arithmetic →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Generative AI with PyTorch. The section links point to the parts of the book it draws on.