Skip to content
ml-recall

#contrastive-loss

1 question from Transfer Learning

Timed test

1 question · 1 min · score and explanations at the end

Take a test
Q 1 / 1Score 0 / 0

Question 1: Short answer

mediumAI-checkedTransfer Learning

A SimCLR loss builds a 2N×2N2N \times 2N cosine-similarity matrix sim for NN images, each seen in two augmented views (rows ii and i+Ni + N are the two views of image ii):

pos = torch.roll(torch.eye(2 * N), N, 1)      # 1 where the column is the other view
neg = torch.ones(2 * N) - torch.eye(2 * N)    # 1 everywhere except the diagonal
numerator = torch.exp(sim / T)[pos.bool()]
denominator = torch.sum(torch.exp(sim / T) * neg, dim=1)
loss = torch.mean(-torch.log(numerator / denominator))

With a batch of N=4N = 4 images, how many terms are summed in each row of denominator?

an integer