sthalles / SimCLR

PyTorch implementation of SimCLR: A Simple Framework for Contrastive Learning of Visual Representations
https://sthalles.github.io/simple-self-supervised-learning/
MIT License
2.19k stars 457 forks source link

Calculation of the similarity #52

Closed ClaudiaShu closed 2 years ago

ClaudiaShu commented 2 years ago

Hi! Thank you for your great work! I'm a bit curious here about how you calculated the cosine similarity. The code just put the similarity calculation with similarity_matrix = torch.matmul(features, features.T).

ClaudiaShu commented 2 years ago

I understand why you did it, thanks. The l2-normalization of hidden states is equivalent to the use of cosine similarity instead of simply dot product.