[Paper Review] Testing Neural Program Analyzers
This paper proposes a transformation-based testing framework to evaluate the robustness of neural program analyzers by generating semantically equivalent but syntactically different programs through techniques like loop swapping, variable renaming, and switch-to-if conversion. The key finding is that even minor syntactic changes can cause state-of-the-art models like code2vec to mispredict labels, revealing significant brittleness in neural program analysis models.
Deep neural networks have been increasingly used in software engineering and program analysis tasks. They usually take a program and make some predictions about it, e.g., bug prediction. We call these models neural program analyzers. The reliability of neural programs can impact the reliability of the encompassing analyses. In this paper, we describe our ongoing efforts to develop effective techniques for testing neural programs. We discuss the challenges involved in developing such tools and our future plans. In our preliminary experiment on a neural model recently proposed in the literature, we found that the model is very brittle, and simple perturbations in the input can cause the model to make mistakes in its prediction.
Motivation & Objective
- To address the lack of systematic testing methods for neural program analyzers in software engineering.
- To investigate whether semantic-preserving code transformations can expose model brittleness and prediction inconsistencies.
- To develop a framework for generating synthetic test programs that maintain semantic equivalence but alter syntactic structure.
- To evaluate model robustness by comparing predictions on original vs. transformed programs.
- To identify transformation types that most effectively trigger prediction failures in neural models.
Proposed method
- Apply semantic-preserving code transformations such as loop exchange (for ↔ while), variable renaming, boolean swapping, switch-to-if conversion, and statement reordering.
- Generate synthetic test programs by applying transformations to original programs from training datasets while preserving program semantics.
- Use the neural model to predict labels for both original and transformed programs and compare outputs.
- Define a transformation-based metamorphic relation: predictions should remain consistent across semantically equivalent variants.
- Establish similarity thresholds for predictions to detect deviations indicating model instability.
- Evaluate the framework on code2vec and GGNN models using Java and C# datasets, respectively.
Experimental results
Research questions
- RQ1Can semantic-preserving code transformations effectively expose prediction inconsistencies in neural program analyzers?
- RQ2Which types of code transformations are most likely to cause neural models to mispredict?
- RQ3How does model robustness vary across different syntactic variations of semantically equivalent programs?
- RQ4To what extent do common neural program embedding models like code2vec and GGNN fail under syntactic perturbations?
- RQ5How can transformation-based testing be systematically applied to evaluate the reliability of neural program analysis models?
Key findings
- The code2vec model mispredicted a while-loop implementation of an isPrime function as a 'skip' method, despite it being semantically equivalent to the for-loop version.
- The model failed to include 'isPrime' in the top-5 predictions for the while-loop version, indicating a significant drop in prediction accuracy.
- Semantic-preserving transformations such as loop exchange and switch conversion caused inconsistent predictions across equivalent program forms.
- No single transformation type was consistently more effective than others, suggesting diverse transformations are needed for comprehensive testing.
- The preliminary results confirm that neural program analyzers are highly brittle, with small syntactic changes leading to large prediction deviations.
- The framework successfully revealed model instability, highlighting the need for robustness testing in neural program analysis.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.