【发布时间】:2019-05-20 21:31:38
【问题描述】:
Using this implementation 我已将注意力包括在我的 RNN(将输入序列分为两类)如下。
visible = Input(shape=(250,))
embed=Embedding(vocab_size,100)(visible)
activations= keras.layers.GRU(250, return_sequences=True)(embed)
attention = TimeDistributed(Dense(1, activation='tanh'))(activations)
attention = Flatten()(attention)
attention = Activation('softmax')(attention)
attention = RepeatVector(250)(attention)
attention = Permute([2, 1])(attention)
sent_representation = keras.layers.multiply([activations, attention])
sent_representation = Lambda(lambda xin: K.sum(xin, axis=1))(sent_representation)
predictions=Dense(1, activation='sigmoid')(sent_representation)
model = Model(inputs=visible, outputs=predictions)
我已经训练了模型并将权重保存到weights.best.hdf5 文件中。
我正在处理二进制分类问题,我的模型的输入是一个热向量(基于字符)。
如何可视化当前实现中某些特定测试用例的注意力权重?
【问题讨论】:
标签: keras deep-learning nlp rnn attention-model