keras中的注意功能
我在下面的链接中关注Keras的自我关注 有人能解释一下这个注意功能到底在做什么吗? 我是python新手,shape=(input_shape[-1],1是什么意思? 我们在哪个方向计算注意力?是在批量大小的方向吗keras中的注意功能,keras,deep-learning,Keras,Deep Learning,我在下面的链接中关注Keras的自我关注 有人能解释一下这个注意功能到底在做什么吗? 我是python新手,shape=(input_shape[-1],1是什么意思? 我们在哪个方向计算注意力?是在批量大小的方向吗 class attention(Layer): def __init__(self, return_sequences=True): self.return_sequences = return_sequences super(at
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 = K.softmax(e, axis=1)
output = x*a
if self.return_sequences:
return output
return K.sum(output, axis=1)
它与这里介绍的非常相似:在这个实现中感谢您def调用(self,x):et=K.squence(K.tanh(K.dot(x,self.W)+self.b),axis=-1)at=K.softmax(et)at=K.expand_dims(at,axis=-1)output=x*at返回K.sum(output,axis=1)但在您的实现中,def call中有tang和softmax,您能解释一下,它们有什么区别吗?与您提供的链接中的call功能有什么区别?