Recurrent neural network
Рекуррентная нейросеть
This type of neural network processes a sequence one step at a time. It carries an internal state from one step to the next, so its response to the current input can depend on what came before.
Also known as: RNN, LSTM
What makes a network recurrent?
A recurrent neural network (RNN) feeds information from one step back into the computation at the next step. Take a speech model listening to a short audio frame: the frame alone may not be enough to identify a sound, but earlier frames can provide context. The model carries that context in a hidden state, a vector of numbers it updates as new inputs arrive. The state is a learned summary, not a copy of everything the model has seen.
From input to prediction
Suppose x_t is the input at step t and h_prev is the state from the previous step. A basic RNN cell can update its state as h_t = tanh(W_x x_t + W_h h_prev + b). The weights and bias are shared across time steps; it's the input and state that change. For a new, independent sequence, the initial state is often set to zero. A prediction layer can read each state to label every element in a sequence, or it can read the final state to classify the sequence as a whole.
Why LSTM exists
To train an RNN, you can draw its repeated cell calls as a chain and trace the effect of the loss backward through that chain. This is backpropagation through time, or BPTT. In a basic RNN, gradients can become very small or very large as they pass through many steps. Small gradients make it hard to learn which earlier inputs matter to a later prediction; large ones can make training unstable.
LSTM (Long Short-Term Memory) is a type of RNN, not a synonym for RNN. It keeps a separate cell state alongside the hidden state. Learned gates control what to retain, what to write, and how much of the cell state to expose through the hidden state. This helps an LSTM learn longer-range dependencies, but it doesn't give it unlimited memory. A GRU also uses gates but has no separate cell state.
When recurrence is useful
Imagine forecasting the next reading from a sensor. A one-way RNN can update its state whenever a reading arrives and make a fresh prediction without reprocessing the entire stream. This same pattern is useful for streaming audio and other inputs that arrive incrementally. For many language tasks, Transformers have largely replaced RNNs: during training, a Transformer can process sequence positions in parallel, while a standard RNN must finish one step before starting the next.
Interview questions to expect
Be ready to explain what gets carried forward and what gets shared. The hidden state is computed from the data and carried between steps; the learned weights are reused at every step. A practical follow-up is whether to reset the state between batches. The answer depends on what the batches contain: carry state across consecutive chunks of the same stream when continuity matters, but don't let it spill over into an unrelated sequence.