Reproduce “CoSQA: 20,000+ Web Queries for Code Search and Question Answering” on OpenResearch

Run Claude Code, Codex or any coding agent as a research agent: literature, hypotheses and experiments on your laptop, cluster or cloud GPUs.

Universal app for Apple silicon and Intel. Requires macOS 11 or later.

About this paper

Junjie Huang, Duyu Tang, Linjun Shou, Ming Gong, Ke Xu, Daxin Jiang, Ming Zhou, Nan Duan

This work from Beihang University, Microsoft Research Asia, and Microsoft STC Asia introduces CoSQA, a dataset of over 20,000 human-annotated real web queries paired with Python functions, alongside CoCLR, a novel contrastive learning method. The approach significantly improves natural language code search and question answering, achieving 63.38% accuracy for code QA and 64.66% MRR for code search, setting new benchmarks for real-world query-code matching.

Key insights

  • Real web queries captured in CoSQA are crucial for training models that accurately reflect practical user search behaviors, leading to better performance than models trained on pseudo queries.
  • Contrastive learning, specifically in-batch augmentation and query-rewritten augmentation, provides a highly effective strategy to enhance query-code semantic matching, even with a strong base model like CodeBERT.
  • Natural language documentation accompanying code functions plays a vital role in query-code matching, contributing significantly more to performance than the function body or header alone.

Summary by alphaXiv.

Tip: change arxiv.org to autoarxiv.org in any arXiv abstract link to open the paper here.