RNN & LSTM
AI · Advanced
Definition
RNNs process sequences step by step with a hidden state; LSTMs add gates to remember long-term information.
Used for time series, speech and early NLP.
Diagram
Flowchart
Example: Simple running state
h = 0
for x in [1, 2, 3]:
h = 0.5 * h + x
print(h)Output: 4.25
Complexity
O(T) sequential steps
Key points
- LSTM gates: forget, input, output
- Transformers have largely replaced RNNs
Interview questions
Why LSTM over RNN?
Its gates reduce vanishing gradients and keep long-range memory.