Type4Py: Deep Similarity Learning-Based Type Inference for Python [article]

Amir M. Mir, Evaldas Latoskinas, Sebastian Proksch, Georgios Gousios
<span title="2021-07-22">2021</span> <i > arXiv </i> &nbsp; <span class="release-stage" >pre-print</span>
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.
more &raquo; ... 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.
<span class="external-identifiers"> <a target="_blank" rel="external noopener" href="https://arxiv.org/abs/2101.04470v2">arXiv:2101.04470v2</a> <a target="_blank" rel="external noopener" href="https://fatcat.wiki/release/wdyshjbse5ba3o2akw3btluncy">fatcat:wdyshjbse5ba3o2akw3btluncy</a> </span>
<a target="_blank" rel="noopener" href="https://web.archive.org/web/20210725212444/https://arxiv.org/pdf/2101.04470v2.pdf" title="fulltext PDF download" data-goatcounter-click="serp-fulltext" data-goatcounter-title="serp-fulltext"> <button class="ui simple right pointing dropdown compact black labeled icon button serp-button"> <i class="icon ia-icon"></i> Web Archive [PDF] <div class="menu fulltext-thumbnail"> <img src="https://blobs.fatcat.wiki/thumbnail/pdf/32/4d/324deb21627514865ea6b8fbf6f9cc1f4f4dda22.180px.jpg" alt="fulltext thumbnail" loading="lazy"> </div> </button> </a> <a target="_blank" rel="external noopener" href="https://arxiv.org/abs/2101.04470v2" title="arxiv.org access"> <button class="ui compact blue labeled icon button serp-button"> <i class="file alternate outline icon"></i> arxiv.org </button> </a>