TypeT5: Seq2seq Type Inference using Static Analysis

Jiayi Wei, Greg Durrett, Isil Dillig
3/16/2023
cs.SEcs.LGcs.PL

No official code found. Best implementation: utopia-group/TypeT5 (32 stars, BSD-3-Clause, last commit 2023-07-09).

Abstract

There has been growing interest in automatically predicting missing type annotations in programs written in Python and JavaScript. While prior methods have achieved impressive accuracy when predicting the most common types, they often perform poorly on rare or complex types. In this paper, we present a new type inference method that treats type prediction as a code infilling task by leveraging CodeT5, a state-of-the-art seq2seq pre-trained language model for code. Our method uses static analysis to construct dynamic contexts for each code element whose type signature is to be predicted by the model. We also propose an iterative decoding scheme that incorporates previous type predictions in the model's input context, allowing information exchange between related code elements. Our evaluation shows that the proposed approach, TypeT5, not only achieves a higher overall accuracy (particularly on rare and complex types) but also produces more coherent results with fewer type errors -- while enabling easy user intervention.

View on arXivView PDF

Code Implementations(1)

utopia-group/TypeT5Community100%
BSD-3-Clause

Seq2seq Type Inference using Static Analysis and CodeT5

327Shell, PythonJan 18, 20233 years agoBSD-3-Clause
gradual-typingpythontransformer-architecturetype-inference

Similar Papers

Cite this paper

@article{wei2023typet,
  title  = {TypeT5: Seq2seq Type Inference using Static Analysis},
  author = {Jiayi Wei and Greg Durrett and Isil Dillig},
  year   = {2023},
  eprint = {2303.09564},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2303.09564v1},
  journal = {ICLR 2023 2023}
}

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/2303.09564.svg)](https://codeofpaper.com/paper/2303.09564)

Discussion