arXiv:2509.01129cs.IR2025-09EMNLP被引 1

用解法相似性检索代码,提升编程竞赛难题生成效果

Beyond the Surface: A Solution-Aware Retrieval Model for Competition-level Code Generation

  • 基于逻辑等价生成新题目,训练模型识别深层解法相似性
  • 在xCodeEval上实现更高精确率与召回率,难题生成性能显著提升
  • 适合需要理解复杂逻辑的编程竞赛代码生成任务

在编程竞赛任务中,题目常嵌入复杂的叙事背景,需深入理解底层解法才能完成。当前代码生成模型主要关注词元级语义建模,易受无关叙述干扰。受RAG启发,检索具有相似解法的参考代码可能提升模型表现,但现有检索模型仍侧重表面语义相似性,忽视竞赛中至关重要的解法级逻辑相似性。为此,本文提出SolveRank——一种基于合成数据的解法感知排序模型。我们利用DeepSeek-R1生成逻辑等价但表述不同的新题目,并通过GPT-4o验证解法一致性;以这些为正样本,BM25或随机检索结果为负样本训练SolveRank。推理时,SolveRank从语料库中检索相关题目及对应代码,辅助下游代码生成器。在xCodeEval数据集上的实验表明,SolveRank在精度和召回率上优于现有顶尖排名方法,显著提升难题的代码生成性能。

原文摘要 · Abstract (English)

In competitive programming task, problem statements are often embedded within elaborate narrative backgrounds, requiring deep understanding of the underlying solutions to successfully complete the tasks. Current code generation models primarily focus on token-level semantic modeling, highly susceptible to distractions from irrelevant narrative statements. Inspired by RAG, retrieving reference code with similar solutions may help enhance model performance on difficult problems. However, existing retrieval models also emphasize surface-level semantic similarity, neglecting the deeper solution-level logical similarities that are critical in competitive programming. Therefore, designing ranking models capable of accurately identifying and retrieving problems and corresponding codes remains an urgent research problem in competitive code generation. In this paper, we propose SolveRank, a solution-aware ranking model empowered by synthetic data for competitive programming tasks. Specifically, we leverage the DeepSeek-R1 model to generate logically equivalent but differently phrased new problems, verified by GPT-4o for solution consistency. Then, we train SolveRank with these as positive samples and BM25/random-retrieved problems as negatives. During inference, SolveRank retrieves relevant problems and corresponding code from the corpus to assist a downstream code generator. Experiments on the xCodeEval dataset demonstrate that SolveRank outperforms SOTA ranking methods in precision and recall metrics, and boosts code generation performance for difficult problems.

代码生成竞赛编程检索增强解法相似

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。