As I want to implement a structure which is similar to the update gate of GRU:
h t = (1-z t )h t-1 + z t h t
And I am trying to implement it with these code but it doesn't work. I am sure the problem are in the following code:
one = K.ones(shape=(1, len, 128))
zt=Subtract([one,zt])
temp_conv2=multiply([reset_conv,zt])
output=Add([temp_conv1,temp_conv2])
I have the following error:
AttributeError:'Tensor' object has no attribute '_keras_history'
I have already tried some other method such as using Lambda
layer but it doesn't work.
one
is not a Keras Tensor therefore you would get that error. You can wrap this in a Lambda
layer:
zt = Lambda(lambda x: Subtract([K.ones(shape=(1, len, 128)), x]))(zt)
Even you don't need to construct that Tensor of ones. Simply use 1-x
:
zt = Lambda(lambda x: 1-x)(zt)
It will be automatically broadcasted and the subtraction would be element-wise.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.