Skip to content
DeepForgeby svx
All problems

Recurrent Policy Hidden State

Problem

Take one GRU hidden-state update.

z = sigmoid(v_h * h + v_x * x), candidate = tanh(w_h * h + w_x * x + bias), and the new hidden state is (1 - z) * h + z * candidate.

Hint

The update gate decides how much of the candidate state replaces the old one.

Test cases

case 1
in: [0,1,1,1,1,1,0]
expected: 0.5567699411459397
case 2
in: [0.5,-0.5,0.5,0,0,1,0.1]
expected: 0.43822511357700633
case 3
in: [2,0,-1,1,-1,1,-0.5]
expected: 1.6439868487073137
Starter codePython
import math
def gru_hidden_update(h, x, w_h, w_x, v_h, v_x, bias):
    # Your code here
    pass

3 test cases · run your code against them in the editor