Type4Py: Deep Similarity Learning-Based Type Inference for Python
Preprint
Abstract
Dynamic languages, such as Python and Javascript, trade static typing for developer flexibility and productivity. Lack of static typing can cause run-time exceptions and is a major factor for weak IDE support. To alleviate these issues, PEP 484 introduced optional type annotations for Python. As retrofitting types to existing codebases is error-prone and laborious, learning-based approaches have been proposed to enable automatic type annotations based on existing, partially annotated codebases. However, it is still quite challenging for learning-based approaches to give a relevant prediction in the first suggestion or the first few ones. In this paper, we present Type4Py, a deep similarity learning-based hierarchical neural network model that learns to discriminate between types of the same kind and dissimilar types in a high-dimensional space, which results in clusters of types. Nearest neighbor search suggests a list of likely types for arguments, variables, and functions' return. The results of the quantitative and qualitative evaluation indicate that Type4Py significantly outperforms state-of-the-art approaches at the type prediction task. Considering the Top-1 prediction, Type4Py obtains a Mean Reciprocal Rank of 72.5%, which is 10.87% and 16.45% higher than that of Typilus and TypeWriter, respectively.Keywords
All Related Versions
This publication has 8 references indexed in Scilit:
- HieNN-DWE: A hierarchical neural network with dynamic word embeddings for document level sentiment classificationNeurocomputing, 2020
- The adverse effects of code duplication in machine learning models of code2019
- Hierarchical Neural Representation for Document ClassificationCognitive Computation, 2019
- LSTM with sentence representations for document-level sentiment classificationNeurocomputing, 2018
- A brief introduction to weakly supervised learningNational Science Review, 2017
- An empirical study on the impact of static typing on software maintainabilityEmpirical Software Engineering, 2013
- A Learning Algorithm for Continually Running Fully Recurrent Neural NetworksNeural Computation, 1989
- Nearest neighbor pattern classificationIEEE Transactions on Information Theory, 1967