Research map / Label-efficient and robust learning / Recognition and long-tail
Uncertainty-Aware Contrastive Learning with Hard Negative Sampling for Code Search Tasks
Read the paperCheck your idea against 108,967 papers
AI-extracted summary. Written by AI from the paper's full text. Numbers and claims can be wrong or missing context, so check the paper before you cite or build on it.
Proposes uncertainty-aware contrastive learning (Gaussian reparameterized query/code embeddings) plus BM25-filtered hard negative sampling, initialized from CoCoSoDa, for code search on CodeSearchNet.
Problem
Code search with contrastive learning treats query and code embeddings as deterministic, although the same semantics can be expressed in diverse language styles; hard negatives are also underused.
Approach
Map query and code embeddings to Gaussian distributions (learned mean and variance) with reparameterization to produce diverse embeddings, add a KL regularizer, and construct hard negative query-code pairs by selecting similar queries and filtering false negatives with BM25.
Key results
- Achieves average MRR of 0.800 across six languages with hard negatives, versus 0.788 for CoCoSoDa and 0.785 for SEA.
- Ablation shows removing uncertainty-aware embedding or intra-modal contrastive learning causes considerable drops (e.g., Bi+sort+HN average 0.793 vs 0.800).
- Hard negative sampling adds gains over in-batch negatives alone (0.800 vs 0.796 average MRR).
Measured effects reported in the paper
| What was changed | Where | Measured | Effect |
|---|---|---|---|
| Add hard negative sampling to in-batch negatives (ablation) | Our code search method · CodeSearchNet AVG. | MRR: 0.796 -> 0.800 | Helped |
| Replace hard negative sampling with random sampling (ablation) | Our code search method · CodeSearchNet AVG. | MRR: 0.800 -> 0.796 | Hurt |
| Add unimodal contrastive learning (ablation) | Our code search method · CodeSearchNet AVG. | MRR: 0.793 -> 0.800 | Helped |
| Add candidate sorting (ablation) | Our code search method · CodeSearchNet AVG. | MRR: 0.794 -> 0.796 | Helped |
| Use uncertainty-aware embedding (ablation) | Our code search method · CodeSearchNet | MRR | Helped |
Surprising findings
- Alignment loss increases during training while uniformity improves, indicating a trade-off in which the model sacrifices some alignment for uniformity.
Limitations
- Baseline results are copied from previous papers rather than re-run under identical settings.
- Gains over CoCoSoDa are modest (about 1.2 MRR points on average).
Experimental setup
Datasets: CodeSearchNet CodeSearchNet expanded candidate set (Guo et al.)
Benchmarks: CodeSearchNet
Metrics: MRR R@1 R@5 R@10
Baselines: RoBERTa (code) CodeBERT GraphCodeBERT SynCoBERT UniXcoder CodeRetriever Soft-InfoNCE TOSS CoCoSoDa SEA
Builds on: CoCoSoDa UniXcoder InfoNCE BM25
Closest papers by meaning
- CODE REPRESENTATION LEARNING AT SCALE (ICLR 2024 · similarity 0.89)
- Towards A Generalist Code Embedding Model Based On Massive Data Synthesis (NeurIPS 2025 · similarity 0.87)
- CoRNStack: High-Quality Contrastive Data for Better Code Retrieval and Reranking (ICLR 2025 · similarity 0.86)
- Planning in Natural Language Improves LLM Search for Code Generation (ICLR 2025 · similarity 0.84)
- From Guessing to Placeholding: A Cost-Theoretic Framework for Uncertainty-Aware Code Completion (ICML 2026 · similarity 0.84)
- DyCodeEval: Dynamic Benchmarking of Reasoning Capabilities in Code Large Language Models Under Data Contamination (ICML 2025 · similarity 0.84)
Writing a paper in this area? scime draft is a free LaTeX editor with AI included, real-time co-authors and a check of your references and venue rules before you submit. It also imports OpenAI Prism projects.
