Skip to content

Instantly share code, notes, and snippets.

View zachmayer's full-sized avatar

Zach Deane-Mayer zachmayer

View GitHub Profile
@zachmayer
zachmayer / AttentionWithContext.py
Created September 13, 2017 15:52 — 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':