Skip to content

Instantly share code, notes, and snippets.

View gentaiscool's full-sized avatar
:octocat:
Writing interesting code...

Genta Indra Winata gentaiscool

:octocat:
Writing interesting code...
View GitHub Profile
@gentaiscool
gentaiscool / AttentionWithContext.py
Created October 24, 2017 06:47 — forked from cbaziotis/AttentionWithContext.py
Keras Layer that implements an Attention mechanism, with a context/query vector, for temporal data. Supports Masking. Follows the work of Yang et al. [https://www.cs.cmu.edu/~diyiy/docs/naacl16.pdf] "Hierarchical Attention Networks for Document Classification"
def dot_product(x, kernel):
"""
Wrapper for dot product operation, in order to be compatible with both
Theano and Tensorflow
Args:
x (): input
kernel (): weights
Returns:
"""
if K.backend() == 'tensorflow':