How a Neural Network Remembers What Matters and Forgets the Rest: LSTM
Long short-term memory explained step by step, from the forget gate to the prediction of the next word.
An LSTM processes a sentence token by token and passes hidden state and cell state from one position to the next. This page works through a recurrent language model cell that was actually trained. You see the gates, the cell state, and the next-token prediction with the learned weights.
Choose the starting context and the token selection at the top. Press "Play" and the computation runs by itself, or use the step list to jump to any point. The model was trained on German sentences, so corpus and vocabulary stay German. "myBytes ist Ihr Deep-Learning-Spezialist" means "myBytes is your deep learning specialist."
All computations run in your browser. Teaching example, not a production forecast.
What the View Shows and Where It Ends
The view shows an LSTM cell with eight embedding dimensions and twelve hidden units. The same cell with the same weights is used for every position. Four projections control which information is stored, forgotten, and passed to the outside. At the end, a linear layer projects the hidden state onto the vocabulary, and softmax turns the logits into probabilities.
The model was trained with PyTorch as a next-token predictor in 400 steps with AdamW. Cross-entropy is computed at all non-padded target positions, and the gradient runs through the unrolled sequence to the shared cell weights. The page shows the measured curve and the learned weights. No retraining takes place in the browser.
The corpus consists of 14 short German example sentences about myBytes and AI and is deliberately tiny. They are promotional lines used here as training material, not verified statements. After the starting context "myBytes macht," the corpus contains two sentences, each once. The network therefore sees two continuations almost level (50.0% and 49.9%), and which one it picks depended on the random initial values in this training run. The measured loss is training loss and not test loss, so it is not a quality measurement. The additive cell state makes learning longer-term dependencies easier but does not guarantee it. This page is a teaching example and not a language model for production use.
More Interactive Models
If you have a question about this, just give us a call: +49 40 60940415.