Part III: Discovery Through Data and Models
Chapter 26: Representation Learning

Representation Learning

"I contain multitudes of features, yet the linear probe only asks me for one direction at a time. It is simultaneously flattering and reductive."

A Feature Vector Lost in Latent Space

Overview

Raw data, whether it is a protein sequence, a spectrogram, or a research abstract, lives in a space that is vast, sparse, and full of irrelevant variation. A pixel grid tells you nothing about molecular function; a bag of characters reveals nothing about scientific meaning. Representation learning is the art and science of transforming raw observations into compact vector spaces where the geometry itself encodes useful structure: similar items cluster together, meaningful differences correspond to interpretable directions, and downstream tasks become simple linear operations on the learned coordinates.

This chapter covers three pillars. First, self-supervised learning (SSL) lets us train powerful encoders without human labels by exploiting the structure inherent in data itself. Second, contrastive objectives provide the mathematical machinery (NT-Xent loss, mutual information maximization, alignment and uniformity) that makes SSL work. Third, we develop rigorous tools for evaluating learned representations, from linear probes to intrinsic geometry metrics. We close with a hands-on recipe: training a domain-specific contrastive embedding model on scientific abstracts, producing representations that outperform generic encoders on domain retrieval tasks.

The representations we build here are the substrate on which the rest of Part III operates. Chapter 27: Scientific Foundation Models scales these ideas to billions of parameters. Chapter 28: Multimodal Scientific AI aligns representations across modalities using the same contrastive principles. And Chapter 30: Anomaly and Novelty Discovery uses learned representations as the space in which anomalies become geometrically obvious. The search framework from Chapter 1 told us that discovery is navigation through a space; this chapter teaches us how to build that space from raw data.

Prerequisites

Readers should be comfortable with the material in Chapter 5: Discovery Through Data, Models, and Simulation (data pipelines and model training basics) and Chapter 25: Exploratory Discovery (dimensionality reduction, clustering, and the motivation for learning structure from data). Familiarity with PyTorch (tensors, autograd, training loops) is assumed; see Appendix B for a refresher. The mathematical prerequisites are linear algebra (dot products, norms, matrix operations) and basic probability (expectations, KL divergence), both covered in Appendix A.

Learning Outcomes

Sections

26.1 Self-Supervised Learning

The three paradigms of learning without labels: masked prediction (BERT, MAE), contrastive learning (SimCLR, MoCo), and generative modeling (VAE, diffusion). Pretext tasks as implicit supervision. Why SSL dominates scientific AI.

26.2 Contrastive Objectives

NT-Xent loss derivation from InfoNCE and mutual information. Alignment and uniformity as dual desiderata. Temperature scaling, hard negatives, and the role of projection heads. SimCLR, MoCo, and CLIP architectures compared.

26.3 Representation Evaluation

Linear probes, k-NN classifiers, and retrieval metrics for measuring representation quality. Intrinsic dimension, isotropy, and the uniformity gap. Centered Kernel Alignment for comparing representation spaces.

26.4 Building a Domain Embedding Model

Recipe: fine-tune a contrastive embedding model on scientific abstracts using sentence-transformers. Data curation, hard negative mining, multi-task training, and evaluation on domain retrieval benchmarks.

What's Next

The representations we learned here on thousands of abstracts are effective, but they are small-scale compared to what modern infrastructure can support. Chapter 27: Scientific Foundation Models takes the same principles (self-supervised pretraining, contrastive alignment, transfer learning) and scales them to billions of parameters and terabytes of scientific data. You will see how the NT-Xent loss from Section 26.2 reappears in the pretraining of protein language models, molecular foundation models, and scientific LLMs, producing representations that transfer across tasks, domains, and even modalities.

Bibliography

Foundational Papers

Chen, T., Kornblith, S., Norouzi, M., & Hinton, G. (2020). A simple framework for contrastive learning of visual representations. ICML 2020.

The SimCLR paper that demonstrated the power of simple contrastive learning with large batch sizes and learnable nonlinear projections, achieving results competitive with supervised pretraining.

He, K., Fan, H., Wu, Y., Xie, S., & Girshick, R. (2020). Momentum contrast for unsupervised visual representation learning. CVPR 2020.

MoCo introduced the momentum-updated encoder and dictionary queue, enabling contrastive learning with large negative sets without requiring enormous batch sizes.

Radford, A., et al. (2021). Learning transferable visual models from natural language supervision. ICML 2021.

CLIP aligned image and text representations through contrastive pretraining on 400 million image-text pairs, enabling zero-shot transfer to dozens of visual tasks.

Wang, T. & Isola, P. (2020). Understanding contrastive representation learning through alignment and uniformity on the hypersphere. ICML 2020.

Decomposed contrastive loss into alignment (positive pairs close) and uniformity (features spread on the hypersphere), providing the theoretical lens used throughout Section 26.2.

van den Oord, A., Li, Y., & Vinyals, O. (2018). Representation learning with contrastive predictive coding. arXiv:1807.03748.

Introduced InfoNCE, the contrastive loss derived from noise-contrastive estimation of mutual information, which underlies NT-Xent and most modern contrastive objectives.

Books

Goodfellow, I., Bengio, Y., & Courville, A. (2016). Deep Learning. MIT Press.

Chapter 15 covers representation learning foundations; the concept of disentangled representations and the manifold hypothesis provide theoretical grounding for this chapter.

Tools & Libraries

PyTorch

The deep learning framework used throughout this chapter for implementing contrastive training loops, custom loss functions, and encoder architectures.

Hugging Face Transformers

Provides pretrained transformer encoders (BERT, SciBERT, RoBERTa) used as backbones for our domain embedding models.

sentence-transformers

The library used in Section 26.4 for training and fine-tuning sentence embedding models with contrastive and multiple-negatives-ranking losses.

lightly

A self-supervised learning framework for PyTorch that provides implementations of SimCLR, MoCo, BYOL, and other SSL methods with minimal boilerplate.

Tutorials & Surveys

Balestriero, R., et al. (2023). A cookbook of self-supervised learning. arXiv:2304.12210.

A comprehensive survey covering SSL paradigms, architectural choices, and evaluation protocols, serving as an excellent companion to this chapter.

Reimers, N. & Gurevych, I. (2019). Sentence-BERT: Sentence embeddings using Siamese BERT-networks. EMNLP 2019.

The foundational paper for sentence-transformers, demonstrating how to adapt BERT for efficient sentence-level embeddings with contrastive training.

Datasets & Benchmarks

Muennighoff, N., et al. (2023). MTEB: Massive Text Embedding Benchmark. EACL 2023.

The standard benchmark for evaluating text embedding models across retrieval, classification, clustering, and semantic similarity tasks.

Lo, K., et al. (2020). S2ORC: The Semantic Scholar Open Research Corpus. ACL 2020.

A large-scale corpus of scientific papers used as training data for domain-specific embedding models in Section 26.4.