I\'m currently using this code that i get from one discussion on github Here\'s the code of the attention mechanism:
_input = Input(shape=[max_length], dtype
I think you can try the following code to add keras self-attention mechanism with LSTM network
from keras_self_attention import SeqSelfAttention
inputs = Input(shape=(length,))
embedding = Embedding(vocab_size, EMBEDDING_DIM, weights=[embedding_matrix], input_length=MAX_SEQUENCE_LENGTH, trainable=False)(inputs)
lstm = LSTM(num_lstm, input_shape=(X[train].shape[0], X[train].shape[1]), return_sequences=True)(embedding)
attn = SeqSelfAttention(attention_activation='sigmoid')(lstm)
Flat = Flatten()(attn)
dense = Dense(32, activation='relu')(Flat)
outputs = Dense(3, activation='sigmoid')(dense)
model = Model(inputs=[inputs], outputs=outputs)
model.compile(loss='binary_crossentropy', optimizer=Adam(0.001), metrics=['accuracy'])
model.fit(X_train, y_train, epochs=10, batch_size=32, validation_data=(X_val,y_val), shuffle=True)