代码拉取完成,页面将自动刷新
from keras.layers import *
from keras.models import *
from keras.utils import plot_model
def attention(input=None, depth=None):
attention = Dense(1, activation='tanh')(input)
attention = Flatten()(attention)
attention = Activation('softmax')(attention)
attention = RepeatVector(depth)(attention)
attention = Permute([2, 1], name='attention_vec')(attention)
attention_mul = Multiply(name='attention_mul')([input, attention])
return attention_mul
if __name__ == '__main__':
data_input = Input(shape=[400])
word_vec = Embedding(input_dim=40000 + 1,
input_length=400,
output_dim=512,
mask_zero=False,
name='Embedding')(data_input)
x = word_vec
x = Conv1D(filters=512, kernel_size=[3], strides=1, padding='same', activation='relu')(x)
x = attention(input=x, depth=512)
x = GlobalMaxPool1D()(x)
x = BatchNormalization()(x)
x = Dense(500, activation="relu")(x)
x = Dense(202, activation="sigmoid")(x)
model = Model(inputs=data_input, outputs=x)
plot_model(model, './attention.png', show_shapes=True)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。