NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Code Generation From Flowcharts with Texts: A Benchmark Dataset and An Approach

Zejie Liu, Xiaoyu Hu, Deyu Zhou, Lin Li, Xu Zhang, Yanzheng XiangEMNLP 2022

Introduction

Generating executable code from high-level requirements is a significant challenge in software engineering. While traditional text-to-code models have made progress, they often struggle with complex logic and non-linear execution paths. Researchers have proposed that flowcharts, which visualize logic through nodes and edges, serve as a more effective intermediate representation for complex programming tasks by capturing the "algorithmic soul" of a solution.

An example of a flowchart mapped to Python code for the 'twoSum' algorithm, illustrating the core task of converting visual logic into code.

The FC2Code Benchmark

To facilitate research in this area, the authors introduced FC2Code, a new benchmark dataset. It consists of 320 code samples extracted from the LeetCode platform. These samples were processed to create flowchart sketches, which were then manually annotated with natural language descriptions. Unlike previous datasets where pseudo-code lines were often independent, FC2Code emphasizes the relationship between nodes; approximately 62% of nodes are explicitly linked to others, requiring models to maintain deep contextual awareness to resolve variable references across different blocks.

Methodology: A Two-Stage Approach

The core contribution of this work is a two-stage framework designed to handle the structural and semantic nuances of flowcharts by treating them as graphs rather than sequential text.

The proposed two-stage architecture: Structure Recognition followed by a Graph-based Code Generation Model.

Stage 1: Structure Recognition

The first stage employs a rule-based model to analyze the flowchart's topology. It identifies fundamental programming constructs such as loops (while) and selections (if). This process transforms the visual graph into a "pseudo-code" skeleton, aligning the flowchart's logic with the formal execution order and structural conventions of programming languages.

Stage 2: Graph-Aware Code Generation

The second stage converts the pseudo-code into final Python code using a structure-aware neural architecture:

  • Graph Attention Networks (GAT): By treating the flowchart as a graph, the model uses GAT to allow nodes to "attend" to their neighbors. This helps resolve ambiguous references (like "it" or "the array") by pulling information from previously visited nodes.
  • Directional Encoding: The model processes the flowchart in both forward and reverse directions, ensuring that each node perceives both its data sources and its intended destination in the execution flow.
  • TranX Decoder: A transition-based neural abstract syntax parser (TranX) is used to generate the final code, ensuring strict adherence to Python's formal syntax.

Key Insights and Results

Analysis of the flowchart structures revealed that most variable relationships occur within 1 or 2 steps, justifying the use of a local "window" in the Graph Attention Network. By forcing the model to follow the flowchart's edges, the researchers significantly reduced the search space for the model, leading to more accurate variable tracking.

In performance evaluations, the proposed model achieved a 55.68 BLEU score, significantly outperforming standard Transformers (44.05 BLEU) and LSTMs (38.25 BLEU). Ablation studies confirmed that the graph-based neighbor information was vital, as removing it caused the score to drop to 51.53.

Conclusion and Future Work

While the FC2Code dataset is currently small, it provides a rigorous testbed for structure-aware code generation. Future work will focus on expanding the dataset size, potentially using Large Language Models (LLMs) for automated annotation, and extending the model to handle multi-function programs and complex class-based structures.

Summary updated

BibTeX
@inproceedings{liu2022code,
  author = {Zejie Liu and Xiaoyu Hu and Deyu Zhou and Lin Li and Xu Zhang and Yanzheng Xiang},
  title = {{Code Generation From Flowcharts with Texts: A Benchmark Dataset and An Approach}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2022},
  doi = {10.18653/v1/2022.findings-emnlp.449},
}
Figure