Representations playgroundLaboratorio delle rappresentazioni

A perceptron with two hidden layers is trained in the page to classify digits, and 500 digits that it never sees in training are followed through its layers: each layer maps them to a point cloud in its own space, which is drawn here in two dimensions with PCA, with t-SNE or with a linear probe. In the input the classes overlap (two images of a 3 in different fonts may share fewer pixels than a 3 and an 8), and the training pulls them apart layer after layer, until in the last hidden layer they lie in regions that the linear map to the logits can separate.

Un percettrone con due strati nascosti è addestrato nella pagina a classificare cifre, e 500 cifre che non vede mai durante l'addestramento sono seguite attraverso i suoi strati: ogni strato le porta in una nuvola di punti nel proprio spazio, disegnata qui in due dimensioni con la PCA, con t-SNE o con una sonda lineare. Nell'ingresso le classi si sovrappongono (due immagini di un 3 in caratteri diversi possono avere in comune meno pixel di un 3 e di un 8), e l'addestramento le separa strato dopo strato, finché nell'ultimo strato nascosto stanno in regioni che la mappa lineare verso i logit riesce a separare.

The same 500 held-out digits in the four spaces of the network, from the 400 pixels of the input to the 10 logits, each map computed on that layer alone; beside its name, the leave-one-out accuracy of the vote of the 5 nearest neighbors in that space. If you hover a point, it and its 8 nearest neighbors in the space of that layer are ringed in every map, and therefore one sees which neighbors a layer brings together and where the other layers put them.Le stesse 500 cifre tenute da parte nei quattro spazi della rete, dai 400 pixel dell'ingresso ai 10 logit, ogni mappa calcolata sul solo strato a cui si riferisce; accanto al nome, l'accuratezza leave-one-out del voto dei 5 vicini più prossimi in quello spazio. Se passi su un punto, il punto e i suoi 8 vicini più prossimi nello spazio di quello strato vengono cerchiati in ogni mappa, e vedi così quali vicini uno strato avvicina e dove li collocano gli altri strati.
Draw a digit (or take a held-out one): the cross marks where it lands in every map. In PCA and in the probe the place is exact; t-SNE has no map for new points, so the cross is put at the mean of the positions of the 500, weighted by the Gaussian affinities \(p_{j|\mathrm{new}}\) of the new point in that layer.Disegna una cifra (o prendine una tenuta da parte): la croce segna dove cade in ogni mappa. Nella PCA e nella sonda la posizione è esatta; t-SNE non ha una mappa per punti nuovi, per cui la croce è posta nella media delle posizioni dei 500, pesata con le affinità gaussiane \(p_{j|\mathrm{new}}\) del nuovo punto in quello strato.

The hovered digit and its 8 nearest neighbors in the space of the layer it was hovered in, nearest first, and below how many of the 8 nearest share its class in each layer.La cifra indicata e i suoi 8 vicini più prossimi nello spazio dello strato in cui è stata indicata, dal più vicino, e sotto quanti degli 8 più vicini ne condividono la classe in ogni strato.

Separation per layer: the accuracy of the 5-nearest-neighbour vote on the 500 points (violet), against its value for the untrained network (gold tick); the dashed line is the accuracy of the network itself on the same digits.La separazione per strato: l'accuratezza del voto dei 5 vicini più prossimi sui 500 punti (viola), a confronto con il suo valore per la rete non addestrata (tacca oro); la linea tratteggiata è l'accuratezza della rete stessa sulle stesse cifre.
Properties of the three maps.Proprietà delle tre mappe.

t-SNE turns the distances of a layer into affinities \(p_{j|i} \propto \exp(-\|x_i - x_j\|^2 / 2\sigma_i^2)\), with \(\sigma_i\) set for every point so that it has about as many effective neighbors as the perplexity, and places points \(y_i\) in the plane to minimize \(\mathrm{KL}(P\,\|\,Q)\), where \(p_{ij} = (p_{j|i} + p_{i|j})/2n\) and \(q_{ij} \propto (1 + \|y_i - y_j\|^2)^{-1}\). The loss is large when near neighbors are put far apart and small for the converse, and therefore the map preserves, roughly, who is next to whom (i.e., the clusters and their members).

It does not preserve the size of a cluster (\(\sigma_i\) adapts to the local density), nor the distance between two clusters (the heavy tail of \(q\) pushes moderately distant groups far apart), nor their relative position, which changes with the seed and the perplexity; two clusters drawn far apart are therefore not more different than two drawn close. For this reason the accuracy above each map is measured in the layer itself, where the distances are those of the network. PCA, on the contrary, is a linear projection on the two directions of largest variance: its distances are faithful along them and shrunk along all others, so that classes that overlap in PCA may well be separated in a direction it does not show. The probe draws the plane \(z = A x\) that a softmax classifier on \(z\) finds most useful, fitted on 1000 other digits that the network does not see either (500 points in 400 dimensions are separated by almost any plane fitted on them); hence, it measures the linear separability of the classes in two dimensions, and it shows little of the geometry of the layer.

t-SNE trasforma le distanze di uno strato in affinità \(p_{j|i} \propto \exp(-\|x_i - x_j\|^2 / 2\sigma_i^2)\), con \(\sigma_i\) fissato per ogni punto in modo che abbia circa tanti vicini effettivi quanti ne indica la perplessità, e colloca i punti \(y_i\) nel piano in modo da minimizzare \(\mathrm{KL}(P\,\|\,Q)\), dove \(p_{ij} = (p_{j|i} + p_{i|j})/2n\) e \(q_{ij} \propto (1 + \|y_i - y_j\|^2)^{-1}\). La loss è grande quando vicini prossimi sono posti lontani e piccola nel caso opposto, e quindi la mappa conserva, grosso modo, chi sta accanto a chi (cioè i cluster e i loro membri).

Non conserva la dimensione di un cluster (\(\sigma_i\) si adatta alla densità locale), né la distanza fra due cluster (la coda pesante di \(q\) allontana molto gruppi moderatamente distanti), né la loro posizione relativa, che cambia con il seme e con la perplessità; due cluster disegnati lontani non sono quindi più diversi di due disegnati vicini. Per questo l'accuratezza sopra ogni mappa è misurata nello strato stesso, dove le distanze sono quelle della rete. La PCA, al contrario, è una proiezione lineare sulle due direzioni di varianza massima: le sue distanze sono fedeli lungo di esse e contratte lungo tutte le altre, così che classi che si sovrappongono nella PCA possono benissimo essere separate in una direzione che essa non mostra. La sonda disegna il piano \(z = A x\) che un classificatore softmax su \(z\) trova più utile, stimato su altre 1000 cifre che neanche la rete vede (500 punti in 400 dimensioni sono separati da quasi ogni piano stimato su di essi); misura quindi la separabilità lineare delle classi in due dimensioni, e mostra poco della geometria dello strato.