用伪代码注入让大模型高效解图算法题,准确率高还省钱
Pseudocode-Injection Magic: Enabling LLMs to Tackle Graph Computational Tasks
- 通过伪代码注入引导大模型理解图任务并生成代码
- 在多个数据集上准确率达90%以上,推理成本降低70%以上
- 适合想用大模型做图算法开发的研究者和工程师
图计算任务本质上复杂,常需设计高级算法。随着大语言模型(LLMs)的兴起,研究者开始探索其解决此类问题的潜力。然而,现有方法受限于大模型对复杂图结构的理解能力以及高昂的推理成本,难以处理大规模图数据。受人类解图题方式启发,我们提出PIE框架——一种基于伪代码注入的大模型图计算推理增强方法,包含问题理解、提示设计与代码生成三步。该框架中,大模型负责理解问题并提取信息生成代码,而图结构分析与代码执行由解释器完成。通过在提示中注入任务相关的伪代码,进一步提升代码生成效率。同时采用低成本试错策略确保生成代码正确执行。不同于其他方法需为每个测试用例调用大模型,PIE仅在代码生成阶段调用一次,生成代码可重复使用,显著降低推理开销。大量实验表明,PIE在准确率与计算效率方面均优于现有基线方法。
原文摘要 · Abstract (English)
Graph computational tasks are inherently challenging and often demand the development of advanced algorithms for effective solutions. With the emergence of large language models (LLMs), researchers have begun investigating their potential to address these tasks. However, existing approaches are constrained by LLMs' limited capability to comprehend complex graph structures and their high inference costs, rendering them impractical for handling large-scale graphs. Inspired by human approaches to graph problems, we introduce a novel framework, PIE (Pseudocode-Injection-Enhanced LLM Reasoning for Graph Computational Tasks), which consists of three key steps: problem understanding, prompt design, and code generation. In this framework, LLMs are tasked with understanding the problem and extracting relevant information to generate correct code. The responsibility for analyzing the graph structure and executing the code is delegated to the interpreter. We inject task-related pseudocodes into the prompts to further assist the LLMs in generating efficient code. We also employ cost-effective trial-and-error techniques to ensure that the LLM-generated code executes correctly. Unlike other methods that require invoking LLMs for each individual test case, PIE only calls the LLM during the code generation phase, allowing the generated code to be reused and significantly reducing inference costs. Extensive experiments demonstrate that PIE outperforms existing baselines in terms of both accuracy and computational efficiency.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。