微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

张量流中的自我关注和多输入模型

如何解决张量流中的自我关注和多输入模型

我正在尝试使用Tensorflow Functional API(https://www.tensorflow.org/guide/keras/functional)定义多输入神经网络,并在我的嵌入层(https://pypi.org/project/keras-self-attention/)之后添加自我关注层。这是我的代码

from keras_self_attention import SeqSelfAttention
from tensorflow import keras
Input1 = Input(shape=(120,),name="Input1")
Input2 = Input(shape=(10,name="Input2")
embedding_layer = Embedding(30,5,input_length=120,)(Input1) 
lstm_layer = tf.keras.layers.Bidirectional(tf.keras.layers.LSTM(units=512))(embedding_layer)                  
attention=SeqSelfAttention(attention_activation='sigmoid')(lstm_layer) 
merge = concatenate([attention,Input2]) 

但是,出现此错误

ValueError: A `Concatenate` layer requires inputs with matching shapes except for the concat axis. Got inputs shapes: [(None,None,1024),(None,10)]. 

我的输入中只有一个序列,我想对此加以注意,然后与另一个输入连接。我该怎么办?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。