← Uber Interview Insights

Uber·Machine Learning Engineer·Technical Phone Screen·Senior

Senior
May 2026

Summary

Uber ML engineer screen with one meaty coding question around implementing CLIP-style contrastive loss from scratch. Pretty focused session, no fluff.

Questions Asked (1)

Q1

Given a batch of image and text embeddings, implement the contrastive loss used in CLIP. The expected formulation averages cross-entropy loss computed over the similarity matrix from both the image and text directions.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

I knew the general idea of contrastive learning but fumbled a bit on the symmetry part.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the input shapes and expected output, then describe the symmetric contrastive loss: compute the similarity matrix between image and text embeddings, apply cross-entropy loss in both directions (image-to-text and text-to-image), and average them. Finally, discuss implementation details like normalization, temperature scaling, and numerical stability.

Pro tip: Mention that you would use log-softmax for numerical stability and that the loss is symmetric, which is crucial for CLIP's performance. Also, note that temperature is a learnable parameter in CLIP, but if not specified, you can assume a fixed value.

1. Clarify inputs and outputs

Confirm the shapes of image and text embeddings (e.g., batch_size x embedding_dim) and that the loss should be a scalar. Ask if temperature scaling is used and if embeddings are normalized.

2. Compute similarity matrix

Normalize embeddings if needed, then compute the dot product between image and text embeddings to get a batch_size x batch_size similarity matrix.

3. Compute contrastive loss in both directions

Apply cross-entropy loss with the correct labels: for image-to-text, the labels are the diagonal indices; for text-to-image, also the diagonal. Use log-softmax for stability.

4. Average the losses

Take the mean of the two cross-entropy losses to get the final contrastive loss.

5. Discuss implementation details and trade-offs

Mention temperature scaling, normalization, numerical stability (e.g., subtracting max logit), and potential for distributed training where the similarity matrix is computed across devices.

Key Points to Mention

  • Symmetric loss: average of image-to-text and text-to-image cross-entropy
  • Similarity matrix computation: dot product of normalized embeddings
  • Temperature scaling: learnable parameter in CLIP, controls softmax sharpness
  • Numerical stability: use log-softmax and subtract max logit
  • Label construction: diagonal elements are positives, off-diagonal are negatives
  • Batch size considerations: large batch sizes improve contrastive learning

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.