Leveraging Metamemory Mechanisms for Enhanced Data-Free Code Generation in LLMs
Shuai Wang, Liang Ding, Yibing Zhan, Yong Luo, Zheng He, Dapeng Tao
TL;DR
This work addresses data-free code generation by introducing a metamemory-inspired framework, $M^{2}\text{WF}$, that enables LLMs to autonomously Recall relevant problems, Evaluate recall quality, Plan an implementation, and Guide the final Python3 solution for a given task. By generating and internally validating synthetic exemplars rather than relying on curated data, the method improves coding performance across both open-source and closed-source LLMs on benchmarks such as HumanEval, HumanEval+, and StudentEval. Extensive experiments show consistent gains over normal prompting and other baselines, demonstrating the approach's versatility, robustness, and applicability to multilingual coding tasks. The framework offers a scalable, data-free pathway to enhance software development workflows with LLMs, albeit with limitations related to API behavior, formatting constraints, and increased token usage.
Abstract
Automated code generation using large language models (LLMs) has gained attention due to its efficiency and adaptability. However, real-world coding tasks or benchmarks like HumanEval and StudentEval often lack dedicated training datasets, challenging existing few-shot prompting approaches that rely on reference examples. Inspired by human metamemory-a cognitive process involving recall and evaluation-we present a novel framework (namely M^2WF) for improving LLMs' one-time code generation. This approach enables LLMs to autonomously generate, evaluate, and utilize synthetic examples to enhance reliability and performance. Unlike prior methods, it minimizes dependency on curated data and adapts flexibly to various coding scenarios. Our experiments demonstrate significant improvements in coding benchmarks, offering a scalable and robust solution for data-free environments. The code and framework will be publicly available on GitHub and HuggingFace.
