0

As I want to implement a structure which is similar to the update gate of GRU:

ht = (1-zt)ht-1 + ztht

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.

today
  • 32,602
  • 8
  • 95
  • 115
  • If the answer resolved your issue, kindly *accept* it by clicking on the checkmark (✔) next to the answer to mark it as "answered" - see [What should I do when someone answers my question?](https://stackoverflow.com/help/someone-answers) – today Dec 15 '18 at 06:54

1 Answers1

1

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.

today
  • 32,602
  • 8
  • 95
  • 115