Closed ToonTalk closed 2 years ago
@pyu10055 Would you be able to confirm why it was done this way? I believe you were involved in this model?
@ToonTalk Thanks for reporting this, this should be computed on the gpu for efficiency.
I used tf.matMul instead:
const scores = tf.matMul(embeddings['queryEmbedding'],
embeddings['responseEmbedding'], false, true).dataSync();
Reading https://github.com/tensorflow/tfjs-models/tree/master/universal-sentence-encoder the sample code needs to compute the dot product of two tensors and it uses arraySync on the tensors, nested for loops, and JavaScript defined vector operations. Wouldn’t it be better practice to use tf.layers.dot? The code would be much more concise and presumably much faster. (If it is the case the sample code predated tf.layers.dot then shouldn’t it be updated?)