This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from keras.layers import Lambda, Reshape, RepeatVector, Concatenate, Conv1D, Activation | |
from keras.layers import Layer | |
from keras import activations | |
class Attention(Layer): | |
def __init__(self, kernel_activation='hard_sigmoid', before=False, **kwargs): | |
super(Attention, self).__init__(**kwargs) | |
self.kernel_activation = activations.get(kernel_activation) | |
K.set_floatx('float32') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AttentiveConv(Layer): | |
def __init__(self, kernel_activation='tanh', filters=3, **kwargs): | |
super(AttentiveConv, self).__init__(**kwargs) | |
self.kernel_activation = activations.get(kernel_activation) | |
if filters%2 == 0: | |
self.filters = filters - 1 | |
else: | |
self.filters = filters | |
self.filters = filters |