How to compute the cosine_similarity in pytorch for all rows in a matrix with respect to all rows in another matrix
问题 In pytorch, given that I have 2 matrixes how would I compute cosine similarity of all rows in each with all rows in the other. For example Given the input = matrix_1 = [a b] [c d] matrix_2 = [e f] [g h] I would like the output to be output = [cosine_sim([a b] [e f]) cosine_sim([a b] [g h])] [cosine_sim([c d] [e f]) cosine_sim([c d] [g h])] At the moment I am using torch.nn.functional.cosine_similarity(matrix_1, matrix_2) which returns the cosine of the row with only that corresponding row in