VarCLR: Variable Semantic Representation Pre-training via Contrastive Learning

19Citations
Citations of this article
27Readers
Mendeley users who have this article in their library.
Get full text

Abstract

Variable names are critical for conveying intended program behavior. Machine learning-based program analysis methods use variable name representations for a wide range of tasks, such as suggesting new variable names and bug detection. Ideally, such methods could capture semantic relationships between names beyond syntactic similarity, e.g., the fact that the names average and mean are similar. Unfortunately, previous work has found that even the best of previous representation approaches primarily capture 'relatedness' (whether two variables are linked at all), rather than 'similarity' (whether they actually have the same meaning). We propose Varclr, a new approach for learning semantic representations of variable names that effectively captures variable similarity in this stricter sense. We observe that this problem is an excellent fit for contrastive learning, which aims to minimize the distance between explicitly similar inputs, while maximizing the distance between dissimilar inputs. This requires labeled training data, and thus we construct a novel, weakly-supervised variable renaming dataset mined from GitHub edits. We show that Varclr enables the effective application of sophisticated, general-purpose language models like BERT, to variable name representation and thus also to related downstream tasks like variable name similarity search or spelling correction. Varclr produces models that significantly outperform the state-of-the-art on IDBENCH, an existing benchmark that explicitly captures variable similarity (as distinct from relatedness). Finally, we contribute a release of all data, code, and pre-trained models, aiming to provide a drop-in replacement for variable representations used in either existing or future program analyses that rely on variable names.

Cite

CITATION STYLE

APA

Chen, Q., Lacomis, J., Schwartz, E. J., Neubig, G., Vasilescu, B., & Goues, C. L. (2022). VarCLR: Variable Semantic Representation Pre-training via Contrastive Learning. In Proceedings - International Conference on Software Engineering (Vol. 2022-May, pp. 2327–2339). IEEE Computer Society. https://doi.org/10.1145/3510003.3510162

Register to see more suggestions

Mendeley helps you to discover research relevant for your work.

Already have an account?

Save time finding and organizing research with Mendeley

Sign up for free