Inferensys

Glossary

Contrastive Predictive Coding (CPC)

A self-supervised representation learning method that trains an encoder to extract slowly varying features by maximizing the mutual information between the latent representations of temporally or spatially distant patches of a sequence.
Data engineer managing feature store on laptop, feature definitions visible, casual data engineering session.
SELF-SUPERVISED REPRESENTATION LEARNING

What is Contrastive Predictive Coding (CPC)?

A framework for learning compact, high-level representations from high-dimensional sequential data by predicting future latent features.

Contrastive Predictive Coding (CPC) is a self-supervised learning method that trains an encoder to extract slowly varying features—the "slow features" that capture shared information—by maximizing the mutual information between the latent representations of temporally or spatially distant patches of a sequence. It combines autoregressive modeling with noise-contrastive estimation to learn representations that encode the underlying shared structure across different parts of the data.

In genomic applications, CPC learns dense embeddings that capture functional and evolutionary constraints by predicting downstream nucleotide contexts from upstream latent representations. The model uses a contrastive loss to distinguish a true future latent vector from a set of negative samples, forcing the encoder to discard low-level, stochastic variation and retain only the high-level, slowly varying features relevant to regulatory syntax and long-range interactions.

SELF-SUPERVISED REPRESENTATION LEARNING

Key Characteristics of CPC

Contrastive Predictive Coding (CPC) is a self-supervised framework that learns powerful representations by maximizing mutual information between latent embeddings of temporally or spatially distant sequence patches, forcing the model to extract slowly varying, high-level features that discard low-level noise.

01

InfoNCE Loss Objective

CPC uses a noise-contrastive estimation loss called InfoNCE to train the encoder. The model must distinguish a true future latent from a set of negative samples drawn from the proposal distribution.

  • Maximizes a lower bound on mutual information between context and future latents
  • The loss is computed as a categorical cross-entropy over the positive and N-1 negative samples
  • A higher N (more negatives) improves the tightness of the mutual information bound
  • The log-bilinear density ratio scores compatibility between context vectors and target embeddings
02

Autoregressive Context Network

CPC employs a unidirectional recurrent or masked transformer that summarizes all past latent observations into a single compact context vector. This context is then used to predict future latents multiple steps ahead.

  • Typically implemented with a GRU or causal transformer decoder
  • The context vector c_t aggregates information from z_≤t
  • Enables prediction of latents at multiple future time offsets (e.g., z_{t+1}, z_{t+2}, z_{t+4})
  • The architecture enforces a bottleneck that discards local noise and retains global structure
03

Slow Feature Extraction

By predicting across long temporal or spatial horizons, CPC forces the encoder to learn slowly varying features that are shared across distant patches of the sequence. High-frequency, unpredictable noise is naturally discarded.

  • The prediction horizon is a critical hyperparameter controlling abstraction level
  • Short horizons capture local texture; long horizons capture global semantics
  • In genomics, this extracts regulatory motifs that span hundreds of base pairs
  • The mutual information maximization principle is agnostic to the data modality
04

Genomic Sequence Application

When applied to DNA sequences, CPC learns embeddings that capture functional regulatory syntax without requiring labeled data. The model predicts the latent representation of a downstream genomic region from the context of an upstream region.

  • Tokenized nucleotides or k-mers are encoded into latent vectors z_t
  • The context network summarizes a promoter or enhancer region
  • The model predicts the embedding of a distal transcription factor binding site or exon
  • Learned representations transfer effectively to variant effect prediction and chromatin state classification
05

Contrastive Pre-Training Paradigm

CPC is a foundational example of the contrastive pre-training paradigm that preceded and influenced models like SimCLR and MoCo. It demonstrated that self-supervised learning could rival supervised pre-training on downstream tasks.

  • Published by van den Oord et al. at DeepMind in 2018
  • Originally demonstrated on speech, images, text, and reinforcement learning environments
  • The strided cropping strategy for images creates spatial patches analogous to temporal windows
  • Established the principle that predicting in latent space is superior to predicting in pixel or token space
06

Negative Sampling Strategy

The choice of negative samples critically impacts representation quality. CPC samples negatives from the same sequence or batch, forcing the model to discriminate between genuine long-range dependencies and spurious correlations.

  • Negatives can be drawn from other positions in the same sequence or from other sequences in the batch
  • Hard negative mining selects negatives that are most confusable with the positive
  • In genomics, negatives from the same chromosome prevent the model from learning trivial GC-content biases
  • The strategy implicitly defines what the representation should be invariant to
UNDERSTANDING CPC

Frequently Asked Questions

Clear answers to common questions about Contrastive Predictive Coding and its role in learning representations from sequential data without labeled examples.

Contrastive Predictive Coding (CPC) is a self-supervised representation learning method that trains an encoder to extract slowly varying features by maximizing the mutual information between the latent representations of temporally or spatially distant patches of a sequence. The architecture consists of a non-linear encoder that maps raw observations to a compact latent space, followed by an autoregressive context model that aggregates past latents into a summary vector. The model is trained using a noise-contrastive estimation loss, where the context vector must distinguish a true future latent from a set of negative samples drawn from the same sequence or batch. This forces the encoder to discard low-level noise and preserve high-level structure that is shared across long temporal windows, making CPC particularly effective for discovering representations useful for downstream tasks like classification or prediction.

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.