Implement a deterministic vanilla RNN network using the supplied parameters. Recurrently compute hidden states and project each one to an output.
ht=tanh(Wxhxt+Whhht−1+bh). yt=Whyht+by.Return a dictionary containing outputs with shape (N, T, O) and final_hidden_state with shape (N, H), both float64 NumPy arrays.
Examples
Input: X = [[[1,0.5],[0.5,1]]], h_0 = [[0,0]], W_xh = [[0.1,0.2],[0.3,0.4]], W_hh = [[0.5,0.1],[0.2,0.3]], b_h = [0,0], W_hy = [[0.3,0.5]], b_y = [0]
Output: {"outputs":[[[0.290271],[0.423627]]],"final_hidden_state":[[0.375576,0.621908]]}
Explanation: Each recurrent hidden state is immediately mapped into the output space while the final hidden state is retained separately.
Input: X = [[[1],[0],[-1]]], h_0 = [[0.2,-0.1]], W_xh = [[0.3],[-0.2]], W_hh = [[0.4,0.1],[0.2,0.5]], b_h = [0.1,-0.1], W_hy = [[0.3,0.5]], b_y = [0.1]
Output: {"outputs":[[[0.081241],[0.09155],[0.097891]]],"final_hidden_state":[[-0.11937,0.067404]]}
Input: X = [[[1],[2]],[[0],[-1]]], h_0 = [[0,0],[0.5,-0.5]], W_xh = [[0.2],[0.4]], W_hh = [[0.3,0.1],[0.2,0.4]], b_h = [0,0], W_hy = [[0.3,0.5],[0.2,0.4]], b_y = [0,0]
Output: {"outputs":[[[0.249187,0.191455],[0.516966,0.395176]],[[-0.019934,-0.019934],[-0.251881,-0.194379]]],"final_hidden_state":[[0.459918,0.757982],[-0.178145,-0.396874]]}
Hint 1
Update hidden before computing the output for each step.
Hint 2
The step output is hidden @ W_hy.T + b_y.
Hint 3
Stack outputs along the sequence axis.
Requirements
- Begin from the supplied h_0 and share parameters across all time steps.
- Project every new hidden state with W_hy and b_y.
- Return exactly the keys outputs and final_hidden_state.
Constraints
- X has shape (N, T, D), and h_0 has shape (N, H).
- W_xh has shape (H, D), W_hh has shape (H, H), and W_hy has shape (O, H).
- b_h and b_y have shapes (H,) and (O,).
- Returned arrays use float64.
All steps in RNN
Accepts: array
Accepts: array
Accepts: array
Accepts: array
Accepts: array
Accepts: array
Accepts: array
Complete RNN
Implement a deterministic vanilla RNN network using the supplied parameters. Recurrently compute hidden states and project each one to an output.
ht=tanh(Wxhxt+Whhht−1+bh). yt=Whyht+by.Return a dictionary containing outputs with shape (N, T, O) and final_hidden_state with shape (N, H), both float64 NumPy arrays.
Examples
Input: X = [[[1,0.5],[0.5,1]]], h_0 = [[0,0]], W_xh = [[0.1,0.2],[0.3,0.4]], W_hh = [[0.5,0.1],[0.2,0.3]], b_h = [0,0], W_hy = [[0.3,0.5]], b_y = [0]
Output: {"outputs":[[[0.290271],[0.423627]]],"final_hidden_state":[[0.375576,0.621908]]}
Explanation: Each recurrent hidden state is immediately mapped into the output space while the final hidden state is retained separately.
Input: X = [[[1],[0],[-1]]], h_0 = [[0.2,-0.1]], W_xh = [[0.3],[-0.2]], W_hh = [[0.4,0.1],[0.2,0.5]], b_h = [0.1,-0.1], W_hy = [[0.3,0.5]], b_y = [0.1]
Output: {"outputs":[[[0.081241],[0.09155],[0.097891]]],"final_hidden_state":[[-0.11937,0.067404]]}
Input: X = [[[1],[2]],[[0],[-1]]], h_0 = [[0,0],[0.5,-0.5]], W_xh = [[0.2],[0.4]], W_hh = [[0.3,0.1],[0.2,0.4]], b_h = [0,0], W_hy = [[0.3,0.5],[0.2,0.4]], b_y = [0,0]
Output: {"outputs":[[[0.249187,0.191455],[0.516966,0.395176]],[[-0.019934,-0.019934],[-0.251881,-0.194379]]],"final_hidden_state":[[0.459918,0.757982],[-0.178145,-0.396874]]}
Hint 1
Update hidden before computing the output for each step.
Hint 2
The step output is hidden @ W_hy.T + b_y.
Hint 3
Stack outputs along the sequence axis.
Requirements
- Begin from the supplied h_0 and share parameters across all time steps.
- Project every new hidden state with W_hy and b_y.
- Return exactly the keys outputs and final_hidden_state.
Constraints
- X has shape (N, T, D), and h_0 has shape (N, H).
- W_xh has shape (H, D), W_hh has shape (H, H), and W_hy has shape (O, H).
- b_h and b_y have shapes (H,) and (O,).
- Returned arrays use float64.
All steps in RNN
Accepts: array
Accepts: array
Accepts: array
Accepts: array
Accepts: array
Accepts: array
Accepts: array