Last active
June 28, 2019 19:20
-
-
Save gaphex/915f47fb5723808d8057202c0c21d5ef to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Q = tf.placeholder("float", [dim]) | |
S = tf.placeholder("float", [None, dim]) | |
Qr = tf.reshape(Q, (1, -1)) | |
PP = tf.keras.backend.batch_dot(S, S, axes=1) | |
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