|
| 1 | +CuREV: Curating Review Comments for Improved Code Review Automation |
| 2 | +=============================== |
| 3 | +This is the replication package accompanying our paper, *Curating Review Comments for Improved Code Review Automation*. |
| 4 | + |
| 5 | +The datasets of this paper are available on [Zenodo](https://zenodo.org/records/14058666). |
| 6 | + |
| 7 | +Overview |
| 8 | +--- |
| 9 | +We propose a methodology to curate a code reviews dataset to enhance its quality and improve the performance of language models on code review downstream tasks, namely comment generation and code refinement. |
| 10 | + |
| 11 | +The main contributions of this work are threefold: |
| 12 | +(1) *A data-centric evaluation framework*, |
| 13 | +(2) *A curation pipeline to improve the quality of review comments*, and |
| 14 | +(3) *Evaluation of the curated dataset, compared to the original, on downstream tasks (i.e, comment generation and code refinement)*. |
| 15 | + |
| 16 | +Project structure |
| 17 | +--- |
| 18 | +The project is structured as follows. |
| 19 | + |
| 20 | + . |
| 21 | + ├── code_refinement/ # Code refinement package |
| 22 | + ├── comment_generation/ # Comment generation package |
| 23 | + ├── quality_assessment/ # empirical study package |
| 24 | + ├── data_curation/ # dataset curation package |
| 25 | + ├── util/ # package for helpers and config |
| 26 | + ├── data/ # Folder for dataset and results |
| 27 | + ├── models/ # Folder for large language models |
| 28 | + ├── requirements.txt # required python libraries |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | +Environment setup |
| 33 | +--- |
| 34 | +To facilitate usage and results replication, we include a file ```requirements.txt``` to install the required python libraries. |
| 35 | +Here are the instructions to create a virtual environment, activate it, and install dependencies using the provided `requirements.txt` file: |
| 36 | + |
| 37 | +1. **Create a Virtual Environment** |
| 38 | + Run the following command to create a virtual environment named `venv`: |
| 39 | + ```bash |
| 40 | + python3 -m venv venv |
| 41 | + ``` |
| 42 | + |
| 43 | +2. **Activate the Virtual Environment** |
| 44 | + - On **macOS/Linux**: |
| 45 | + ```bash |
| 46 | + source venv/bin/activate |
| 47 | + ``` |
| 48 | + - On **Windows**: |
| 49 | + ```bash |
| 50 | + .\venv\Scripts\activate |
| 51 | + ``` |
| 52 | + |
| 53 | +3. **Install Dependencies** |
| 54 | + With the virtual environment activated, install the required Python libraries from `requirements.txt`: |
| 55 | + ```bash |
| 56 | + pip install -r requirements.txt |
| 57 | + ``` |
| 58 | + |
| 59 | +4. **Verify the Installation** |
| 60 | + To confirm that all dependencies are installed correctly, run: |
| 61 | + ```bash |
| 62 | + pip list |
| 63 | + ``` |
| 64 | + |
| 65 | +5. **Deactivating the Environment** |
| 66 | + When you’re finished, you can deactivate the virtual environment with: |
| 67 | + ```bash |
| 68 | + deactivate |
| 69 | + ``` |
| 70 | + |
| 71 | +Data |
| 72 | +--- |
| 73 | +The original code review dataset is available in [Zenodo](https://zenodo.org/records/14058666). |
| 74 | +To run the experiments, you need to download ```Code_Refinement.zip``` and place the dataset under the ```data/``` folder. |
| 75 | +You can use the utilities method *create_HFdataset* in ```util.dataset``` to merge the downloaded jsonl files into a HuggingFace dataset. |
| 76 | + |
| 77 | +Models |
| 78 | +--- |
| 79 | +We run *Llama-3.1-70B* on our local machines using [ExLlamaV2](https://github.com/turboderp/exllamav2) to geneerate accurate judgments using our defined evaluation framework. |
| 80 | +You can choose the [same model](https://huggingface.co/hugging-quants/Meta-Llama-3.1-70B-Instruct-GPTQ-INT4) or any other model. |
| 81 | +Or, you can to download a quantized version of any other model that is compatible with *ExLlamaV2*. |
| 82 | +The downloaded model should be placed under the folder ```models/```. |
| 83 | + |
| 84 | + |
| 85 | +1- A data-centric evaluation framework |
| 86 | +--- |
| 87 | + |
| 88 | +We propose an evaluation framework to categorize and assess the quality of code reviews. It consists of (1) a **categorization scheme** to classify the *type*, *nature*, and *civility* of code review comments, and (2) **scoring criteria** to assess the overall quality of code reviews based on their *relevance*, *clarity*, and *conciseness*. We apply our evaluation framework to the largest existing dataset of code reviews. Given the scale of the dataset, we utilize a large language model (LLM) as a judge to automatically annotate samples with thoroughly designed prompts to ensure reliable and consistent annotations. |
| 89 | + |
| 90 | +The experiments conducted for this contribution are available under the folder ```quality_assessment/```. |
| 91 | + |
| 92 | +To run the LLM judgments: |
| 93 | +```bash |
| 94 | +python quality_assessment/inference.py \ |
| 95 | + --model_dir="models/Meta-Llama-3.1-70B-Instruct-GPTQ-INT4/" \ |
| 96 | + --dataset_path="data/Code_Refinement/CRdataset" \ |
| 97 | + --save_steps=5000 |
| 98 | +``` |
| 99 | +The full list of arguments is available in ```util/config.py```. |
| 100 | + |
| 101 | + |
| 102 | +2- CuREV: a curated dataset for code review |
| 103 | +--- |
| 104 | + |
| 105 | +The experiments conducted for this contribution are available under the folder ```data_curation/```. |
| 106 | + |
| 107 | +To run the experiments for reformulating review comments: |
| 108 | +```bash |
| 109 | +python reformulate_reviews/inference.py \ |
| 110 | + --model_dir="models/Meta-Llama-3.1-70B-Instruct-GPTQ-INT4/" \ |
| 111 | + --dataset_path="data/Code_Refinement/CRdataset" \ |
| 112 | + --output_path="data/eval_results/reform_results.jsonl" \ |
| 113 | + --save_steps=5000 |
| 114 | +``` |
| 115 | +The full list of arguments is available in ```util/config.py```. |
| 116 | + |
| 117 | + |
| 118 | +3-a. Comment generation |
| 119 | +--- |
| 120 | + |
| 121 | +The experiments conducted for this contribution are available under the folder ```comment_generation/```. |
| 122 | + |
| 123 | +- To train a language model on comment generation on the original dataset: |
| 124 | +```bash |
| 125 | +python comment_generation/sft_init.py \ |
| 126 | + --model_name_or_path="deepseek-ai/deepseek-coder-6.7b-instruct" \ |
| 127 | + --dataset_path="data/Code_Refinement/CRdataset" \ |
| 128 | + --output_path="data/eval_results/reform_results.jsonl" \ |
| 129 | + --save_steps=200 \ |
| 130 | + --checkpoint_path="models/comment_generation/init_ckpts" \ |
| 131 | + --output_path="models/comment_generation/final_model" |
| 132 | +``` |
| 133 | + |
| 134 | +- To train a language model on comment generation on the original dataset: |
| 135 | +```bash |
| 136 | +python comment_generation/sft_cur.py \ |
| 137 | + --model_name_or_path="deepseek-ai/deepseek-coder-6.7b-instruct" \ |
| 138 | + --dataset_path="data/Code_Refinement/CRdataset_reform" \ |
| 139 | + --output_path="data/eval_results/reform_results.jsonl" \ |
| 140 | + --save_steps=200 \ |
| 141 | + --checkpoint_path="models/comment_generation/init_ckpts" \ |
| 142 | + --output_path="models/comment_generation/final_model" |
| 143 | +``` |
| 144 | + |
| 145 | +- To run the inference on the initial or curated dataset: |
| 146 | +```bash |
| 147 | +python comment_generation/hf_inference-init.py |
| 148 | +python comment_generation/hf_inference-cur.py |
| 149 | +``` |
| 150 | + |
| 151 | +- To run the evaluation of both model: |
| 152 | +```bash |
| 153 | +python comment_generation/evaluation.py" |
| 154 | +``` |
| 155 | +
|
| 156 | +
|
| 157 | +- The full list of arguments is available in ```util/config.py```. |
| 158 | +
|
| 159 | +
|
| 160 | +3-b. Code refinement |
| 161 | +--- |
| 162 | +
|
| 163 | +The experiments conducted for this contribution are available under the folder ```code_refinement/```. |
| 164 | +
|
| 165 | +- To run the inference of a model for code on the initial dataset: |
| 166 | +```bash |
| 167 | +python comment_generation/hf_inference-init.py \ |
| 168 | + --model_name_or_path="deepseek-ai/deepseek-coder-6.7b-instruct" \ |
| 169 | + --dataset_path="data/Code_Refinement/CRdataset" \ |
| 170 | + --output_path="data/eval_results/reform_results.jsonl" \ |
| 171 | + --save_steps=1000 \ |
| 172 | + --output_path="models/init_coderef_results.jsonl" |
| 173 | +``` |
| 174 | +
|
| 175 | +- To run the inference of a model for code on the curated dataset: |
| 176 | +```bash |
| 177 | +python comment_generation/hf_inference-cur.py \ |
| 178 | + --model_name_or_path="deepseek-ai/deepseek-coder-6.7b-instruct" \ |
| 179 | + --dataset_path="data/Code_Refinement/CRdataset_reform" \ |
| 180 | + --output_path="data/eval_results/reform_results.jsonl" \ |
| 181 | + --save_steps=1000 \ |
| 182 | + --output_path="models/cur_coderef_results.jsonl" |
| 183 | +``` |
| 184 | +
|
| 185 | +- To run the evaluation of both model: |
| 186 | +```bash |
| 187 | +python comment_generation/evaluate.py" |
| 188 | +``` |
| 189 | + |
| 190 | +- The full list of arguments is available in ```util/config.py```. |
0 commit comments