Inferensys

Glossary

Contrastive Predictive Coding (CPC)

A self-supervised approach that learns representations by predicting future latent representations from past ones using autoregressive models and a probabilistic contrastive loss.
ML engineer running AI model benchmarks, performance charts on multiple screens, late night home office setup.
SELF-SUPERVISED REPRESENTATION LEARNING

What is Contrastive Predictive Coding (CPC)?

A self-supervised framework that learns representations by predicting future latent representations from past ones using autoregressive models and a probabilistic contrastive loss.

Contrastive Predictive Coding (CPC) is a self-supervised learning approach that trains an encoder to extract useful representations by maximizing the mutual information between past context and future observations in a latent space. The model uses an autoregressive network to summarize historical context into a compact vector, then employs a probabilistic contrastive loss—specifically the InfoNCE loss—to distinguish the true future latent representation from a set of randomly sampled negative distractors.

In medical imaging, CPC excels at learning from unlabeled volumetric sequences—such as adjacent CT slices or ultrasound frames—by predicting the latent features of subsequent frames from prior ones. This forces the encoder to capture clinically relevant anatomical structure and temporal dynamics without manual annotation. The resulting pre-trained representations transfer effectively to downstream tasks like tumor segmentation and disease progression modeling, where labeled data is scarce.

ARCHITECTURAL COMPONENTS

Key Features of Contrastive Predictive Coding

Contrastive Predictive Coding (CPC) learns powerful representations by predicting future latent states from past context using autoregressive models and a probabilistic contrastive loss. The following cards break down its core mechanisms.

01

Autoregressive Context Modeling

CPC employs an autoregressive model (typically a GRU or causal Transformer) to summarize the history of latent representations into a single context vector (c_t). This context vector is not a simple average; it encodes the sequential dependencies necessary to predict future states. The model is trained to make these predictions in a compressed latent space rather than the raw observation space, forcing it to discard low-level noise and retain high-level semantic information. This is critical for medical imaging sequences (e.g., ultrasound video or dynamic contrast-enhanced MRI) where temporal evolution carries diagnostic significance.

02

Density Ratio Estimation with InfoNCE

Instead of directly modeling the high-dimensional distribution of future observations p(x_{t+k} | c_t), CPC estimates a density ratio that preserves the mutual information between the context and future latents. The model uses the InfoNCE (Noise-Contrastive Estimation) loss, which frames the prediction task as a categorical classification problem. The objective is to correctly identify the true future latent (positive sample) from a set of randomly sampled negative latents. This probabilistic contrastive approach avoids the computational intractability of generative modeling while learning representations that maximize mutual information.

03

Mutual Information Maximization

The theoretical foundation of CPC is the maximization of mutual information (MI) between the context vector c_t and future latent representations z_{t+k}. The InfoNCE loss provides a lower bound on MI: I(x; c) ≥ log(N) - L_N, where N is the number of negative samples. By optimizing this bound, CPC learns to extract the underlying shared information between temporally separated signals. In medical imaging, this translates to learning features that capture anatomical and pathological structures invariant to short-term temporal variations, such as cardiac or respiratory motion.

04

Negative Sampling Strategy

The quality of CPC representations depends heavily on the negative sampling strategy. For a given positive pair (c_t, z_{t+k}), negative samples are drawn from other time steps within the same sequence or from entirely different sequences. Hard negative mining—selecting negatives that are semantically similar but temporally incorrect—forces the model to learn finer-grained distinctions. In medical contexts, this could mean distinguishing between visually similar tissue textures that appear at different phases of a contrast-enhanced scan, improving the model's sensitivity to subtle pathological changes.

05

Latent Space Prediction Architecture

CPC operates in a compressed latent space rather than raw pixel space. A non-linear encoder g_enc maps observations x_t to latent representations z_t. The autoregressive model g_ar then summarizes past latents into a context c_t. A log-bilinear model f_k(c_t, z_{t+k}) = exp(z_{t+k}^T W_k c_t) scores the compatibility between context and future latents. This separation of concerns—encoding, context aggregation, and scoring—allows each component to specialize. The encoder learns to extract meaningful features, the autoregressive model captures temporal dynamics, and the scoring function evaluates predictive accuracy.

06

Multi-Step Future Prediction

CPC predicts multiple future time steps simultaneously using separate prediction heads W_k for each offset k. This multi-step objective forces the context vector c_t to encode information relevant across different temporal horizons, from immediate next-step features to longer-range semantic structure. The model learns a hierarchy of temporal representations: short-term predictions capture local dynamics, while long-term predictions require understanding global context. For medical time-series like EEG or functional MRI, this enables the extraction of features spanning multiple temporal scales relevant to neurological diagnosis.

REPRESENTATION LEARNING COMPARISON

CPC vs. Other Self-Supervised Learning Methods

Architectural and functional comparison of Contrastive Predictive Coding against dominant self-supervised learning paradigms for medical imaging.

FeatureCPCSimCLRMasked Autoencoder (MAE)BYOL

Core Objective

Predict future latent representations from past context using autoregressive models

Maximize agreement between differently augmented views via contrastive loss

Reconstruct masked image patches from visible context

Predict target representations of a momentum encoder without negative pairs

Negative Samples Required

Autoregressive Component

Temporal/Sequential Modeling

Primary Loss Function

InfoNCE (density ratio estimation)

NT-Xent (normalized temperature-scaled cross entropy)

MSE (mean squared error reconstruction)

MSE (latent prediction error)

Architecture Type

Autoregressive encoder + context network

Joint embedding with projection head

Asymmetric encoder-decoder

Siamese networks with stop-gradient

Representation Collapse Risk

Low (explicit negative repulsion)

Low (explicit negative repulsion)

Low (reconstruction objective)

Moderate (requires stop-gradient and EMA)

Suitability for 3D Volumetric Data

High (native sequential modeling of slices)

Moderate (requires 3D augmentations)

High (native patch masking in 3D)

Moderate (requires 3D augmentations)

CONTRASTIVE PREDICTIVE CODING

Frequently Asked Questions

Clear, technically precise answers to the most common questions about Contrastive Predictive Coding (CPC), its mechanisms, and its application in medical imaging.

Contrastive Predictive Coding (CPC) is a self-supervised representation learning approach that learns useful features by training an autoregressive model to predict future latent representations from past ones using a probabilistic contrastive loss (InfoNCE). The architecture consists of a non-linear encoder that maps raw observations (e.g., image patches) to a sequence of latent vectors, and an autoregressive context model (typically a GRU or transformer) that summarizes all past latents into a single context vector. Instead of predicting raw pixel values, CPC maximizes the mutual information between the context vector and future latent representations. This is achieved by training the model to correctly identify the true future latent from a set of negative samples drawn from the same sequence or batch. The key insight is that by forcing the model to distinguish between temporally coherent and incoherent representations, it learns to extract the slow, high-level features that encode the underlying structure of the data—features that are highly transferable to downstream tasks like classification or segmentation.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.