Why is hard negative mining important for contrastive learning objectives?

Quick Overview

Asks why contrastive learning benefits from hard negatives and what can go wrong when you mine them. Tests understanding of the InfoNCE gradient, practical ways to find hard negatives, and the false-negative and stability risks that come with them.

Why is hard negative mining important for contrastive learning objectives?

Role: Machine Learning Engineer

Category: Machine Learning

Difficulty: medium

Interview Round: Other

Contrastive objectives such as InfoNCE train an encoder to pull an anchor toward its positive and push it away from negatives. Why is hard negative mining important for these objectives, and what can go wrong when you use it? ```hint Look at the gradient Write the gradient of the InfoNCE loss with respect to one negative's similarity score, and see how it depends on how close that negative already sits to the anchor. ``` ### What a Strong Answer Covers - What makes a negative hard, and how its gradient compares with an easy negative's under a softmax contrastive loss - What the model learns from hard negatives that random negatives do not teach, with a concrete case such as dense retrieval - Practical ways to obtain hard negatives, including batch size, memory queues, explicit mining and temperature - The risks of false negatives and early instability, and how to reduce them ### Follow-up Questions - How does the temperature in InfoNCE change which negatives dominate the gradient? - In dense retrieval, how would you detect and filter false negatives among BM25-mined or ANN-mined candidates? - Why does ANCE refresh its ANN index during training, and what goes wrong if the mined negatives are stale? - How does semi-hard mining in a triplet loss differ from always taking the hardest negative in the batch?

Overview: Asks why contrastive learning benefits from hard negatives and what can go wrong when you mine them. Tests understanding of the InfoNCE gradient, practical ways to find hard negatives, and the false-negative and stability risks that come with them.

General logo
General
Nov 25, 2026
mediumMachine Learning EngineerOtherMachine Learning
0
0

Contrastive objectives such as InfoNCE train an encoder to pull an anchor toward its positive and push it away from negatives. Why is hard negative mining important for these objectives, and what can go wrong when you use it?

What a Strong Answer Covers Guidance

  • What makes a negative hard, and how its gradient compares with an easy negative's under a softmax contrastive loss
  • What the model learns from hard negatives that random negatives do not teach, with a concrete case such as dense retrieval
  • Practical ways to obtain hard negatives, including batch size, memory queues, explicit mining and temperature
  • The risks of false negatives and early instability, and how to reduce them

Follow-up Questions Guidance

  • How does the temperature in InfoNCE change which negatives dominate the gradient?
  • In dense retrieval, how would you detect and filter false negatives among BM25-mined or ANN-mined candidates?
  • Why does ANCE refresh its ANN index during training, and what goes wrong if the mined negatives are stale?
  • How does semi-hard mining in a triplet loss differ from always taking the hardest negative in the batch?