LSTM playgroundLaboratorio LSTM

A recurrent network reads a sequence one symbol at a time and has to carry in its state whatever the answer will need. A network of LSTM cells, one of GRU cells and a plain \(\tanh\) network of the same size are trained side by side, with Adam, on tasks in which an early symbol decides a late answer. In the LSTM the cell state \(c_t\), kept by the forget gate and written by the input gate, carries the first bit across many steps, and the GRU of Cho et al. carries it too, with a single state and two gates: while its update gate \(z_t\) is nearly closed \(h_t\) is almost a copy of \(h_{t-1}\), and the reset gate \(r_t\) decides how much of \(h_{t-1}\) enters the candidate \(\tilde h_t\). In the plain network the gradient with respect to the early states shrinks geometrically with the delay, and therefore at 20 steps the first bit is learned only from some initial weights, and at 30 almost never.

Una rete ricorrente legge una sequenza un simbolo alla volta e deve portare nel suo stato tutto ciò che servirà alla risposta. Una rete di celle LSTM, una di celle GRU e una semplice rete \(\tanh\) della stessa dimensione sono addestrate fianco a fianco, con Adam, su compiti in cui un simbolo iniziale decide una risposta tardiva. Nella LSTM lo stato della cella \(c_t\), conservato dal forget gate e scritto dall'input gate, porta il primo bit attraverso molti passi, e la GRU di Cho et al. lo porta anch'essa, con un solo stato e due gate: finché il suo update gate \(z_t\) è quasi chiuso \(h_t\) è quasi una copia di \(h_{t-1}\), e il reset gate \(r_t\) decide quanto di \(h_{t-1}\) entra nel candidato \(\tilde h_t\). Nella rete semplice il gradiente rispetto agli stati iniziali si riduce geometricamente con il ritardo, e quindi a 20 passi il primo bit viene appreso solo da alcuni pesi iniziali, e a 30 quasi mai.

The cell unrolled over the steps around \(t\), drawn from the values of the sequence below: the lines along the top are the units of \(c_t\), those along the bottom the units of \(h_t\) (violet positive, gold negative, thicker when larger); each gate is a column of bars, one per unit, filled as far as the gate is open. The GRU has no cell state, and its lines along the top are the units of \(h_t\) itself.La cella srotolata sui passi intorno a \(t\), disegnata con i valori della sequenza qui sotto: le linee in alto sono le unità di \(c_t\), quelle in basso le unità di \(h_t\) (viola positivo, oro negativo, più spesse quando più grandi); ogni gate è una colonna di barre, una per unità, riempita quanto il gate è aperto. La GRU non ha uno stato della cella, e le sue linee in alto sono le unità di \(h_t\) stesso.
steppasso \(t\)
The whole sequence, step by step (columns, the input on top) and unit by unit (rows): \(c_t\) (divided by 2 and clipped), \(h_t\), the gates from 0 (ground) to 1 (violet) and the candidate \(\tilde c_t\), or, for the GRU, \(h_t\), the gates \(z_t\) and \(r_t\) and the candidate \(\tilde h_t\); the frame marks step \(t\). Click a column to move there.L'intera sequenza, passo per passo (colonne, con l'ingresso in alto) e unità per unità (righe): \(c_t\) (diviso per 2 e troncato), \(h_t\), i gate da 0 (sfondo) a 1 (viola) e il candidato \(\tilde c_t\), o, per la GRU, \(h_t\), i gate \(z_t\) e \(r_t\) e il candidato \(\tilde h_t\); il riquadro segna il passo \(t\). Clicca una colonna per spostarti lì.
The loss of the three networks, trained on the same sequences (10 minibatches of 16 fresh sequences per epoch), and their accuracy.La loss delle tre reti, addestrate sulle stesse sequenze (10 minibatch di 16 sequenze nuove per epoca), e la loro accuratezza.
The norm of the gradient of the loss at the last step \(T\) with respect to \(h_t\), averaged over 32 test sequences and divided by its value at \(t = T\), in log scale: for the plain RNN it falls by a roughly constant factor at every step back, while for the LSTM, before training, it stays nearly flat, carried by \(c_t\) through the forget gates. Once the LSTM has stored the bit it falls too in the middle of the sequence, which the answer no longer depends on. For the GRU, whose update gates start nearly closed, it falls only slowly, and once the bit is stored it usually stays nearly flat, since a gate \(z_t\) near 0 passes on the state, and with it the gradient, almost unchanged.La norma del gradiente della loss all'ultimo passo \(T\) rispetto a \(h_t\), mediata su 32 sequenze di test e divisa per il suo valore in \(t = T\), in scala logaritmica: per la RNN semplice cala di un fattore circa costante a ogni passo all'indietro, mentre per la LSTM, prima dell'addestramento, resta quasi piatta, portata da \(c_t\) attraverso i forget gate. Quando la LSTM ha memorizzato il bit, cala anch'essa nel mezzo della sequenza, da cui la risposta non dipende più. Per la GRU, i cui update gate partono quasi chiusi, cala solo lentamente, e una volta memorizzato il bit di solito resta quasi piatta, perché un gate \(z_t\) vicino a 0 passa oltre lo stato, e con esso il gradiente, quasi immutato.