This is an IntvML Pro interview question. Upgrade to Pro to unlock the full prompt, diagrams, and solution.
Tag: Data Eng
DL0149 World Models from Unlabeled Video
This is an IntvML Pro interview question. Upgrade to Pro to unlock the full prompt, diagrams, and solution.
DL0147 Multi-Task VLA Negative Transfer
This is an IntvML Pro interview question. Upgrade to Pro to unlock the full prompt, diagrams, and solution.
DL0126 Contrastive Learning Pairs
What is contrastive learning, and what are positive and negative pairs?

The Problem: A retail search team has 2,000,000 unlabeled product photos and only 800 labeled ones. A teammate proposes contrastive pretraining for the image encoder ahead of the similar-items launch. No one on the team can yet say what the method optimizes, or which photo pairs it should treat as alike and which as different.
Answer
Contrastive learning trains an encoder by comparison instead of by prediction of a label: it pulls the embeddings of things that should mean the same thing together and pushes everything else apart. A positive pair is two views of the same underlying content (two augmentations of one photo in SimCLR, an image and its caption in CLIP, two nearby audio segments in CPC), and a negative pair is an anchor paired with content assumed to be different (any other item in the batch). The standard objective, InfoNCE, turns this into a softmax classification problem: given an anchor, identify its single positive among one positive and
negatives, using scaled cosine similarity as the logit. Positives define what the representation should be invariant to, and negatives are what prevents the trivial solution where the encoder maps every input to the same vector, a failure called representational collapse. The whole design problem of a contrastive system is therefore the pair-construction policy: a positive that is too easy teaches nothing, and a negative that is secretly a positive actively teaches the wrong thing.
(1) Positives Encode The Invariance You Want: whatever transformation you apply to build a positive pair is exactly the factor the encoder learns to discard, so color jitter buys color invariance and destroys any task where color is the signal.
(2) Negatives Are The Anti-Collapse Term: without a repulsive term the constant mapis a global minimum of the attraction loss, so negatives provide the uniformity pressure that spreads embeddings over the hypersphere.
(3) InfoNCE Is A-Way Classification: one positive logit in the numerator, the positive plus all negatives in the denominator, which is why the loss is bounded below by
under a random encoder.
(4) Temperature Sets Hard-Negative Focus: small(0.05 to 0.1 is typical) concentrates almost all repulsive gradient on the few most similar negatives, while large
treats all negatives nearly equally.
(5) Negative Count Is A Systems Problem: SimCLR needs batch sizes of 4096 or more to get enough in-batch negatives, MoCo decouples them with a momentum-encoder queue, and CLIP trained with a 32768 global batch across many GPUs.
(6) False Negatives Are The Main Bias: in-batch negatives assume every other sample is semantically different, which is false on class-imbalanced or deduplicated-poorly data, and the loss then pushes apart items that should be close.Pairs do not have to come from augmentation. The general recipe is: find a cheap source of known agreement and treat everything else as disagreement. Augmentation gives agreement between two crops of one image; multimodal alignment gives agreement between an image and the alt-text scraped alongside it; temporal or spatial context gives agreement between adjacent frames, patches, or sentences; and labels give agreement between any two samples of the same class, which is what SupCon exploits to allow many positives per anchor. The negatives are almost always just the rest of the batch, because sampling them explicitly is expensive and in-batch negatives come for free with the forward pass already computed.

Figure 1: Pair construction and its geometric effect. Each anchor has exactly one positive (the other view of the same source) and
negatives (all views of the other images in the batch); on the unit hypersphere the loss is a single attractive force toward the positive balanced against repulsive forces from every negative.
Mathematical Formulation:
Where:
is the cosine similarity used as the logit, computed on L2-normalized embeddings
produced by the encoder (and, in SimCLR, a discarded projection head).
is the per-anchor NT-Xent loss and
its average over all
views of an
-image batch.
indexes the anchor view,
its unique positive, and
ranges over every other view, so the denominator holds 1 positive and
negatives.
is the temperature; the gradient weight on negative
is its softmax probability, so shrinking
sharpens that distribution onto the hardest negatives.
is the mutual information between the two views and
the number of negatives, giving the standard InfoNCE lower bound: the bound saturates at
, which is one reason large batches help.

Figure 2: Temperature decides which negatives matter. At
the hardest 1% of negatives absorbs most of the repulsive gradient, making training an implicit hard-negative miner that is also maximally sensitive to false negatives; at
the pressure is spread nearly uniformly and the embedding space stays smoother but less discriminative.
Aspect Augmentation (SimCLR, MoCo) Multimodal (CLIP, ALIGN) Supervised (SupCon) Anchor One augmented view of an image An image embedding A labeled sample Positive A second augmentation of the same image (exactly one) The paired caption text (exactly one, symmetric loss both directions) Every other sample sharing the label (many per anchor) Negatives All 2N-2 other views, or a momentum queue of 65k stale keys All other captions in the global batch (32k in CLIP) Only samples with a different label, so false negatives vanish Invariance learned To the augmentation family you chose (crop, color, blur) To modality and phrasing, giving a shared image-text space To everything within a class, which can over-collapse fine detail Main failure mode Augmentation removes task-relevant signal; shortcut solutions from crop statistics Noisy or generic captions produce weak positives; batch size dominates cost Needs labels, so it is not self-supervised and inherits label noise Login to view more contentDL0095 Zero-Shot vs Few-Shot
How do zero-shot and few-shot prompting differ, and when does few-shot prompting beat fine-tuning?

The Problem: A support team must tag incoming tickets into a strict JSON schema (queue, urgency) using one frozen base model that already serves four other tasks. They have only 40 labeled tickets and a schema that is revised every week, and they must choose among an instruction-only prompt, a prompt with a few solved tickets, and a LoRA fine-tune.
Answer
Both are inference-time conditioning: the weights
never change, only the tokens placed before the query. Zero-shot prompting gives an instruction and the input, so the model must map the task description onto a behavior it already learned during pretraining or instruction tuning. Few-shot prompting (in-context learning) prepends
solved demonstrations
that pin down the output format, the label space, and the input distribution before the real query arrives, which is why it helps most on tasks with an unusual schema or a strict output contract. In the original GPT-3 study, TriviaQA accuracy for the 175B model moved 64.3% → 71.2% going from zero-shot to 64-shot, and the gap between the two settings shrinks as models get better instruction tuning. Few-shot prompting beats fine-tuning when labeled data is scarce (roughly tens of examples), the task spec is still changing weekly, one frozen base must serve many tasks, or no training infrastructure exists; fine-tuning wins once you have thousands of clean labels, need the lowest possible per-request cost and latency, or need behavior that no prompt reliably elicits. The decision is mostly economics plus label count, not model quality: demonstrations are paid for on every request, while a fine-tune is a one-time cost amortized over traffic.
(1) Same Weights, Different Context: neither method computes a gradient; few-shot differs from zero-shot only by the demonstration block
inserted into the prompt.
(2) Demonstrations Teach Format, Not Mostly Facts: the label space, input distribution, and output template drive most of the gain, which is why even partly incorrect labels in the exemplars often still work.
(3) Cost Is Recurring:exemplars add
prefill tokens per call, inflating time-to-first-token and input spend on every request forever.
(4) Fine-Tuning Trades Setup For Marginal Cost: a LoRA run costs money once and then serves a short prompt, so it wins above a traffic break-even point.
(5) Data Volume Decides The Ceiling: with a handful of labels in-context learning is usually ahead; with thousands, parameter updates reach accuracy no prompt matches.The mechanism is worth stating precisely because it predicts the failure modes. Demonstrations act as a task locator rather than a training set: replacing gold labels with random ones from the correct label set degrades few-shot accuracy far less than removing the labels entirely, which shows the exemplars are mostly specifying which distribution to condition on. That same conditioning creates strong biases: majority-label bias (a class over-represented in the exemplars gets over-predicted), recency bias (the last exemplar dominates), and ordering sensitivity that can swing accuracy by tens of points across permutations of the same
examples. Calibration on a content-free input and stratified, order-shuffled exemplar selection recover most of that variance, and any prompt tuned on a large validation set is no longer honestly “few-shot” because the selection itself consumed labels.

Figure 1: Illustrative shot-scaling behavior: most of the in-context gain arrives by
and flattens after
, a model fine-tuned on only 100 labels sits near the few-shot curve, and 5,000 labels put the fine-tuned small model above the frozen large model.
Mathematical Formulation:
Where:
is the generated answer,
the query, and
the instruction text; the first two lines are the zero-shot and few-shot predictive distributions under identical
.
is the demonstration block and
the shot count, with
recovering the zero-shot case exactly.
,
, and
are token lengths of the instruction, one exemplar, and the query;
is the prefill length that sets time-to-first-token.
- The numeric line instantiates
for
exemplars of 60 tokens each, giving 1,990 prompt tokens against 70 for the zero-shot prompt.
is the price per input token,
the one-time fine-tuning cost, and
the break-even request volume above which the fine-tune is cheaper; it assumes both options serve the same output length and per-token price.
Plugging in real numbers makes the trade-off concrete. At
per million input tokens, the 1,920 extra tokens from 32 exemplars cost about
per request, so a
LoRA job pays for itself after roughly 104,000 requests. Prompt caching changes that arithmetic sharply: because the exemplar block is a fixed prefix, cached reads billed near 10% of the input rate push the break-even beyond a million requests and also cut the prefill latency penalty. That is why the honest answer to “few-shot or fine-tune” depends on traffic volume, prefix stability, and whether your serving stack caches, not on which technique sounds more advanced.

Figure 2: Illustrative cost crossover: the few-shot line grows linearly with traffic because the exemplar prefix is re-billed per call, the fine-tune is a flat one-time charge, and prompt caching flattens the few-shot slope by roughly an order of magnitude.
Property Zero-shot Few-shot (in-context) Fine-tuning (LoRA) Labeled examples needed None, only a clear instruction Typically 4 to 64, plus a small set for prompt selection Hundreds to tens of thousands Where task knowledge lives Pretraining and instruction tuning only In the prompt, re-sent or cached per request In adapter weights, prompt stays short Prompt tokens per request 70 in the worked example 1,990 at K=32, so higher time-to-first-token 70, same as zero-shot Iteration speed Seconds, edit the instruction Seconds, swap or reorder exemplars Hours per run plus eval and deploy Main failure mode Wrong output schema, task misread Majority-label and recency bias, ordering variance, context limits Overfits small or noisy label sets, forgets off-task behavior Multi-task serving One model, one endpoint One model, per-task prompt template One adapter per task over a frozen base Login to view more content











