Latent space playgroundLaboratorio dello spazio latente

An autoencoder compresses each image of a digit into a code of two numbers and learns to rebuild the image from the code alone, so that every digit becomes a point of the plane and every point of the plane an image. Trained only to reconstruct, it leaves wide regions between the classes whose points decode to nothing recognizable; the variational version encodes each digit as a small Gaussian and pays, in the KL term, for moving it away from a standard normal, which packs the codes around the origin and makes (almost) the whole plane decodable.

Un autoencoder comprime ogni immagine di una cifra in un codice di due numeri e impara a ricostruire l'immagine dal solo codice, così che ogni cifra diventa un punto del piano e ogni punto del piano un'immagine. Addestrato solo a ricostruire, lascia fra le classi ampie regioni i cui punti si decodificano in nulla di riconoscibile; la versione variazionale codifica ogni cifra come una piccola gaussiana e paga, nel termine KL, l'allontanarsi da una normale standard, il che addensa i codici attorno all'origine e rende decodificabile (quasi) tutto il piano.

The latent plane: the code of each of 600 held-out digits, colored by its class (for the VAE the mean \(\mu(x)\), with the circles of radius 1 and 2 of the prior). Drag the ring to decode any point; click two digits to interpolate between them.Il piano latente: il codice di ciascuna di 600 cifre tenute da parte, colorato secondo la sua classe (per il VAE la media \(\mu(x)\), con i cerchi di raggio 1 e 2 della prior). Trascina l'anello per decodificare un punto qualsiasi; fai clic su due cifre per interpolare fra di esse.
The same square of the plane, cut into 12×12 cells, each showing what the decoder makes of the point at its center: the regions that no digit maps to decode to blurs or to mixtures, until the VAE fills them.Lo stesso quadrato del piano, diviso in 12×12 celle, ciascuna delle quali mostra che cosa il decoder ricava dal punto al suo centro: le regioni in cui non cade alcuna cifra si decodificano in macchie o in miscugli, finché il VAE non le riempie.

The point under the ring, decoded, and the interpolation between the two digits clicked on the plane: the images decoded at evenly spaced points of the segment that joins their codes.Il punto sotto l'anello, decodificato, e l'interpolazione fra le due cifre scelte sul piano: le immagini decodificate in punti equispaziati del segmento che unisce i loro codici.

decoded at the ringdecodificato all'anello

the ringl'anello

Draw a digit with the mouse or a finger: it is scaled and centered as the training digits are (its inked box to 16 pixels, its center of mass in the middle, as for MNIST), its code is the gold diamond on both views, and on the right is the image decoded from that code.Disegna una cifra con il mouse o con un dito: è scalata e centrata come le cifre di addestramento (il riquadro inchiostrato a 16 pixel, il baricentro nel mezzo, come per MNIST), il suo codice è il rombo oro in entrambe le viste, e a destra c'è l'immagine decodificata da quel codice.

inputingresso

reconstructionricostruzione

The VAE maximizes, for each digit \(x\), the evidence lower bound below (with weight \(\beta\) on its second term), and the curves show its two terms per digit as losses, averaged over the last batches: the reconstruction error \(-\mathbb{E}\log p_\theta(x\mid z)\), the binary cross-entropy of the decoded image, and the KL divergence of \(q_\phi(z\mid x) = \mathcal{N}(\mu, \mathrm{diag}\,\sigma^2)\) from the prior. The plain autoencoder sets \(z = \mu(x)\) and minimizes the first term only. Hover a curve or a term to highlight it.Il VAE massimizza, per ogni cifra \(x\), il limite inferiore dell'evidenza qui sotto (con peso \(\beta\) sul secondo termine), e le curve ne mostrano i due termini per cifra come loss, mediati sugli ultimi batch: l'errore di ricostruzione \(-\mathbb{E}\log p_\theta(x\mid z)\), l'entropia incrociata binaria dell'immagine decodificata, e la divergenza KL di \(q_\phi(z\mid x) = \mathcal{N}(\mu, \mathrm{diag}\,\sigma^2)\) dalla prior. L'autoencoder semplice pone \(z = \mu(x)\) e minimizza solo il primo termine. Passa su una curva o su un termine per metterlo in evidenza.

\(\mathcal{L}_\beta(x) = \class{frec}{\mathbb{E}_{q_\phi(z\mid x)}\big[\log p_\theta(x\mid z)\big]} - \beta\,\class{fkl}{D_{\mathrm{KL}}\big(q_\phi(z\mid x)\,\big\|\,\mathcal{N}(0, I)\big)},\)

\(\class{fkl}{D_{\mathrm{KL}} = \tfrac12 \textstyle\sum_{q=1}^{2} \big(\mu_q^2 + \sigma_q^2 - 1 - \log \sigma_q^2\big)}, \quad z = \mu + \sigma \odot \varepsilon\)