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

时间:2020-10-25 06:47:41

标签: tensorflow keras deep-learning tensorflow2.0 attention-model

我正在尝试使用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)]. 

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

0 个答案:

没有答案