TYPILUS: Neural Type Hints

被引:77
作者
Allamanis, Miltiadis [1 ]
Barr, Earl T. [2 ]
Ducousso, Soline [2 ,3 ]
Gao, Zheng [2 ]
机构
[1] Microsoft Res, Cambridge, England
[2] UCL, London, England
[3] Ecole Natl Super Tech Avancees, Paris, France
来源
PROCEEDINGS OF THE 41ST ACM SIGPLAN CONFERENCE ON PROGRAMMING LANGUAGE DESIGN AND IMPLEMENTATION (PLDI '20) | 2020年
基金
英国工程与自然科学研究理事会;
关键词
type inference; structured learning; deep learning; graph neural networks; meta-learning;
D O I
10.1145/3385412.3385997
中图分类号
TP31 [计算机软件];
学科分类号
081202 ; 0835 ;
摘要
Type inference over partial contexts in dynamically typed languages is challenging. In this work, we present a graph neural network model that predicts types by probabilistically reasoning over a program's structure, names, and patterns. The network uses deep similarity learning to learn a TypeSpace- a continuous relaxation of the discrete space of types - and how to embed the type properties of a symbol ( i.e. identifier) into it. Importantly, our model can employ one-shot learning to predict an open vocabulary of types, including rare and user-defined ones. We realise our approach in TYPILUS for Python that combines the TypeSpace with an optional type checker. We show that TYPILUS accurately predicts types. TYPILUS confidently predicts types for 70% of all annotatable symbols; when it predicts a type, that type optionally type checks 95% of the time. TYPILUS can also find incorrect type annotations; two important and popular open source libraries, fairseq and allennlp, accepted our pull requests that fixed the annotation errors TYPILUS discovered.
引用
收藏
页码:91 / 105
页数:15
相关论文
共 60 条
[1]   A Survey of Machine Learning for Big Code and Naturalness [J].
Allamanis, Miltiadis ;
Barr, Earl T. ;
Devanbu, Premkumar ;
Sutton, Charles .
ACM COMPUTING SURVEYS, 2018, 51 (04)
[2]   Suggesting Accurate Method and Class Names [J].
Allamanis, Miltiadis ;
Barr, Earl T. ;
Bird, Christian ;
Sutton, Charles .
2015 10TH JOINT MEETING OF THE EUROPEAN SOFTWARE ENGINEERING CONFERENCE AND THE ACM SIGSOFT SYMPOSIUM ON THE FOUNDATIONS OF SOFTWARE ENGINEERING (ESEC/FSE 2015) PROCEEDINGS, 2015, :38-49
[3]   Learning Natural Coding Conventions [J].
Allamanis, Miltiadis ;
Barr, Earl T. ;
Bird, Christian ;
Sutton, Charles .
22ND ACM SIGSOFT INTERNATIONAL SYMPOSIUM ON THE FOUNDATIONS OF SOFTWARE ENGINEERING (FSE 2014), 2014, :281-293
[4]  
Allamanis M, 2013, IEEE WORK CONF MIN S, P207, DOI 10.1109/MSR.2013.6624029
[5]  
Allamanis Miltiadis, 2018, P INT C LEARN REPR I
[6]  
Allamanis Miltiadis, 2019, SPLASH ONWARD
[7]   code2vec: Learning Distributed Representations of Code [J].
Alon, Uri ;
Zilberstein, Meital ;
Levy, Omer ;
Yahav, Eran .
PROCEEDINGS OF THE ACM ON PROGRAMMING LANGUAGES-PACMPL, 2019, 3 (POPL)
[8]  
Alon Uri, 2010, P INT C LEARN REPR I
[9]  
[Anonymous], 2015, ICLR
[10]  
[Anonymous], 2015, P INT C MACH LEARN I