ConvD1的注意事项?

问题描述 投票:1回答:1

我的主管要求我为CNN实现一个Attention层(应用于文本),但是我很确定它不适用于ConvD1层。

使用Keras,我有一个非常简单的模型,其嵌入层后面是卷积层。

由于ConvD1的输入为(#documents, words, embedding_size),后接一个MaxPooling-Layer,因此我考虑了丢弃最大池并在此处插入Attention,但在这种情况下,我真的不知道我的查询和值输入是什么。

我知道tf.backend有一个Attention-Layer,但是可以在这里应用它吗?还是我需要某种自我关注?

我需要的是,查看哪个(单词)(最)负责相应的分类。

sequence_input = Input(shape=(MAX_SEQUENCE_LENGTH,), dtype='int32')
embedded_sequences = embedding_layer(sequence_input)

conv1 = Conv1D(filters=2, kernel_size=2, padding='same')(embedded_sequences)
conv1 = MaxPooling1D(pool_size=32)(conv1)
conv1 = Dropout(0.2)(conv1)

x = Dense(50, activation="relu",
          kernel_regularizer=regularizers.l2(0.01),
          bias_regularizer=regularizers.l2(0.01))(conv1)
x = Dropout(0.3)(x)

preds = Dense(1, activation='sigmoid',name='output')(x)  
model = Model(sequence_input, preds)

model.compile(loss='binary_crossentropy', 
              optimizer='adam', 
              metrics=[TruePositives(name='true_positives'),
                       TrueNegatives(name='true_negatives'),
                       FalseNegatives(name='false_negatives'),
                       FalsePositives(name='false_positives'),
                       ])
python tensorflow keras attention-model
1个回答
0
投票

[尝试使用此link,其中包含用于添加注意层的代码段,也就是CNN的Bahdanau风格的关注]

© www.soinside.com 2019 - 2024. All rights reserved.