Implement one step of a tanh recurrent neural network:
at=xtWx+ht−1Wh+b ht=tanh(at)Here, xt∈RD is the current input, ht−1∈RH is the previous hidden state, Wx∈RD×H maps inputs, Wh∈RH×H maps the previous state, and b∈RH is the bias. Return ht as a one-dimensional NumPy array.
Input: x_t = [1.0, 0.0], h_prev = [0.0, 0.0], Wx = [[1.0, 0.0], [0.0, 1.0]], Wh = [[0.0, 0.0], [0.0, 0.0]], b = [0.0, 0.0]
Output: [0.761594, 0.0]
Explanation: Only the first input coordinate reaches the pre-activation, so tanh is applied to [1, 0].
Input: x_t = [0.0, 0.0], h_prev = [1.0, -1.0], Wx = [[0.0, 0.0], [0.0, 0.0]], Wh = [[1.0, 0.0], [0.0, 1.0]], b = [0.0, 0.0]
Output: [0.761594, -0.761594]
Compute the pre-activation with x_t @ Wx + h_prev @ Wh + b.
Pass the complete pre-activation array to np.tanh.
Sign in to take notes on this problem
Accepts: array
Accepts: array
Accepts: array
Accepts: array
Accepts: array
Implement one step of a tanh recurrent neural network:
at=xtWx+ht−1Wh+b ht=tanh(at)Here, xt∈RD is the current input, ht−1∈RH is the previous hidden state, Wx∈RD×H maps inputs, Wh∈RH×H maps the previous state, and b∈RH is the bias. Return ht as a one-dimensional NumPy array.
Input: x_t = [1.0, 0.0], h_prev = [0.0, 0.0], Wx = [[1.0, 0.0], [0.0, 1.0]], Wh = [[0.0, 0.0], [0.0, 0.0]], b = [0.0, 0.0]
Output: [0.761594, 0.0]
Explanation: Only the first input coordinate reaches the pre-activation, so tanh is applied to [1, 0].
Input: x_t = [0.0, 0.0], h_prev = [1.0, -1.0], Wx = [[0.0, 0.0], [0.0, 0.0]], Wh = [[1.0, 0.0], [0.0, 1.0]], b = [0.0, 0.0]
Output: [0.761594, -0.761594]
Compute the pre-activation with x_t @ Wx + h_prev @ Wh + b.
Pass the complete pre-activation array to np.tanh.
Sign in to take notes on this problem
Accepts: array
Accepts: array
Accepts: array
Accepts: array
Accepts: array