Exploring Language Model's Code Generation Ability with Auxiliary Functions

Seonghyeon Lee, Sanghwan Jang, Seongbo Jang, Dongha Lee, Hwanjo Yu

Introduction: The "Helper Function" Gap

In modern software engineering, code is rarely written as a single monolithic block. Instead, developers rely on modularity, breaking complex tasks into reusable auxiliary functions. While Large Language Models (LLMs) have shown remarkable progress in code generation benchmarks like HumanEval, these evaluations typically focus on synthesizing isolated functions from scratch. This paper investigates a critical missing link: how effectively can LLMs utilize existing code context and auxiliary functions?

The HumanExtension Benchmark

To address this question, the authors introduced HumanExtension, a manually curated dataset of 151 problems. Derived from HumanEval, each problem in HumanExtension is restructured into a pair of functions: a target function and a corresponding auxiliary function that handles a specific subroutine. The dataset adheres to core software engineering principles, such as the Liskov substitution principle, to ensure realistic relationships between components.

Methodology: Prompting and Implementation Styles

The study evaluated several code-centric LLMs, including Incoder, CodeGen, StarCoder, and CodeLLaMA, using four prompting strategies:

  1. Direct: Baseline generation without auxiliary context.
  2. Irrelevant: Providing a non-functional helper to test noise robustness.
  3. Step-by-step: Requiring the model to generate its own helper before the target.
  4. Oracle: Providing the ground-truth human-written auxiliary function.

A key focus was the Implementation Style Analysis. The researchers distinguished between "Black-box extension" (calling the provided helper) and "White-box extension" (re-implementing the helper's logic inside the target). While humans prefer the maintainability of black-box calls, LLMs often default to redundant white-box re-implementations.

Key Results: The Power of Oracle Context

The inclusion of relevant auxiliary functions (Oracle) yielded significant performance gains across all models. As shown in the results table, models like Incoder 1B experienced a staggering 444.4% relative improvement in Pass@1 scores when provided with an Oracle helper.

Table 1: Pass@1 performance across different models and prompting strategies.

While instruction-tuned models like CodeLLaMA-Instruct-34B achieved the highest absolute baseline (0.4222), base models often demonstrated a superior ability to leverage the Oracle functions relative to their baseline performance. Furthermore, a strong correlation (>0.9) was found between a model's tendency to use black-box calls and its overall success rate, suggesting that delegation is a "safer" strategy for LLMs.

Analysis: Attention and Documentation

The researchers identified two critical factors influencing auxiliary function utilization:

  • Docstrings: Removing natural language documentation from helpers led to a massive performance drop, indicating that LLMs rely heavily on semantic descriptions rather than raw code analysis to understand function utility.
  • The U-Shaped Attention Curve: When multiple helpers were present, models were most effective at identifying the relevant one if it appeared at the beginning or end of the prompt. Information placed in the middle was frequently overlooked.
Figure 1: Pass@1 performance as a function of the relevant auxiliary function's position in the prompt.

Conclusion and Future Directions

The findings highlight a "copy-paste" habit in current LLMs that contradicts software engineering best practices. While providing context helps, models lack the "wisdom" to consistently delegate tasks to existing abstractions. Future work should focus on instruction-tuning methodologies that explicitly reward modularity and the use of existing codebases, moving AI toward acting as a seasoned software architect rather than a novice coder.

Summary updated

BibTeX
@inproceedings{lee2024exploring,
  author = {Seonghyeon Lee and Sanghwan Jang and Seongbo Jang and Dongha Lee and Hwanjo Yu},
  title = {{Exploring Language Model's Code Generation Ability with Auxiliary Functions}},
  booktitle = {Conference of the North American Chapter of the Association for Computational Linguistics},
  year = {2024},
  doi = {10.18653/v1/2024.findings-naacl.181},
}
Figure