Typilus: Neural Type Hints

Miltiadis Allamanis, Earl T. Barr, Soline Ducousso, Zheng Gao
4/6/2020
cs.PLcs.LGstat.ML

Official code: typilus/typilus (63 stars, MIT, last commit 2023-02-08).

Abstract

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.

View on arXivView PDF

Code Implementations(1)

typilus/typilusOfficial100%
MIT

Code for "Typilus: Neural Type Hints" PLDI 2020

6318Ruby, ShellMar 25, 20203 years agoMIT

Cite this paper

@article{allamanis2020typilus,
  title  = {Typilus: Neural Type Hints},
  author = {Miltiadis Allamanis and Earl T. Barr and Soline Ducousso and Zheng Gao},
  year   = {2020},
  eprint = {2004.10657},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2004.10657}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2004.10657.svg)](https://codeofpaper.com/paper/2004.10657)

Discussion