mirror of
https://github.com/openai/CLIP.git
synced 2026-11-05 01:37:26 +00:00
[GH-ISSUE #48] Two questions regarding model implementation: #43
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
openai/CLIP#43
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @vinsis on GitHub (Feb 24, 2021).
Original GitHub issue: https://github.com/openai/CLIP/issues/48
First of all thank you for providing the code and pretrained model. The results look stunning.
I was looking into the source code and there are two parts I am struggling to understand:
logit_scalein the model here? It seems to simply scale the dot products between two representations.VisualTransformerwhat is the role ofclass_embeddingdefined here.Thanks!
@PaulLerner commented on GitHub (Mar 3, 2021):
This is the embedding used for the final representation, see here they only keep the first "token" of each sequence.
See http://arxiv.org/abs/2010.11929 for more details about Vision Transformer :)
@vinsis commented on GitHub (Mar 4, 2021):
Got it, thanks.
The answer to the first question still remains elusive.
@jongwook commented on GitHub (Mar 4, 2021):
During contrastive learning, we interpret the dot products as logits that are fed to the cross-entropy loss for each text and image example. Because we normalize the feature vectors, the dot products are capped between [-1, 1], which might not have an enough dynamic range and limit the categorical probability distributions that the logits can express. For this reason, we scale the logits to have larger differences. To avoid numerical instability, we clipped the scale value at 100, and for all models that we trained, it reached 100. This comment explains how to clip the value.
@vinsis commented on GitHub (Mar 4, 2021):
Ok thanks. That explains it.
@Horizon2333 commented on GitHub (Oct 17, 2021):
So why don't you directly initialize temperature parameter to 100 ? What's the purpose of let it grow from 1/0.07 to 100? Does it bring enough performance improvement?
@justStarG commented on GitHub (May 30, 2024):
Yes, I think initialize to 100 will converge faster. But why not set to 100?
@yakorch commented on GitHub (Sep 8, 2025):
@Horizon2333 @thesby
I am late to the party, but perhaps this is still useful.
In Temperature-Free Loss Function for Contrastive Learning, the authors analyze the properties of the InfoNCE loss, showing that for high temperature values (in the paper notation that I cite), the total loss is non-zero even for correct model predictions (C -> 1).
However, my intuition is that at the start of the training, the model is poor, resulting in very few "C->1" predictions, so the optimization process does not experience this drawback of the chosen loss function. And this comes with a neat bonus of a strong gradient magnitude for non-optimal C, speeding up training.
After some training, hopefully the model is better, and "C->1" predictions are common, and one can no longer ignore the non-zero InfoNCE loss. Yet it is no longer a problem thanks to the decreasing temperature as a learnable parameter.