Implement the two LSTM input branches. The input gate chooses how much new information to write, while the candidate branch proposes the new content.
it=σ(Wi[ht−1,xt]+bi). Ct=tanh(Wc[ht−1,xt]+bc).Return a dictionary containing input_gate and candidate_state as float64 NumPy arrays. Each array has shape (H,) for one sample or (N, H) for a batch.
Examples
Input: h_prev = [0,0], x_t = [1,0.5], W_i = [[0.2,0.3,0.1,0.4],[0.4,0.2,0.3,0.1]], b_i = [0,0], W_c = [[0.3,0.1,0.2,0.1],[0.1,0.4,0.1,0.3]], b_c = [0,0]
Output: {"input_gate":[0.574443,0.586618],"candidate_state":[0.244919,0.244919]}
Explanation: Both branches read the same joined features but use different weights and activations.
Input: h_prev = [0.3,-0.2], x_t = [0.5,1], W_i = [[0.2,0.3,0.1,0.4],[0.4,0.2,0.3,0.1]], b_i = [0.1,-0.1], W_c = [[0.3,0.1,0.2,0.1],[0.1,0.4,0.1,0.3]], b_c = [0.05,0.1]
Output: {"input_gate":[0.634136,0.557248],"candidate_state":[0.309507,0.379949]}
Input: h_prev = [[0,0],[0.3,-0.2]], x_t = [[1,0.5],[0.5,1]], W_i = [[0.2,0.3,0.1,0.4],[0.4,0.2,0.3,0.1]], b_i = [0,0], W_c = [[0.3,0.1,0.2,0.1],[0.1,0.4,0.1,0.3]], b_c = [0,0]
Output: {"input_gate":[[0.574443,0.586618],[0.610639,0.581759]],"candidate_state":[[0.244919,0.244919],[0.263625,0.291313]]}
Hint 1
Compute joined once and reuse it for both affine transforms.
Hint 2
Use sigmoid for input_gate and np.tanh for candidate_state.
Requirements
- Use the same [h_prev, x_t] concatenation for both branches.
- Apply sigmoid to the input-gate branch and tanh to the candidate branch.
- Return exactly the keys input_gate and candidate_state.
Constraints
- Unbatched h_prev and x_t have shapes (H,) and (D,); batched inputs have shapes (N, H) and (N, D).
- W_i and W_c have shape (H, H + D).
- b_i and b_c have shape (H,).
- Both returned arrays use float64.
All steps in LSTM
Accepts: array
Accepts: array
Accepts: array
Accepts: array
Accepts: array
Accepts: array
Input Gate
Implement the two LSTM input branches. The input gate chooses how much new information to write, while the candidate branch proposes the new content.
it=σ(Wi[ht−1,xt]+bi). Ct=tanh(Wc[ht−1,xt]+bc).Return a dictionary containing input_gate and candidate_state as float64 NumPy arrays. Each array has shape (H,) for one sample or (N, H) for a batch.
Examples
Input: h_prev = [0,0], x_t = [1,0.5], W_i = [[0.2,0.3,0.1,0.4],[0.4,0.2,0.3,0.1]], b_i = [0,0], W_c = [[0.3,0.1,0.2,0.1],[0.1,0.4,0.1,0.3]], b_c = [0,0]
Output: {"input_gate":[0.574443,0.586618],"candidate_state":[0.244919,0.244919]}
Explanation: Both branches read the same joined features but use different weights and activations.
Input: h_prev = [0.3,-0.2], x_t = [0.5,1], W_i = [[0.2,0.3,0.1,0.4],[0.4,0.2,0.3,0.1]], b_i = [0.1,-0.1], W_c = [[0.3,0.1,0.2,0.1],[0.1,0.4,0.1,0.3]], b_c = [0.05,0.1]
Output: {"input_gate":[0.634136,0.557248],"candidate_state":[0.309507,0.379949]}
Input: h_prev = [[0,0],[0.3,-0.2]], x_t = [[1,0.5],[0.5,1]], W_i = [[0.2,0.3,0.1,0.4],[0.4,0.2,0.3,0.1]], b_i = [0,0], W_c = [[0.3,0.1,0.2,0.1],[0.1,0.4,0.1,0.3]], b_c = [0,0]
Output: {"input_gate":[[0.574443,0.586618],[0.610639,0.581759]],"candidate_state":[[0.244919,0.244919],[0.263625,0.291313]]}
Hint 1
Compute joined once and reuse it for both affine transforms.
Hint 2
Use sigmoid for input_gate and np.tanh for candidate_state.
Requirements
- Use the same [h_prev, x_t] concatenation for both branches.
- Apply sigmoid to the input-gate branch and tanh to the candidate branch.
- Return exactly the keys input_gate and candidate_state.
Constraints
- Unbatched h_prev and x_t have shapes (H,) and (D,); batched inputs have shapes (N, H) and (N, D).
- W_i and W_c have shape (H, H + D).
- b_i and b_c have shape (H,).
- Both returned arrays use float64.
All steps in LSTM
Accepts: array
Accepts: array
Accepts: array
Accepts: array
Accepts: array
Accepts: array