To learn what photos show without any labels, a model gets two crops of each photo and has to tell which crops belong together. For one crop, the model scores how alike it is to every crop in the batch (“Invent the score”, from −1 to 1). twin is the index of the other crop of the same photo; the rest are strangers. Write twin_loss(similarities, twin, temperature): one number training pushes down, lower when the crop picks out its twin better. temperature sets how sharply it picks (“Confident or cautious”).
One crop of a dog photo has a twin, the other crop of the same photo, somewhere in a batch of crops; the rest are strangers. The model scores how alike each crop is to this one. Watch two batches, then drag the strangers around.
twin_loss(similarities, twin, temperature)| similarities | how alike this crop is to each crop in the batch (-1 to 1) | e.g. [0.9, 0.95, 0.95, 0.95] |
| twin | the index of the other crop of the same photo | e.g. 0 |
| temperature | how sharply to pick (small = sharp) | e.g. 0.1 |
| returns | one number: lower = it picks out its twin better | |