Skip to content

Instantly share code, notes, and snippets.

@vlavorini
Last active October 3, 2017 10:52
Show Gist options
  • Save vlavorini/c7114aca9d1bdc1cf37195b4295c9ae2 to your computer and use it in GitHub Desktop.
Save vlavorini/c7114aca9d1bdc1cf37195b4295c9ae2 to your computer and use it in GitHub Desktop.
expd=tf.expand_dims(ptf,2) # from (n_emb x emb_dim) to (n_emb x emb_dim x 1)
tiled=tf.tile(expd, [1,1,tf.shape(ptf)[0]]) # copying the same matrix n times
trans=tf.transpose(ptf)
num=tf.reduce_sum(tf.squared_difference(trans,tiled), 1)
den1=1-tf.reduce_sum(tf.square(ptf),1)
den1=tf.expand_dims(den1, 1)
den=tf.matmul(den1, tf.transpose(den1))
tot=1+2*tf.div(num, den)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment