Long Short-Term Memory (LSTM) Network

Sequence Models & Generative Models DS practice problem on Onlearn.

Difficulty: medium.

Topics: Long Short-Term Memory (LSTM) Network, Gating Mechanisms, Backpropagation Through Time, Vanishing Gradient Problem, Cell State Memory, Hidden State Initialization, Deep Learning Foundations, Sequence Modeling, Optimization Theory, Information Theory, Computational Linear Algebra, Recurrent Neural Architectures, Gradient-Based Learning, Time-Series Analysis, Regularization Techniques, Activation Function Dynamics.

Task: Implement Long Short Term Memory (LSTM) Network Your task is to implement an LSTM network that processes a sequence of inputs and produces the final hidden state and cell state after processing all inputs. Write a class LSTM with the following methods: init (self, input size, hidden size): Initializes the LSTM with random weights and zero biases. forward(self, x, initial hidden state, initial cell state): Processes a sequence of inputs and returns the hidden states at each time step, as well as the final hidden state and cell state. The LSTM should compute the forget gate, input gate, candidate cell state, and output gate at each time step to update the hidden state and cell state.