Better Modeling the Programming World with Code Concept Graphs-augmented Multi-modal Learning

Martin Weyssow, Houari A. Sahraoui, Bang Liu

TL;DR

This paper proposes a novel multi-modal learning approach to better model the programming world by combining code token representations with concept graphs derived from code. By jointly training a language model (LM) with a graph neural network (GNN) on these different data modalities, the authors aim to capture richer semantic information, leading to improved performance in tasks like code search.

What Problem Does This Paper Address?

Current state-of-the-art approaches in code modeling, primarily based on natural language processing (NLP) techniques, have made significant strides. However, the authors argue that these methods often overlook the full potential of diverse data sources and levels of abstraction available within software artifacts. While some work combines code with documentation or uses graph-based methods on structures like Abstract Syntax Trees (ASTs), there's a gap in leveraging multiple data modalities and high-level concept abstractions in a unified learning framework. The paper posits that just as human language relies on compositionality and hierarchical concepts, programming languages also possess a rich conceptual structure that can be better exploited for learning.

Methods

The core of the proposed method is a multi-modal learning framework that augments existing pre-trained language models of code. This is achieved by:

  1. Concept Graph Extraction: For a given code snippet, they extract "concept graphs" (CGs). These CGs represent high-level relationships between domain concepts materialized by code constructs (e.g., variables, methods, calls). Unlike ASTs, these CGs focus on identifiers and their semantic dependencies, aiming to be more language-agnostic. They define a CG as a relational graph $G = (V, E)$, where $V$ is a set of identifier nodes (with features like name and type) and $E$ represents typed relations (e.g., "dependsOn," "defines," "calls") between these identifiers.
  2. Multi-modal Learning Architecture: They propose a framework that jointly learns from two modalities:
  3. Code Tokens: Processed by a pre-trained language model (like CodeBERT).
  4. Concept Graphs: Processed by a Graph Neural Network (GNN), specifically a Gated Graph Neural Network (GAT) with a global attention pooling layer.
  5. Joint Learning Strategies: Two strategies for combining the learning models are discussed:
  6. Combining Outputs: The embeddings from the LM (for code tokens) and the GNN (for concept graphs) are combined (e.g., via summation) to form a final representation.
  7. Combining Models (More Sophisticated): This involves integrating the learning models more deeply, for instance, by conditioning code token representations on their corresponding concept graph node representations. For their preliminary evaluation, they used the simpler "combining outputs" method.

The objective is to minimize the distance between the combined code+CG representation and the query representation, effectively guiding the LM to learn better, more semantically rich representations.

Datasets

  • CodeSearchNet dataset: A modified version was used for training and evaluation. This dataset consists of pairs of <code, doc> (code snippets and their corresponding natural language descriptions). The authors use the documentation as a proxy for user queries.
  • The dataset was split into 164,923 pairs for training, 5,183 for validation, and 10,955 for testing.
  • For each code snippet, they extract its corresponding concept graph, resulting in triplets of <CG, code, query>.

Key Insights and Ideas

  • Code as Concepts: The fundamental idea is that programs, like natural languages, can be understood as manipulating concepts at various levels of abstraction. This conceptual structure is key to deeper understanding.
  • Leveraging Multiple Abstractions: Software artifacts offer rich, heterogeneous information at different levels (e.g., raw code tokens, ASTs, concept graphs). Combining these diverse modalities is crucial for comprehensive modeling.
  • Concept Graphs as High-Level Guidance: Concept graphs, by abstracting semantic relationships between identifiers, can provide a higher-level, more structured signal to guide learning models, potentially overcoming limitations of purely token-based or structural approaches.
  • Potential for Language Agnosticism: The concept graph extraction method is designed to be less dependent on specific language syntax, opening avenues for cross-lingual transfer learning.

Key Results

In their preliminary evaluation for code search on the CodeSearchNet dataset, the proposed CCGNN (Code Concept Graph Neural Network) model, which jointly learns from code tokens and concept graphs, achieved a Mean Reciprocal Rank (MRR) slightly above 0.78.

  • Slight Improvement: The CCGNN model showed a slight increase in MRR compared to a baseline CodeBERT model fine-tuned on code tokens alone.
  • No Significant Difference (Statistically): While the trend showed improvement, t-tests did not reveal a statistically significant difference between CodeBERT and CCGNN for each epoch.
  • CCGNN_nograph Performance: Interestingly, a variant called CCGNN_nograph (which uses the GNN for training but not at test time) performed identically to CCGNN. This suggests that the GNN's role in guiding the LM during training is beneficial, even if the CG itself isn't explicitly used during inference.
  • Simplicity of Combination: The authors note that their simple output combination method might be a limiting factor, suggesting that more sophisticated fusion techniques could yield more substantial gains.

Limitations and Future Work

  • Preliminary Evaluation: The authors acknowledge that this is a preliminary evaluation, and the observed gains are modest.
  • Simple Combination Method: The current method of combining model outputs is straightforward. Future work will explore more sophisticated integration strategies, such as combining the architectures of the LM and GNN directly.
  • End-Task Specificity: While evaluated for code search, the framework's applicability to other tasks (e.g., code generation, bug detection) needs to be explored by adapting the learning objectives.
  • Language Expansion: The current work focuses on Java. Future plans include extracting concept graphs for other programming languages and investigating transfer learning across languages.
  • Exploring More Modalities: The authors intend to compare different combinations of data modalities beyond code tokens and concept graphs.

Summary updated

BibTeX
@inproceedings{weyssow2022better,
  author = {Martin Weyssow and Houari A. Sahraoui and Bang Liu},
  title = {{Better Modeling the Programming World with Code Concept Graphs-augmented Multi-modal Learning}},
  booktitle = {ICSE (NIER)},
  year = {2022},
  url = {https://openreview.net/forum?id=R6RBjlmiB5dE},
}
Figure