Combine the previous GRU hidden state and the candidate state with the update gate:
ht=zt⊙ht−1+(1−zt)⊙ht.Here, zt is the update gate, ht−1 is the previous state, ht is the candidate state, and ⊙ means elementwise multiplication. Accept one sample or a batch and return the new state as a matching float64 NumPy array.
Examples
Input: z_t = [0.5,0.5], h_prev = [1,-1], h_tilde = [0.2,0.4]
Output: [0.6,-0.3]
Explanation: A gate value of 0.5 averages the corresponding old and candidate values.
Input: z_t = [1,1], h_prev = [2,-3], h_tilde = [8,9]
Output: [2,-3]
Input: z_t = [[0,0.25],[0.75,1]], h_prev = [[1,2],[3,4]], h_tilde = [[5,6],[7,8]]
Output: [[5,5],[4,4]]
Hint 1
Compute z_t * h_prev + (1.0 - z_t) * h_tilde elementwise.
Requirements
- Blend the previous and candidate states elementwise using z_t.
- Return a float64 NumPy array with the same shape as the inputs.
Constraints
- All three arrays have the same shape, either (H,) or (N,H).
- Gate values lie in [0,1].
- Every input is float64 and finite.
All steps in GRU
- Reset Gate
- Update Gate
- Candidate Hidden
- Hidden State Update
- GRU Cell
- Complete GRU
Related practice
Accepts: array
Accepts: array
Accepts: array
Hidden State Update
Combine the previous GRU hidden state and the candidate state with the update gate:
ht=zt⊙ht−1+(1−zt)⊙ht.Here, zt is the update gate, ht−1 is the previous state, ht is the candidate state, and ⊙ means elementwise multiplication. Accept one sample or a batch and return the new state as a matching float64 NumPy array.
Examples
Input: z_t = [0.5,0.5], h_prev = [1,-1], h_tilde = [0.2,0.4]
Output: [0.6,-0.3]
Explanation: A gate value of 0.5 averages the corresponding old and candidate values.
Input: z_t = [1,1], h_prev = [2,-3], h_tilde = [8,9]
Output: [2,-3]
Input: z_t = [[0,0.25],[0.75,1]], h_prev = [[1,2],[3,4]], h_tilde = [[5,6],[7,8]]
Output: [[5,5],[4,4]]
Hint 1
Compute z_t * h_prev + (1.0 - z_t) * h_tilde elementwise.
Requirements
- Blend the previous and candidate states elementwise using z_t.
- Return a float64 NumPy array with the same shape as the inputs.
Constraints
- All three arrays have the same shape, either (H,) or (N,H).
- Gate values lie in [0,1].
- Every input is float64 and finite.
All steps in GRU
- Reset Gate
- Update Gate
- Candidate Hidden
- Hidden State Update
- GRU Cell
- Complete GRU
Related practice
Accepts: array
Accepts: array
Accepts: array