Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. class CustomConstSoftmaxLayer(Layer):
  2.  
  3. def __init__(self, **kwargs):
  4. super(CustomConstSoftmaxLayer, self).__init__(**kwargs)
  5.  
  6. def build(self, input_shape):
  7. self.const = self.add_weight(name='const',
  8. shape=tuple([1] * len(input_shape[0])),
  9. initializer='zero',
  10. trainable=True)
  11. super(CustomConstSoftmaxLayer, self).build(input_shape)
  12.  
  13. def call(self, args):
  14. [x, logits] = args
  15. tmp = K.tile(self.const, K.shape(x))
  16. return K.sum(K.softmax(logits) * K.concatenate([x, tmp], axis=-1), axis=-1, keepdims=True)
  17.  
  18. def compute_output_shape(self, input_shape):
  19. return input_shape[0]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement