Skip to content

Instantly share code, notes, and snippets.

@gaphex
Created June 23, 2019 18:05
Show Gist options
  • Save gaphex/2e6a28275a9e999e69bdf84b3f0c4686 to your computer and use it in GitHub Desktop.
Save gaphex/2e6a28275a9e999e69bdf84b3f0c4686 to your computer and use it in GitHub Desktop.
Q = tf.placeholder("float", [dim])
S = tf.placeholder("float", [None, dim])
S_norm = tf.placeholder("float", [None, 1])
Qr = tf.reshape(Q, (1, -1))
PP = S_norm
QQ = tf.matmul(Qr, tf.transpose(Qr))
PQ = tf.matmul(S, tf.transpose(Qr))
distance = PP - 2 * PQ + QQ
distance = tf.sqrt(tf.reshape(distance, (-1,)))
top_neg_dists, top_indices = tf.math.top_k(tf.negative(distance), k=top_k)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment