Join Our 5-Week ML/AI Engineer Interview Bootcamp 🚀 led by ML Tech Leads at FAANGs
Implement the forward pass of the gates in a single LSTM cell, which controls how information is forgotten, added, and exposed at each timestep in a sequence model. Given an input vector and the previous hidden/cell states, you’ll compute the new hidden and cell states for one step.
Implement the function:
Rules:
f_t, i_t, o_t and candidate state c_tilde using the formulas above.\odot.h_t and c_t as NumPy arrays.Output:
| Argument | Type |
|---|---|
| x_t | np.ndarray |
| c_prev | np.ndarray |
| h_prev | np.ndarray |
| params | dict |
| Return Name | Type |
|---|---|
| value | tuple |
Use NumPy only; no deep learning frameworks.
Ensure shapes: W(hid,in), U(hid,hid), b(hid).
Return NumPy arrays.
Ensure inputs are NumPy arrays for @ matrix multiplication.
Implement sigmoid(z)=1/(1+exp(-z)); use np.tanh for candidate/hidden.
Compute gates: f,i,o = sigmoid(W@x + U@h + b); then c=f*c_prev+i*c_tilde, h=o*tanh(c); return NumPy arrays.