liveBook · Manning

Contrastive learning

Contrastive learning is a representation-learning technique that trains a model to bring representations of related examples closer and separate representations of unrelated examples.

How 3 Manning books explain it

Retrieval Augmented Generation, The Foundational Ideas

Contrastive learning trains representations by bringing related examples closer and pushing unrelated examples farther apart in representation space.

How it is used
Supports scalable semantic similarity search and zero-shot dense retrieval by shaping a shared embedding space.
How deep it goes
Explains pairwise geometry, Siamese encoders, pooling, and indexing benefits, but does not specify a mathematical loss formula.
Examples
Uses Sentence-BERT similarity search and Contriever-powered HyDE retrieval as concrete applications.
What you can do after
Apply it via Siamese encoders and FAISS to precompute embeddings and perform fast similarity search.

Read how Retrieval Augmented Generation, The Foundational Ideas explains contrastive learning →

Build a Text-to-Image Generator (from Scratch)

Contrastive learning is a representation-learning technique that brings related examples closer and separates nonmatching examples in an embedding space.

How it is used
Uses shared embeddings to measure image–text similarity and support cross-modal retrieval.
How deep it goes
Explains encoders, batch similarities, and bidirectional losses, then stops short of deriving the loss equations.
Examples
Demonstrates Flickr 8k image–caption pairs, a beach-dog prompt, and batch diagonal versus off-diagonal similarities.
What you can do after
Apply it via CLIP to select images matching text descriptions and evaluate image–text compatibility.

Read how Build a Text-to-Image Generator (from Scratch) explains contrastive learning →

Outlier Detection in Python

A representation-learning technique that brings embeddings of similar items closer together and separates embeddings of dissimilar items.

How it is used
Uses learned embedding similarity as a self-supervised approach to tabular outlier detection.
How deep it goes
Defines the embedding objective and sketches ICL, but defers detailed implementation and training mechanics.
Examples
Uses altered images, tabular feature subsets, and KDD Cup records scored through DeepOD.
What you can do after
Apply it via DeepOD’s ICL estimator to fit tabular data and compute outlier scores.

Read how Outlier Detection in Python explains contrastive learning →

Also covered in

What to know first

Related concepts

Questions about contrastive learning

What is contrastive learning?

Contrastive learning is a representation-learning technique that trains a model to bring representations of related examples closer and separate representations of unrelated examples.

Which Manning books explain contrastive learning?

Retrieval Augmented Generation, The Foundational Ideas, Build a Text-to-Image Generator (from Scratch) and Outlier Detection in Python.

What should I know before learning contrastive learning?

Manning books that teach contrastive learning usually introduce embedding, computer vision, DALL-E and diffusion model first.

What kinds of contrastive learning are there?

Kinds of contrastive learning include ICL.

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.