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.
Glossary
Contrastive Predictive Coding (CPC)

What is Contrastive Predictive Coding (CPC)?
A framework for learning compact, high-level representations from high-dimensional sequential data by predicting future latent features.
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.
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.
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
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_taggregates information fromz_≤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
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
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
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
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
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.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Key concepts, architectures, and loss functions that operationalize the contrastive learning paradigm for genomic sequence representation.
InfoNCE Loss
The canonical loss function underpinning CPC. It uses a noise-contrastive estimation objective to maximize the mutual information between a context vector and a future latent, while simultaneously pushing apart negative samples drawn from a proposal distribution. In genomics, this forces the model to learn features that are predictive of downstream regulatory elements.
Autoregressive Context Network
The recurrent or masked transformer component in CPC that summarizes all past latent representations into a single, dense context vector. This vector discards local noise and retains slowly varying features, such as the presence of a CpG island or a promoter region, that are predictive of distant sequence patches.
Mutual Information Maximization
The core mathematical objective of CPC. Rather than minimizing pixel-level reconstruction error, the model maximizes the mutual information between context and future observations. This encourages the extraction of high-level, shared structure—like gene synteny or conserved non-coding elements—while ignoring low-level stochastic variation.
Negative Sampling Strategy
The method for selecting negative examples critically impacts representation quality. In genomic CPC, negative samples can be drawn from:
- Random positions on the same chromosome
- Different chromosomes entirely
- Synthetic sequences with matched nucleotide frequencies Hard negative mining, using sequences from homologous regions, prevents the model from learning trivial shortcuts.
SimCLR
A parallel contrastive framework that, unlike CPC's predictive approach, maximizes agreement between differently augmented views of the same input. For DNA, augmentations include random masking, reverse-complement flipping, or adding Gaussian noise to one-hot encodings. It learns strand-invariant and noise-robust genomic embeddings without requiring a sequential prediction task.
Contrastive Loss
A broader family of metric-learning objectives that organize the embedding space by pulling positive pairs (e.g., orthologous promoters) together and pushing negative pairs (e.g., random intergenic regions) apart. In genomics, this creates a semantically meaningful latent manifold where functionally similar sequences cluster, enabling zero-shot annotation transfer across species.

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.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us