In-Context Code-Text Learning for Bimodal Software Engineering

Xunzhu Tang, Liran Wang, Yonghui Liu, Linzheng Chai, Jian Yang, Zhoujun Li, Haoye Tian, Jacques Klein, Tegawendé F. BissyandéarXiv 2024 · DOI

Abstract

The INCTRL (In-Context Code-Text Learning) framework introduces a unified, structured approach to teaching Large Language Models (LLMs) how to handle diverse software engineering tasks without the need for expensive fine-tuning. By leveraging a sophisticated 6-part prompt template and Retrieval-Augmented Generation (RAG), INCTRL significantly boosts the performance of models like CodeLLAMA across 23 different datasets, turning them from mediocre performers into state-of-the-art contenders for tasks ranging from code generation to vulnerability detection.

Introduction

Software engineering is inherently "bimodal"—it requires a deep understanding of both formal algorithmic logic (code) and informal natural language (comments, documentation, bug reports). While Large Language Models (LLMs) have shown promise in both domains, they often struggle to bridge the gap between them across a wide variety of tasks.

Current solutions usually fall into two camps: multitask learning, which tries to force everything into a single format but often misses nuances, and task-specific fine-tuning, which is computationally expensive and creates models that are "one-trick ponies." Furthermore, standard In-Context Learning (ICL)—where you simply give the model a few examples—often fails on complex classification tasks like identifying code clones or vulnerabilities because the model lacks sufficient context to understand the "decision boundary."

Methodology

The authors propose INCTRL, a pipeline designed to "activate" the latent knowledge within pre-trained code models through structured prompting.

The INCTRL framework architecture, illustrating the flow from task configuration to the final response generation using a structured prompt and RAG module.

The core components include:

  1. Unified Code-Text Interface: A task-agnostic interface that handles three types of outputs: Class (binary/category), Code (generation/translation), and Text (summarization).
  2. Configurable Prompt Template: Instead of a simple "instruction + input" prompt, INCTRL uses a six-section structure: Introduction, Definition, Pre-instruction, Demonstration (few-shot examples), Post-instruction, and the final Question.
  3. RAG Module: For classification tasks, INCTRL uses a Retrieval-Augmented Generation module. It uses CodeBERT to create semantic embeddings of the code, allowing the system to find and include the most relevant examples from the training set as demonstrations in the prompt, rather than just choosing them at random.

Experimental Setup

The study evaluates INCTRL across 23 datasets covering seven major software engineering tasks:

  • Vulnerability Detection: Big-Vul, Draper, D2A, ReVeal, Devign.
  • Clone Detection: BigCloneBench.
  • Code Completion: InstructHumanEval, Safim.
  • Code Translation: CodeXGLUE, HumanEval-X.
  • Program Repair: CodeXGLUE, HumanEvalPack.
  • Code Summarization: CodeXGLUE, XLCoST, Funcom.
  • Code Generation: APPS, MBPP, Mercury, StudentEval, and others.

Results and Discussion

The improvements brought by INCTRL over the baseline CodeLLAMA models were substantial across all metrics.

Performance comparison of CodeLLAMA models with and without the INCTRL framework across various code-output, text-output, and class-output tasks.

Key findings include:

  • Structure is the "Key" to the Engine: The specific 6-part structure of the prompt is what truly unlocks the model's performance. Even "Instruct" versions of models saw massive gains with the INCTRL template.
  • Classification Needs Relevance: While generation tasks can work with random examples, classification tasks (like clone detection) are much more sensitive. The RAG module proved essential here; by providing examples that were semantically similar to the query, the model could better understand the specific patterns it needed to look for.
  • Bypassing the Fine-Tuning Tax: INCTRL demonstrates that for many SE tasks, a well-engineered "contextual environment" can make a general-purpose model perform as well as, or better than, specialized ones.

Quantitatively, the framework achieved a 69 percentage point improvement in F1-score for clone detection. On the CodeXGLUE program repair task, INCTRL improved the BLEU score of CodeLLAMA-7b from 1.43 to 86.34. Across all tasks, precision improved by at least 12% and recall by up to 93.88%.

Conclusion

While INCTRL avoids the cost of training, the RAG module and the long, structured prompts increase the "inference-time" cost. Retrieving examples and processing longer input sequences takes more time and memory. Future work will explore the cost-benefit trade-off between INCTRL and task-specific fine-tuning more deeply, as well as testing the framework's robustness against adversarial or "noisy" code inputs.

Summary updated

BibTeX
@misc{tang2024context,
  author = {Xunzhu Tang and Liran Wang and Yonghui Liu and Linzheng Chai and Jian Yang and Zhoujun Li and Haoye Tian and Jacques Klein and Tegawendé F. Bissyandé},
  title = {{In-Context Code-Text Learning for Bimodal Software Engineering}},
  year = {2024},
  eprint = {2410.18107},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2410.18107},
}
Figure