How to add attention layer to a Bi-LSTM
This can be a possible custom solution with a custom layer that computes attention on the positional/temporal dimension from tensorflow.keras.layers import Layer from tensorflow.keras import backend as K class Attention(Layer): def __init__(self, return_sequences=True): self.return_sequences = return_sequences super(Attention,self).__init__() def build(self, input_shape): self.W=self.add_weight(name=”att_weight”, shape=(input_shape[-1],1), initializer=”normal”) self.b=self.add_weight(name=”att_bias”, shape=(input_shape[1],1), initializer=”zeros”) super(Attention,self).build(input_shape) def call(self, x): e = K.tanh(K.dot(x,self.W)+self.b) a = … Read more