Skip to content

Instantly share code, notes, and snippets.

@ericjang
Last active February 24, 2016 14:13
Show Gist options
  • Save ericjang/63cb2235060c2225592b to your computer and use it in GitHub Desktop.
Save ericjang/63cb2235060c2225592b to your computer and use it in GitHub Desktop.
def linear(x,output_dim):
"""
affine transformation Wx+b
assumes x.shape = (batch_size, num_features)
"""
w=tf.get_variable("w", [x.get_shape()[1], output_dim])
b=tf.get_variable("b", [output_dim], initializer=tf.constant_initializer(0.0))
return tf.matmul(x,w)+b
def attn_window(scope,h_dec,N):
with tf.variable_scope(scope,reuse=DO_SHARE):
params=linear(h_dec,5)
gx_,gy_,log_sigma2,log_delta,log_gamma=tf.split(1,5,params)
gx=(A+1)/2*(gx_+1)
gy=(B+1)/2*(gy_+1)
sigma2=tf.exp(log_sigma2)
delta=(max(A,B)-1)/(N-1)*tf.exp(log_delta) # batch x N
return filterbank(gx,gy,sigma2,delta,N)+(tf.exp(log_gamma),)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment