Representation Learning with Contrastive Predictive Coding — van den Oord, Li, VInyals
Information noise contrastive estimation (InfoNCE) loss builds on the noise-contrastive estimation (NCE) framework. It generalizes the binary classification problem (true data vs. noise distribution) to a multiclass classification problem, where the goal is to predict which of the N samples (1 positive and N-1 negatives) come from the true data distribution. It uses categorical cross-entropy loss to identify the positive sample.
Here, our true data is drawn from a conditional distribution with “context” c: . And our N-1 negative samples are drawn from the marginal distribution (independent of context c): . Let be all N samples, only one of which is , and be the position where the positive sample is located.
The probability of detecting the correct positive sample is:
Here, the denominator is summing over all the N possible positions for the positive sample.
Dividing the numerator and denominator by helps us cancel some terms:
Taking a scoring function , we get
The InfoNCE loss optimizes the negative log probability (aka cross-entropy loss) of classifying the positive example correctly:
In this way, InfoNCE is described as a probabilistic contrastive loss that retains information most helpful for predicting future samples. InfoNCE loss is commonly used in self-supervised learning for contrastive learning.
Showing consistency of InfoNCE and ranking NCE loss
- In InfoNCE, the N-1 negative samples are drawn from the marginal p(x), so p(x) = q(x)