Token LabBuscar

← Biblioteca de artículos
Representations & contrastive learning / 2018

CPC: learn by identifying the right future

Treat contrastive prediction as a classification problem and inspect what negative sampling assumes.

Representation Learning with Contrastive Predictive Coding · van den Oord, Li & Vinyals · arXiv:1807.03748

Original editorial analysis by Token Lab · Source checked 2026-10-25 · Paper claims and synthetic examples are separated.

Detailed technical articles are available in English and Chinese. This locale shows the English article with localized navigation.

01 · What the paper establishes

CPC predicts future latent representations from an autoregressive context using a contrastive objective. The paper explores speech, images, text and reinforcement-learning environments. Its mutual-information interpretation depends on the sampling construction and objective assumptions.

Primary source: paper abstract ↗
Study guide & lesson outlineLEARNING CONTRACT

Understand → implement → investigate

Goal: explain the mechanism in this lesson, reproduce one example and test a failure case. Reading alone does not mark mastery.

  • Understand: state assumptions, shapes/units and a counterexample.
  • Implement: reproduce a numerical example and inspect boundaries.
  • Investigate: compare one alternative under a matched budget.

02 · The mechanism

Text / 原始公式
L = −log [exp(s₊/τ) / Σⱼ exp(sⱼ/τ)]
∂L/∂sⱼ = (pⱼ−1[j=+])/τ
Under InfoNCE assumptions: I(X;C) ≥ log N − L_N

The learner does not need to reconstruct every pixel or waveform sample to discriminate a plausible continuation. Context should retain information useful for that discrimination. Negatives define what counts as an alternative; if their distribution is wrong, a shortcut can solve the classification task without the intended representation. N includes the positive candidate in the displayed bound.

Notation and intuition are teaching explanations. Consult the original method for complete assumptions and implementation details.

Mechanism map & worked derivation

Encode observations → Summarize context → Score future and negatives → Contrastive loss → encoder
Original schematic; read the steps from top to bottom. SVG ↓
Symbols and assumptions
SymbolMeaning
s₊Positive candidate compatibility score
τTemperature, strictly positive
NTotal candidates including the positive
  1. Rewrite the loss as −s₊/τ+logΣexp(sⱼ/τ). Differentiating the log-sum-exp produces pⱼ/τ; the positive also gets −1/τ.
  2. For scores [2,1,0,−1] and τ, probabilities are approximately [0.643914,0.236883,0.087144,0.032059]. Score gradients are [−0.356086,0.236883,0.087144,0.032059].
  3. The gradients sum to zero because adding the same constant to every score leaves the distribution unchanged. Use this invariance as a numerical implementation check.
Experiment checkpoint

Compare analytical gradients with central differences. Audit whether the negative sampler leaks source identity.

LOCAL / SYNTHETIC / INTERACTIVE

Change one variable. Explain what moves.

Original teaching calculation, not a reproduction of the paper’s benchmark. Bars are relative within this panel; numeric values and units are authoritative.

04 · Work through an example

Original example: four candidates have scores [2,1,0,−1], with the first positive and τ Its probability is about 0.644, giving loss 0.440. The number log 4−0.440≈0.946 is an illustrative bound expression; a single hand-picked row does not estimate population mutual information. Lower temperature sharpens the distribution but also changes gradient scaling.

05 · Design your experiment

Check analytical score gradients against finite differences. Then deliberately add a false negative and inspect its repulsive gradient. For an encoder POC, split data by source identity before constructing pairs, document the negative sampler and evaluate frozen representations with a held-out probe. Compare downstream metrics, not only contrastive loss.

Research deliverable

State one hypothesis; save the configuration and raw results; identify a competing explanation; report the narrowest supported conclusion. Use the linked lab as a local starting point, not a full paper reproduction.

Open related lesson / lab →

06 · Limits & reviewer questions

Editorial caution: easier discrimination can mean better shortcuts rather than better semantics. More negatives can introduce false negatives and change optimization. Do not label a toy log-N-minus-loss calculation as a measured information content of a real model.

Why can removing a false negative lower loss without proving better retrieval?

Removing a denominator term makes the classification task easier immediately, even with unchanged embeddings. Retrieval quality requires a separate fixed candidate set and held-out relevance labels.

07 · Read the original

Section 2.3 and Appendix A.1. Write the sampling distribution beside each probability.

Year is the first arXiv submission year. Unversioned links follow revisions; record the exact version in your reproduction report. DeepSeek-R1 here is explicitly pinned to v1.

Continue this topic

MATHEMATICAL REVIEW · 2026-10-26

Assumptions, implementation & acceptance

The mutual-information bound uses population expected InfoNCE loss: positives from the joint and independent negatives from the corresponding marginal. A single row loss is not a mutual-information estimate. Temperature must be positive.

Displayed formula, bilingual explanation and declared slider range. This code reproduces the scalar teaching calculation, not the paper training system.

Before running: predict a boundary case

Check analytical score gradients against finite differences. Then deliberately add a false negative and inspect its repulsive gradient. For an encoder POC, split data by source identity before constructing pairs, document the negative sampler and evaluate frozen representations with a held-out probe. Compare downstream metrics, not only contrastive loss.

Hint: isolate the assumption

Keep the baseline input fixed, change one parameter or boundary, and compare both the numerical result and the claimed units. A passing example verifies this fixture only.

Minimal executable example

Save the example and linked modules in one folder. Use Node.js 22 or newer, then run node contrastive-predictive-coding.mjs. No third-party runtime dependencies.

import {paperCalc} from './paper-core.mjs';
const result=paperCalc("cpc",1);
console.log(result);
Reference output — reveal after predicting
{
  "labels": [
    "Positive",
    "Negative 1",
    "Negative 2",
    "Negative 3"
  ],
  "values": [
    0.6439142598879724,
    0.23688281808991013,
    0.08714431874203257,
    0.03205860328008499
  ],
  "unit": "probability",
  "extra": 0.4401896985611953,
  "extraLabel": "Loss (nats)"
}

Test and transfer

Check analytical score gradients against finite differences. Then deliberately add a false negative and inspect its repulsive gradient. For an encoder POC, split data by source identity before constructing pairs, document the negative sampler and evaluate frozen representations with a held-out probe. Compare downstream metrics, not only contrastive loss.

Record input, code version, expected result and observed result in the notebook below. Then construct a counterexample that violates the assumption above and explain why the original conclusion no longer follows.

Download complete kit (.tar.gz) · Complete reference kit and regression checks

Predict, test and keep evidence

Before revealing an answer, predict one result. After the exercise, record the discrepancy and a transfer test. Saved locally across language editions.

Open notebook / export / clear →

The mathematical review scope is recorded per lesson. It does not establish empirical paper reproduction; report suspected errors in your notes. Review scope