SimCLR's contrastive loss, NT-Xent, asks for each anchor to pick its positive out of all the other views in the batch. It is a softmax cross-entropy over cosine similarities scaled by a temperature.
Implement nt_xent_anchor(sim_pos, sims_neg, tau), the softmax loss of the positive among the candidates.
logaddexp for numerical stability.Stack the positive and negative similarities divided by tau, then compute logsumexp minus the positive's logit.
No results yet
Run your code to check it against the examples, or submit to run every test.