arXiv:2510.13163cs.CL2025-10

用图结构表示代码,让大模型一次生成抽象程序

A Matter of Representation: Towards Graph-Based Abstract Code Generation

  • 用JSON定义代码图节点与边,实现抽象代码生成
  • 在ScratchTest上准确率超70%,单次生成即有效
  • 首次证明表示方式直接影响生成效果,适合编程教育研究者

当前大语言模型擅长生成顺序化原始代码,但缺乏对基于图的抽象代码生成的研究。此类生成将核心逻辑封装在预定义节点中,执行流程由边决定,适用于可视化编程语言及无法访问源码的场景。本文提出并评估了用于图结构代码生成的JSON表示方法,在自研的Python版Scratch基础上构建的ScratchTest小规模基准上进行测试。实验表明,只要使用合适的图表示,大模型可在单次生成中完成任务,无需复杂流水线。不同表示方式导致显著不同的准确率,凸显表示设计的关键作用。本工作为图式抽象代码生成的表示学习迈出第一步。

原文摘要 · Abstract (English)

Most large language models (LLMs) today excel at generating raw, sequential code with minimal abstractions and custom structures. However, there has been little work on graph-based abstract code generation, where significant logic is encapsulated in predefined nodes and execution flow is determined by edges. This is relevant for visual programming languages, and in cases where raw source code is inaccessible to users and LLM training sets. In this work, we propose and evaluate JSON representations for graphs to enable high accuracy graph-based abstract code generation. We evaluate these representations on ScratchTest, a mini-benchmark based on our custom Python re-implementation of Scratch, which tests the LLM in code graph space. Our findings demonstrate that LLMs can indeed perform the aforementioned generation task in a single pass without relying on specialized or complex pipelines, given the correct graph representations. We also show that different representations induce significantly different accuracies, highlighting the instrumental role of representations in this generation task. All in all, this work establishes the first steps towards representation learning for graph-based abstract code generation.

代码生成图神经网络编程教育LLM

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