Implement one forward step of a gated recurrent unit. The update gate is
zt=σ(xtWz+ht−1Uz+bz)The reset gate is
rt=σ(xtWr+ht−1Ur+br)The candidate hidden state is
ht=tanh(xtWh+(rt⊙ht−1)Uh+bh)The new hidden state is
ht=(1−zt)⊙ht−1+zt⊙htHere, xt has feature width D, ht−1 has hidden width H, σ is the sigmoid function, and ⊙ denotes elementwise multiplication. The params dictionary contains Wz, Wr, and Wh with shape (D,H); Uz, Ur, and Uh with shape (H,H); and bz, br, and bh with shape (H,). Support one sample or a batch and return the new hidden state as a NumPy array with the same shape as h_prev.
Input: x = [[0, 0, 0], [0, 0, 0]], h_prev = [[1.0, -1.0], [2.0, 0.0]], every parameter value = 0
Output: [[0.5, -0.5], [1.0, 0.0]]
Explanation: Both gates equal 0.5 and the candidate equals 0, so the new state retains half of h_prev.
Input: x = [0.5, -1.0, 0.0, 0.25, 0.75], h_prev = [0.0, 0.1, -0.1, 0.2], params use the required shapes shown above
Output: [-0.1115, 0.0543, -0.2421, 0.0817]
np.asarray(value, dtype=float) converts each input and parameter to an array.
Reshape one-dimensional x and h_prev to one-row arrays before matrix multiplication.
np.where(a >= 0, 1 / (1 + np.exp(-a)), np.exp(a) / (1 + np.exp(a))) is a stable sigmoid.
Sign in to take notes on this problem
Accepts: array
Accepts: array
Accepts: any
Implement one forward step of a gated recurrent unit. The update gate is
zt=σ(xtWz+ht−1Uz+bz)The reset gate is
rt=σ(xtWr+ht−1Ur+br)The candidate hidden state is
ht=tanh(xtWh+(rt⊙ht−1)Uh+bh)The new hidden state is
ht=(1−zt)⊙ht−1+zt⊙htHere, xt has feature width D, ht−1 has hidden width H, σ is the sigmoid function, and ⊙ denotes elementwise multiplication. The params dictionary contains Wz, Wr, and Wh with shape (D,H); Uz, Ur, and Uh with shape (H,H); and bz, br, and bh with shape (H,). Support one sample or a batch and return the new hidden state as a NumPy array with the same shape as h_prev.
Input: x = [[0, 0, 0], [0, 0, 0]], h_prev = [[1.0, -1.0], [2.0, 0.0]], every parameter value = 0
Output: [[0.5, -0.5], [1.0, 0.0]]
Explanation: Both gates equal 0.5 and the candidate equals 0, so the new state retains half of h_prev.
Input: x = [0.5, -1.0, 0.0, 0.25, 0.75], h_prev = [0.0, 0.1, -0.1, 0.2], params use the required shapes shown above
Output: [-0.1115, 0.0543, -0.2421, 0.0817]
np.asarray(value, dtype=float) converts each input and parameter to an array.
Reshape one-dimensional x and h_prev to one-row arrays before matrix multiplication.
np.where(a >= 0, 1 / (1 + np.exp(-a)), np.exp(a) / (1 + np.exp(a))) is a stable sigmoid.
Sign in to take notes on this problem
Accepts: array
Accepts: array
Accepts: any