RNN Forward Step
Hard
~20 min
code completion
RNN: Single Time Step
A Recurrent Neural Network (RNN) processes sequences by maintaining a hidden state that is updated at each time step:
where:
Your task:
Implement rnn_step(h_prev, x, Wh, Wx, b) that returns the next hidden state .
Example Tests
Zero inputs and prev state: output is tanh(b)
Input: {"b":[0,0],"x":[0,0],"Wh":[[1,0],[0,1]],"Wx":[[1,0],[0,1]],"h_prev":[0,0]}
Expected: [0,0]
Identity Wh, zero Wx and b: output = tanh(h_prev)
Input: {"b":[0,0],"x":[0,0],"Wh":[[1,0],[0,1]],"Wx":[[0,0],[0,0]],"h_prev":[1,0]}
Expected: [0.76159,0]
tanh squashes large values to ±1
Input: {"b":[0,0],"x":[1,0],"Wh":[[0,0],[0,0]],"Wx":[[100,0],[0,1]],"h_prev":[0,0]}
Expected: [1,0]