Generative Type Inference for Python
Yun Peng, Chaozheng Wang, Wenxuan Wang, Cuiyun Gao, Michael R. Lyu

TL;DR
TypeGen is a few-shot generative approach that leverages static analysis and chain-of-thought prompts to improve Python type inference, significantly outperforming existing methods with minimal annotated data.
Contribution
The paper introduces TypeGen, a novel few-shot generative type inference method that combines static analysis with language models using chain-of-thought prompts, requiring only a few annotations.
Findings
TypeGen outperforms Type4Py by 10% in argument type prediction.
TypeGen achieves 22.5% higher accuracy in return value type prediction.
TypeGen improves zero-shot performance of large language models by 27% to 84%.
Abstract
Python is a popular dynamic programming language, evidenced by its ranking as the second most commonly used language on GitHub. However, its dynamic type system can lead to potential type errors, leading researchers to explore automatic type inference approaches for Python programs. The rule-based type inference approaches can ensure the accuracy of predicted variable types, but they suffer from low coverage problems. Supervised type inference approaches, while feature-agnostic, require large, high-quality annotated datasets and are limited to pre-defined types. As zero-shot approaches, the cloze-style approaches reformulate the type inference problem into a fill-in-the-blank problem. However, their performance is limited. This paper introduces TypeGen, a few-shot generative type inference approach that incorporates static domain knowledge from static analysis. TypeGen creates…
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Code & Models
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
Taxonomy
TopicsSoftware Engineering Research · Topic Modeling · Machine Learning in Materials Science
