Loss Comparison: CLIP vs SigLIP¶
Let \(\mathbf{U}, \mathbf{V} \in \mathbb{R}^{N \times D}\) be the \(\ell_2\)-normalized image and text embeddings respectively.
Let \(\mathbf{S} = \mathbf{U}\mathbf{V}^\top\) be the \(N \times N\) matrix of cosine similarity scores, where \(s_{ij} = \mathbf{u}_i \cdot \mathbf{v}_j\).
Let \(t = e^{t'}\) be the learned temperature parameter.
CLIP Loss¶
For a vector \(\mathbf{x} \in \mathbb{R}^K\), the softmax function is defined as:
Defining the row-wise softmax probabilities:
That is,
In general, for soft labels \(y_{ij} \in [0,1]\) representing the affinity between image \(i\) and text \(j\):
Where \(\mathbf{CE}\) is the cross entropy function. For probability vectors \(\hat{\mathbf{p}}, \mathbf{y} \in \mathbb{R}^K\) over \(K\) categories:
For distribution matrices \(\hat{\mathbf{P}} \in \mathbb{R}^{N \times K}\) and \(\mathbf{Y} \in \mathbb{R}^{N \times K}\), where each row is a distribution over \(K\) categories and \(N\) is the batch size:
In standard CLIP with hard labels:
- \(y_{ij} = 1 \iff\) image \(i\) corresponds to text \(j\)
- \(y_{ij} = 0 \iff\) image \(i\) does not correspond to text \(j\)
The loss becomes:
Hence, CLIP uses a symmetric softmax-based contrastive loss (InfoNCE). For each image \(i\), it treats the matching text \(i\) as the correct class among \(N\) candidates (and vice versa).
SigLIP Loss¶
Defining the pairwise sigmoid probability:
where \(b\) is a learned bias term.
In general, for soft labels \(y_{ij} \in [0,1]\) representing the affinity between image \(i\) and text \(j\):
Note that binary cross entropy (BCE) is simply the \(C = 2\) case of CE. For a single prediction \(\hat{p} \in [0,1]\) and label \(y \in \{0,1\}\), the distribution vectors are \(\hat{\mathbf{p}} = (\hat{p},\; 1 - \hat{p})\) and \(\mathbf{y} = (y,\; 1 - y)\), giving:
Each pair \((i, j)\) contributes one such binary classification. Applying this to every pair:
Equivalently, flattening the \((i,j)\) pairs into a single batch dimension of size \(N^2\), this is just the matrix \(\mathbf{CE}\) applied to an \(N^2 \times 2\) matrix where each row contains \((\hat{P}^{\text{sig}}_{ij},\; 1 - \hat{P}^{\text{sig}}_{ij})\) with corresponding labels \((y_{ij},\; 1 - y_{ij})\):
In standard SigLIP with hard labels:
- \(y_{ij} = 1 \iff\) image \(i\) corresponds to text \(j\) (positive pair)
- \(y_{ij} = 0 \iff\) image \(i\) does not correspond to text \(j\) (negative pair)
The loss becomes:
where we use \(z_{ij} = 2y_{ij} - 1 \in \{+1, -1\}\) and the identity \(1 - \sigma(x) = \sigma(-x)\).
Learnable parameters:
- \(t = e^{t'}\): temperature (initialized with \(t' = \log 10\), so \(t = 10\))
- \(b\): bias term (initialized to \(-10\))
The bias \(b\) is crucial for training stability — it prevents large initial gradient updates from the heavy imbalance of \(N^2 - N\) negative pairs vs \(N\) positive pairs.
Key Differences¶
| Property | CLIP | SigLIP |
|---|---|---|
| Loss type | Softmax (N-way classification) | Sigmoid (pairwise binary) |
| Normalization | Global across batch | Per-pair independent |
| Symmetry | Two passes (I→T and T→I) | Single symmetric pass |
| Learnable params | Temperature \(t\) | Temperature \(t\) + bias \(b\) |
| Memory | \(O(N^2)\) for full softmax | \(O(N^2)\) but chunked-friendly |
CLIP Loss Multiclass Analysis¶
When a batch contains \(n\) images \(i, i{+}1, \ldots, i{+}n{-}1\) whose corresponding texts are all identical, i.e. \(\mathbf{v}_{i} = \mathbf{v}_{i+1} = \cdots = \mathbf{v}_{i+n-1}\), it is natural to replace the identity target \(\mathbf{Y} = \mathbf{I}_N\) with a block-diagonal target \(\mathbf{Y}'\) that assigns equal credit to every correct match. Concretely, \(\mathbf{Y}'\) equals \(\mathbf{I}_N\) except on the \(n \times n\) block covering rows and columns \(i, \ldots, i{+}n{-}1\), where:
We prove that this does not change the loss: \(\mathcal{L}_{\text{CLIP}}(\mathbf{Y}) = \mathcal{L}_{\text{CLIP}}(\mathbf{Y}')\).
Since \(\mathbf{Y}\) and \(\mathbf{Y}'\) differ only on rows \(i, \ldots, i{+}n{-}1\), it suffices to show equality of the contributions from these rows in both the image-to-text and text-to-image terms.
Key identity¶
Because the texts agree, \(\mathbf{v}_{i+c} = \mathbf{v}_{i+k}\), we have \(s_{r,\, i+c} = s_{r,\, i+k}\) for all \(r\) and all \(c, k \in \{0, \ldots, n{-}1\}\). Since the softmax is applied row-wise to \(t \cdot \mathbf{S}\), this gives:
That is, for every row \(r\), the entries at columns \(i\) through \(i{+}n{-}1\) are equal (same-coloured entries denote equal values):
Similarly, since the text-to-image term \(\hat{\mathbf{P}}^{(T \to I)} = \text{row-Softmax}(t \cdot \mathbf{S}^\top)\).
That is, rows \(i\) through \(i{+}n{-}1\) of \(\hat{\mathbf{P}}^{(T \to I)}\) are identical:
Part 1: Image-to-text loss¶
Consider the contribution of row \(i{+}k\) for a fixed \(k \in \{0, \ldots, n{-}1\}\).
Under \(\mathbf{Y} = \mathbf{I}_N\):
Under \(\mathbf{Y}'\):
where the second equality uses \((\ast)\). Since this holds for every \(k\), the image-to-text contribution from these \(n\) rows is unchanged.
Part 2: Text-to-image loss¶
Under \(\mathbf{Y}'\):
Under the block target, every row \(i{+}k\) in this block has both the same softmax outputs (by \((\ast\ast)\)) and the same target row (\(Y'_{i+k,:}\) is identical for all \(k\)). Therefore every row contributes the same loss, and the total contribution from the \(n\) rows is \(n\) times the loss from a single row:
Under \(\mathbf{Y} = \mathbf{I}_N\):
where the second equality applies \((\ast\ast)\) to replace row \(i{+}k\) with row \(i\). This is the same expression.
Conclusion¶
The duplicate texts create two symmetries. Column equality \((\ast)\) makes the image-to-text block target simply average \(n\) identical log-probabilities. Row equality \((\ast\ast)\) lets the text-to-image contributions collapse: both the identity and block targets reduce to the same sum \(-\sum_{c=0}^{n-1} \log \hat{P}^{(T \to I)}_{i,\, i+c}\). Consequently, assigning soft targets that split credit equally among duplicate text entries does not change the CLIP loss.
So... if we want a multi class loss function we will have to get back to the drawing board!
Note this proof works for duplicate images too by symetry.