Skip to content

SOAR-Lab/llm-apr-knowledge-injection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hierarchical Knowledge Injection for Improving LLM-based Program Repair

This repository contains the full replication package for our paper on Hierarchical Knowledge Injection for Improving LLM-based Program Repair. It includes all code, datasets, prompts, and analysis scripts used in our experiments.


📁 Repository Structure

📄 Notebooks

File Description
main.ipynb Extracts and constructs contextual information for each bug across all three knowledge layers: Bug, Repository, and Project.
generate_prompts.ipynb Uses the extracted data to generate prompts for each bug under each knowledge layer.
run_patches.ipynb Executes the test suites for each generated patch to evaluate whether the bug is successfully fixed.
analysis.ipynb Performs all quantitative and qualitative analysis, including fix rates, Pass@k metrics, and error breakdowns, as reported in the paper.

All notebooks include detailed markdown explanations to facilitate reproducibility and understanding.


📂 Folders

bug-data/

Contains the full dataset of bugs organized by project and bug ID. Each bug has layer-specific data and outputs.

Example structure:

bug-data/
├── pandas/
│   ├── 1/
│   │   ├── prompts
│   │   ├── patches
│   │   └── extracted_data.json
│   ├── 2/
│   │   ├── ...
...

Each bug folder includes:

  • prompts: The generated prompts for different knowledge layers (.md files)
  • patches: Model-generated patches
  • extracted_data.json: Extracted contextual information used for prompt construction

data/

Contains processed CSV files used for analysis and annotation.

File Description
annotated_dataset.csv Manually annotated bug types (e.g., GUI, Network, Program Anomaly)
annotated_dataset_with_bug_level_results.csv Fix outcomes for GPT-4o-mini using bug-level context
annotated_dataset_with_bug_level_results_llama.csv Fix outcomes for LLaMA 3.3 using bug-level context
annotated_dataset_with_repository_level_results_gpt.csv Fix outcomes for GPT-4o-mini using repository-level context
annotated_dataset_with_repository_level_results_llama.csv Fix outcomes for LLaMA 3.3 using repository-level context
annotated_dataset_with_project_level_results_gpt.csv Fix outcomes for GPT-4o-mini using project-level context
annotated_dataset_with_project_level_results_llama.csv Fix outcomes for LLaMA 3.3 using project-level context
annotated_dataset_with_all_levels_results_gpt.csv Fix outcomes for GPT-4o-mini using all-levels context at the same time
annotated_dataset_with_all_levels_results_llama.csv Fix outcomes for LLaMA 3.3 using all-levels context at the same time
calculated_complexity_metrics.csv Cyclomatic complexity, LOC, Halstead metrics, and maintainability for all buggy functions

📦 Requirements

Install the required packages:

langchain
jedi
sentence_transformers
scikit-learn
transformers
torch
numpy
pandas

🚀 Running the Replication

  1. Extract context using main.ipynb for each bug. (You can skip since the information is already extracted for each bug)
  2. Generate prompts with generate_prompts.ipynb. (You can skip since prompts are already generated for each bug)
  3. Run model and evaluate patches using run_patches.ipynb.
  4. Analyze results and reproduce the figures and tables in the paper with analysis.ipynb.

Each step is modular and well-commented to support custom extensions or ablations.


📊 Projects in Our Dataset

The following table summarizes the characteristics of the 16 open-source Python projects included in our dataset: These projects vary in size and popularity, ranging from 16k to 135k stars on GitHub, and include diverse bug types such as Program Anomaly, GUI, and Network.

Project Summary


🧠 Prompting: Chain-of-Thought

We use a structured chain-of-thought prompt to guide LLMs step-by-step through analyzing and repairing each buggy function. This format encourages the model to first understand the bug and its context before generating a fix.

As an example, the general structure is illustrated below for the Bug Knowledge Layer:

Chain-of-Thought Prompt

About

Replication package for “Hierarchical Knowledge Injection for Improving LLM-based Program Repair”, published in Automated Software Engineering (ASE) 2025

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors