Hi Ramraj!



 cramraj8:

What is the difference between cosine similarity functions torch.nn.CosineSimilarity and torch.nn.functional.cosine_similarity ?


The two are effectively the same and they can be used essentially
interchangeably.  In particular, they both support backpropagation
in the same way.
CosineSimilarity is the class / function-object version (and almost
certainly merely wraps a call to cosine_similarity()), while
cosine_similarity() is the function version.
It’s primarily a matter of style which you choose to use.  However,
CosineSimilarity is a Module, so you could, for example, place
it in a Sequential, if that were to make sense for your use case.
Best.
K. Frank