TensoriumInterview preparation
← Home

Core concepts · 62 topics

A guided path through the ideas behind modern LLMs.

Read the stages in order: how text becomes a prediction, what happens inside the Transformer block, how a model learns, then serving, scale, and post-training. Every topic names what to know first, then gives the intuition, the math with concrete numbers, the common misconception, and a self-check. Already comfortable with the basics? Switch to By area and jump straight to a topic.

New to machine learning? Start here instead.

These topics work best as a refresher; they assume ideas like probability and loss. Begin with three short beginner lessons (tokens, embeddings, next-token prediction), then the visual walkthrough for attention and the Transformer.

Finish line: You can explain how text becomes a prediction and what training does to improve that prediction.

Topic 57 of 62 · Wider ML toolkit

Contrastive loss (InfoNCE)

Medium

How does the InfoNCE / NT-Xent contrastive loss work, and what roles do positives, negatives, and temperature play?

Practice choosing loss functions · 10 scenarios ↓
Why this mattersContrastive objectives (InfoNCE) power modern text and multimodal embedding models; their quality hinges on batch negatives, temperature, and avoiding false negatives.

1 · Start with the intuition

Contrastive learning trains an encoder to map related items (a positive pair, such as a search query and a relevant document, or two augmented views of the same image) close together on the unit hypersphere while pushing unrelated items (negatives) apart. InfoNCE frames this as a multi-class classification problem over the batch: given an anchor embedding zᵢ, treat its positive partner zⱼ as the correct class and all other candidates in the pool as competing wrong classes, then apply cross-entropy to their temperature-scaled cosine similarities.

2 · How the mechanism works

Mechanism step 1 of 3 · no question to answer

Encode (and usually L2-normalize)

Map queries/anchors and candidates to vectors. Retrieval and SimCLR-style setups usually L2-normalize them so the dot product is cosine similarity; InfoNCE itself allows any score function.

Next, we will look at: Scale by temperature τ. Move on when this operation makes sense.

Visualizing the behavior

Cosine similarities for 2 images × 2 views (positives outlined)

Illustrative
Cosine similarities for 2 images × 2 views (positives outlined)
anchor ↓ · candidate →1a1b2a2b
1aself0.80.20
1b0.8self0.10.3
2a0.20.1self0.7
2b00.30.7self
Each row is a (2N − 1)-way classification: find your other view among every candidate except yourself. The diagonal is excluded, and the off-diagonal cells that are not outlined are negatives.

Anchor 1a, scores [0.8 positive, 0.2, 0.0]: effect of temperature

Derived

p(positive) = softmax(s / τ)

τ = 1.0
0.500
τ = 0.5
0.665
τ = 0.2
0.936
τ = 0.1
0.997
Lower temperature sharpens the softmax. The loss then focuses on the hardest negatives and saturates on easy ones; if τ is too low, training can become unstable or overreact to false negatives.