LLM Learning Hub

workspace/llm-course/home

LSTM

An LSTM (Long Short-Term Memory) is an RNN variant with gating mechanisms (input, forget, output gates) that control information flow, allowing it to capture longer dependencies than vanilla RNNs.

What is LSTM?

An LSTM (Long Short-Term Memory) is an RNN variant with gating mechanisms (input, forget, output gates) that control information flow, allowing it to capture longer dependencies than vanilla RNNs.

An LSTM (Long Short-Term Memory) is an RNN variant with gating mechanisms (input, forget, output gates) that control information flow, allowing it to capture longer dependencies than vanilla RNNs.

Where is it used?

LSTMs powered early speech recognition (DeepSpeech), machine translation, and text generation; they remain useful for small-scale sequential tasks where transformers are overkill.

How to build it

Use `nn.LSTM(input_size, hidden_size, batch_first=True)`, run a sequence through it, and inspect the tuple of (output, (h_n, c_n)) to see the cell state that carries long-term memory.

Code

A practical example:

example.pypython