How is GRU outputting the following Values? I am getting a different answer<Keras>

20 Views Asked by At

When I run the following code I get this

from tensorflow import keras 
import numpy as np
x = np.ones((1,2,1))
model = keras.models.Sequential()
model.add(keras.layers.GRU(
    units = 1, activation='tanh', recurrent_activation='sigmoid',
    use_bias=True, kernel_initializer='ones',
    recurrent_initializer='ones',bias_initializer='zeros', return_sequences = True))
model.predict(x)

I get the output => array([[[0.20482421], [0.34675306]]], dtype=float32)

When I do this by hand I am getting 0.55

Assuming no biases and all weights are set to 1

hidden_(t-1) = 0

update_gate = sigmoid(1 x 1 + 1x0) = 0.73

relevance_gate = sigmoid(1x1 + 1x0) = 0.73

candidate_h(t) = tanh( 1 x (0 x 0.73) + 1 x 1) = tanh(1) = 0.76

h(t) = 0.73*0.76 + (1 - 0.73)x0 = 0.55

so shouldn't the first value of the output be 0.55?