Skip to content
ml-recall

#in-batch-negatives

1 question from PyTorch

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-checkedPyTorch

A batch holds bb images x and their augmented copies x_pos. For row i, x_pos[i] is the positive and the other b−1b - 1 rows of x_pos are its negatives:

z1 = F.normalize(f(x), dim=1)        # (b, d)
z2 = F.normalize(f(x_pos), dim=1)    # (b, d)
logits = z1 @ z2.T / tau             # (b, b)

Complete the loss: loss = F.cross_entropy(logits, torch.(b))

Fill in every blank (hints in the boxes). Enter moves to the next blank.