Embedding Java Classes with code2vec: Improvements from Variable Obfuscation
Not on the map. Why?
Abstract (arXiv)
Automatic source code analysis in key areas of software engineering, such as code security, can benefit from Machine Learning (ML). However, many standard ML approaches require a numeric representation of data and cannot be applied directly to source code. Thus, to enable ML, we need to embed source code into numeric feature vectors while maintaining the semantics of the code as much as possible. code2vec is a recently released embedding approach that uses the proxy task of method name prediction to map Java methods to feature vectors. However, experimentation with code2vec shows that it learns to rely on variable names for prediction, causing it to be easily fooled by typos or adversarial attacks. Moreover, it is only able to embed individual Java methods and cannot embed an entire collection of methods such as those present in a typical Java class, making it difficult to perform predictions at the class level (e.g., for the identification of malicious Java classes). Both shortcomings are addressed in the research presented in this paper. We investigate the effect of obfuscating variable names during the training of a code2vec model to force it to rely on the structure of the code rather than specific names and consider a simple approach to creating class-level embeddings by aggregating sets of method embeddings. Our results, obtained on a challenging new collection of source-code classification problems, indicate that obfuscating variable names produces an embedding model that is both impervious to variable naming and more accurately reflects code semantics. The datasets, models, and code are shared for further ML research on source code.
Key facts. Cited by 12 papers in the map (data through 7 Oct 2026). First posted on arXiv 6 Apr 2020.
Builds on
No reference list yet.
Built on by
Citing papers per year: 2021: 4; 2022: 4; 2023: 3; 2024: 1.
12 papers.
- 2021A Survey on Machine Learning Techniques for Source Code Analysiscited by 23
- 2021Memorization and Generalization in Neural Code Intelligence Modelscited by 17
- 2024What can Large Language Models Capture about Code Functional Equivalence?cited by 13
- 2022An Exploratory Study on Code Attention in BERTcited by 12
- 2022Syntax-Guided Program Reduction for Understanding Neural Code Intelligence Modelscited by 7
- 2021Code2Snapshot: Using Code Snapshots for Learning Representations of Source Codecited by 4
- 2022A Survey of Deep Learning Models for Structural Code Understandingcited by 4
- 2021Repo2Vec: A Comprehensive Embedding Approach for Determining Repository Similaritycited by 2
- 2023Study of Distractors in Neural Models of Codecited by 2
- 2023An Exploratory Literature Study on Sharing and Energy Use of Language Models for Source Codecited by 1
- 2022Extracting Label-specific Key Input Features for Neural Code Intelligence Modelscited by 0
- 2023A Study of Variable-Role-based Feature Enrichment in Neural Models of Codecited by 0
- 2024What can Large Language Models Capture about Code Functional Equivalence?20 Aug 2024
- 2023An Exploratory Literature Study on Sharing and Energy Use of Language Models for Source Code5 Jul 2023
- 2023A Study of Variable-Role-based Feature Enrichment in Neural Models of Code8 Mar 2023
- 2023Study of Distractors in Neural Models of Code3 Mar 2023
- 2022Syntax-Guided Program Reduction for Understanding Neural Code Intelligence Models28 May 2022
- 2022A Survey of Deep Learning Models for Structural Code Understanding3 May 2022
- 2022An Exploratory Study on Code Attention in BERT5 Apr 2022
- 2022Extracting Label-specific Key Input Features for Neural Code Intelligence Models14 Feb 2022
- 2021Code2Snapshot: Using Code Snapshots for Learning Representations of Source Code1 Nov 2021
- 2021A Survey on Machine Learning Techniques for Source Code Analysis18 Oct 2021
- 2021Repo2Vec: A Comprehensive Embedding Approach for Determining Repository Similarity11 Jul 2021
- 2021Memorization and Generalization in Neural Code Intelligence Models16 Jun 2021