Types of Neural Networks / Recurrent Neural Networks
Recurrent Neural Networks
IntermediateRNNs process sequences by maintaining a hidden state that carries information across time steps.
Recurrence
The same weights are reused at every time step. Training uses Backpropagation Through Time (BPTT).
hₜ is the hidden state and oₜ is the output before any task-specific activation (for example, softmax for class probabilities). Bias vectors are included in both transformations. Initialize h₀ with zeros or a learned vector.
Sequence configurations
- One-to-many — image captioning
- Many-to-one — sentiment analysis
- Many-to-many — translation, tagging
- Bidirectional RNNs read the sequence in both directions
Limitations
- Vanishing gradients make long-range dependencies hard to learn.
- Sequential computation limits parallelism.
Interview questions & answers
Q1. How does an RNN retain information from earlier time steps?
Answer: At each step, the RNN computes a new hidden state from the current input and the previous hidden state using shared parameters. The state summarizes preceding context, but a basic RNN may struggle to preserve information over long sequences.
Q2. What is backpropagation through time?
Answer: BPTT unfolds the recurrent computation across time and applies backpropagation through that graph, accumulating gradients for the shared parameters. Truncated BPTT limits the number of steps traversed, reducing memory and compute but restricting gradient-based credit assignment.
Q3. When is a bidirectional RNN unsuitable?
Answer: A bidirectional RNN uses both earlier and later sequence elements to compute representations. It is unsuitable when future inputs are unavailable, such as strict real-time forecasting or causal next-token prediction. It can be useful when the entire input sequence is available.