Using this implementation I have included attention to my RNN (which classify the input sequences into two classes) as follows.
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)
I have trained the model and saved the weights into weights.best.hdf5
file.
I am dealing with binary classification problem and the input to my model is the one hot vectors (character based).
How can I visualize the attention weights for certain specific test case in the current implementation?