TL;DR
This paper introduces CORE, a novel deep learning model that automates code review recommendations by learning from code changes and their corresponding reviews alone. CORE significantly outperforms existing methods by effectively capturing code semantics through a multi-level embedding approach, making code reviews more efficient for developers.
What Problem Does This Paper Address?
Code reviews are a crucial part of software development, helping to identify defects, improve code quality, and facilitate knowledge sharing. However, as projects grow and evolve rapidly, manual code reviews become a time-consuming and labor-intensive task for developers. Existing automated solutions often rely on extensive source code or complex context, which may not always be available. This paper tackles the challenge of providing accurate code review recommendations using only the submitted code changes and their associated reviews, aiming to reduce reviewer workload and improve efficiency.
Methods
The core of CORE lies in its innovative approach to representing code changes and reviews. It employs a multi-level embedding strategy, combining:
- Word-level embeddings: Standard word embeddings (like word2vec) are used to capture the semantic meaning of words. To handle project-specific tokens and reduce noise, these embeddings are retrained on preprocessed review texts where project-specific terms are replaced with placeholders.
- Character-level embeddings: This addresses the "Out-of-Vocabulary" (OOV) problem common in code, where unique tokens might not be present in pre-trained word embeddings. By embedding individual characters, CORE can better represent novel or rare tokens.
These multi-level embeddings are then fed into a multi-attention network. This network uses an attention mechanism to allow the model to focus on the most relevant parts of both the code changes and the reviews, thereby learning a more robust representation of their semantic consistency. The model is trained using a deep learning-to-rank approach to predict a relevancy score between a code change and a review.
Datasets
The authors collected a dataset of 57,260 <code change, review> pairs from 19 popular Java projects hosted on GitHub. This dataset was created by crawling pull requests and their associated reviews. The data was split into training, validation, and testing sets. Negative samples were generated by pairing code changes with irrelevant reviews to help the model learn what constitutes a non-relevant review.
Key Insights and Ideas
- Leveraging only code changes and reviews is sufficient: The paper demonstrates that valuable review recommendations can be generated without needing the full source code or extensive context, which is a significant practical advantage.
- Multi-level embeddings are key: Combining word-level and character-level embeddings is crucial for effectively capturing the nuances of code and review text, especially for handling the OOV problem in code.
- Attention mechanism enhances relevance: The multi-attention mechanism helps the model pinpoint the most important semantic elements in code changes and reviews, leading to more accurate relevancy predictions.
- Developer interest is high: A user study with industrial developers indicated strong interest and agreement on the usefulness of CORE for practical development.
Key Results
CORE significantly outperformed baseline models:
- Recall@10: CORE achieved a 131.03% increase compared to the state-of-the-art DeepMem model.
- Mean Reciprocal Rank (MRR): CORE showed a 150.69% improvement over DeepMem.
- Statistical significance tests confirmed the superiority of CORE.
- A qualitative analysis of case studies highlighted CORE's ability to identify semantically related tokens between code and reviews, a capability lacking in baseline models.
Limitations and Future Work
- Limitations:
- The paper acknowledges that the performance of CORE might be affected by the length of code changes, with mid-range lengths (50-75 tokens) yielding the best results. Very long code sequences might be truncated, losing important context.
- The quality of the dataset is a potential threat, as there's a possibility of overlap between training and testing sets, though efforts were made to mitigate this.
- The implementation of DeepMem might not have achieved its full potential due to the lack of access to its original contextual data.
- Future Work:
- The authors suggest improving review generation by incorporating neural translation and better code change embeddings.
- They also mention the potential for CORE to integrate external information, such as code structure and comments, to further enhance semantic relevancy learning.
Summary updated