tensorflow中的自我注意和多输入模型

tensorflow中的自我注意和多输入模型,tensorflow,keras,deep-learning,tensorflow2.0,attention-model,Tensorflow,Keras,Deep Learning,Tensorflow2.0,Attention Model,我试图使用Tensorflow函数API()定义一个多输入神经网络,并在嵌入层()之后添加自我注意层。这是我的代码: from keras_self_attention import SeqSelfAttention from tensorflow import keras Input1 = Input(shape=(120, ),name="Input1") Input2 = Input(shape=(10, ),name="Input2") embed

我试图使用Tensorflow函数API()定义一个多输入神经网络,并在嵌入层()之后添加自我注意层。这是我的代码:

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)]. 

我的输入中只有一个序列,我想对其应用自我注意,然后与另一个输入连接。我该怎么做呢?

keras\u self\u attention
是用
tf2.x
编写的吗?如果不是的话,我想我们不能把两个版本都混在一起。基于。有什么线索可以解释我为什么会出现这个错误吗?是您迄今为止尝试过的给定代码吗?它似乎不是多输入!为什么要通过嵌入层进行展平,而不是通过序列层,即LSTM?我的错。你是对的。我不需要平坦层。为什么要在嵌入层和自我关注层之间添加序列层,如密集层或LSTM层?为什么不在嵌入层之后添加自我关注层呢?我只是假设,我们确实不需要设置序列层。是的,你可以在嵌入层之后添加自我关注层。我根据您给定的代码片段成功运行了代码。但我很确定这不是你想要的。