First,I have a tensor like this,
a = [[A B],[C D]]
I'd like to calculate cosin-similarity between each other,I mean calculate cos([A B],[A B]),cos([A B],[C D]),cos([C D],[A B]),cos([C D],[C D]) to form a similarity matrix like this,
[[cos([A B],[A B]),cos([A B],[C D])],
[cos([C D],[A B]),cos([C D],[C D])]]
I want to use follow code to get similarity matrix,it did't work.
`tf.losses.cosine_distance(tf.expand_dims(a, 0),
tf.expand_dims(a, 1), axis = 2)`
How to use efficient vectorization to do this work in TF1?thank your reply.
This may help,
output