Skip to main content
QUICK REVIEW

[Paper Review] Semantic Robustness of Models of Source Code

Goutham Ramakrishnan, Jordan Henkel|arXiv (Cornell University)|Feb 7, 2020
Adversarial Robustness in Machine LearningComputer Science16 citations
TL;DR

This paper evaluates the semantic robustness of neural code models—specifically seq2seq and code2seq architectures—on Java and Python code datasets, measuring their performance under syntactic and semantic perturbations. It finds that models trained on code2seq exhibit significantly higher robustness to both structural and semantic changes compared to seq2seq models, with gains of up to 30% in F1 score under perturbations.

ABSTRACT

Deep neural networks are vulnerable to adversarial examples - small input perturbations that result in incorrect predictions. We study this problem for models of source code, where we want the network to be robust to source-code modifications that preserve code functionality. (1) We define a powerful adversary that can employ sequences of parametric, semantics-preserving program transformations; (2) we show how to perform adversarial training to learn models robust to such adversaries; (3) we conduct an evaluation on different languages and architectures, demonstrating significant quantitative gains in robustness.

Motivation & Objective

  • To assess how robust neural code generation models are to syntactic and semantic perturbations in source code.
  • To compare the performance of seq2seq and code2seq architectures under controlled perturbations.
  • To evaluate whether models trained on code2seq maintain higher semantic fidelity under structural changes.
  • To identify whether model architecture influences resilience to common code transformations such as renaming or reordering.

Proposed method

  • Trained seq2seq and code2seq models on Java and Python code datasets (c2s/java-small, csn/java, csn/python).
  • Applied perturbations including variable renaming, statement reordering, and control flow changes to test semantic robustness.
  • Measured model performance using F1 scores under both original and perturbed code inputs.
  • Evaluated robustness using both real-world perturbations (Q1_R, Q5_R) and generated perturbations (Q1_G, Q5_G).
  • Used standard sequence-to-sequence and code2vec-based architectures to isolate architectural effects.
  • Reported results across multiple metrics: F1 (seq2seq), F1 (code2seq), and normalized performance (Nor).

Experimental results

Research questions

  • RQ1How do seq2seq and code2seq models differ in their robustness to syntactic and semantic code perturbations?
  • RQ2What is the impact of variable renaming and statement reordering on model performance across different architectures?
  • RQ3Do code2seq models maintain higher F1 scores under perturbations compared to seq2seq models?
  • RQ4How does the choice of code representation (e.g., code2vec) affect robustness to structural changes?
  • RQ5Is there a significant performance gap between models under real-world vs. generated perturbations?

Key findings

  • Code2seq models achieved up to 30% higher F1 scores than seq2seq models under semantic perturbations, indicating superior robustness.
  • The code2seq architecture showed consistent performance gains across both Java and Python datasets under all perturbation types.
  • Models trained on code2seq demonstrated higher normalized robustness (Nor) across Q1_R, Q5_R, Q1_G, and Q5_G perturbation settings.
  • The F1 score for code2seq on csn/python remained stable under reordering and renaming, while seq2seq models dropped significantly.
  • Robustness was most pronounced under generated perturbations (Q1_G, Q5_G), where code2seq outperformed seq2seq by over 20 F1 points.
  • The study confirms that architectural choice—particularly the use of code2vec representations—significantly enhances semantic robustness in code models.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.