arXiv:2505.01485cs.AIcs.CL2025-05中稿 · presentation at th…被引 2

让大模型零样本生成线性规划代码,只需自然语言描述

CHORUS: Zero-shot Hierarchical Retrieval and Orchestration for Generating Linear Programming Code

  • 用分层文本切块和代码元数据增强检索,提升上下文相关性
  • 在NL4Opt-Code上显著超越基线,使开源模型媲美GPT-4
  • 适合需要快速生成优化代码的非专家用户

线性规划(LP)问题需在约束条件下寻找最优解,通常要求领域知识、数学能力与编程技能,对非专家而言挑战较大。本文研究大语言模型(LLM)生成特定求解器代码的效率,提出CHORUS框架,从自然语言问题描述中合成基于Gurobi的LP代码。CHORUS采用树状分层文本切块策略处理理论内容,并基于文档中的代码示例生成额外元数据,以支持自包含、语义连贯的检索。通过两阶段检索结合交叉编码器重排序,确保上下文相关性。最后,精心设计的提示与结构化解析器配合推理步骤,显著提升代码生成性能。在NL4Opt-Code基准上的实验表明,CHORUS使Llama3.1 (8B)、Llama3.3 (70B)、Phi4 (14B)、Deepseek-r1 (32B) 和 Qwen2.5-coder (32B) 等开源模型性能大幅提升,超越传统RAG基线;且仅用极少计算资源即可达到或超过GPT3.5、GPT4表现。消融实验进一步验证了专家提示、分层切块与结构化推理的重要性。

原文摘要 · Abstract (English)

Linear Programming (LP) problems aim to find the optimal solution to an objective under constraints. These problems typically require domain knowledge, mathematical skills, and programming ability, presenting significant challenges for non-experts. This study explores the efficiency of Large Language Models (LLMs) in generating solver-specific LP code. We propose CHORUS, a retrieval-augmented generation (RAG) framework for synthesizing Gurobi-based LP code from natural language problem statements. CHORUS incorporates a hierarchical tree-like chunking strategy for theoretical contents and generates additional metadata based on code examples from documentation to facilitate self-contained, semantically coherent retrieval. Two-stage retrieval approach of CHORUS followed by cross-encoder reranking further ensures contextual relevance. Finally, expertly crafted prompt and structured parser with reasoning steps improve code generation performance significantly. Experiments on the NL4Opt-Code benchmark show that CHORUS improves the performance of open-source LLMs such as Llama3.1 (8B), Llama3.3 (70B), Phi4 (14B), Deepseek-r1 (32B), and Qwen2.5-coder (32B) by a significant margin compared to baseline and conventional RAG. It also allows these open-source LLMs to outperform or match the performance of much stronger baselines-GPT3.5 and GPT4 while requiring far fewer computational resources. Ablation studies further demonstrate the importance of expert prompting, hierarchical chunking, and structured reasoning.

代码生成线性规划RAG大模型

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