一句话:提出两阶段“先生成后排序”框架,显著提升 Python 中用户定义类型与未见类型的推断准确率。
Python 的动态类型系统灵活但易引发类型相关错误,自动类型推断可用于补全类型提示。现有基于学习的方法虽有较好准确率,却难以全面处理各类类型,尤其是复杂参数化类型和未见过的用户定义类型。本文提出 TIGER,一个“先生成后排序”(GTR)的两阶段框架:借助微调的预训练代码模型,分别以 span masking 目标训练生成模型、以对比学习目标训练相似度模型;生成阶段产出大量类型候选(包括复杂参数化类型),排序阶段则结合用户定义类型对候选精确排序。在 ManyTypes4Py 数据集上的评估表明,TIGER 在多种类型类别上优于现有方法,在 Top-5 Exact Match 中推断用户定义类型和未见类型的准确率分别提升 11.2% 和 20.1%,同时验证了生成与排序两阶段对自动类型推断的重要作用。
Python's dynamic typing system offers flexibility and expressiveness but can lead to type-related errors, prompting the need for automated type inference to enhance type hinting. While existing learning-based approaches show promising inference accuracy, they struggle with practical challenges in comprehensively handling various types, including complex parameterized types and (unseen) user-defined types. In this paper, we introduce TIGER, a two-stage generating-then-ranking (GTR) framework, designed to effectively handle Python's diverse type categories. TIGER leverages fine-tuned pre-trained code models to train a generative model with a span masking objective and a similarity model with a contrastive training objective. This approach allows TIGER to generate a wide range of type candidates, including complex parameterized types in the generating stage, and accurately rank them with user-defined types in the ranking stage. Our evaluation on the ManyTypes4Py dataset shows TIGER's advantage over existing methods in various type categories, notably improving accuracy in inferring user-defined and unseen types by 11.2% and 20.1% respectively in Top-5 Exact Match. Moreover, the experimental results not only demonstrate TIGER's superior performance and efficiency, but also underscore the significance of its generating and ranking stages in enhancing automated type inference.
DOI 原文 ·
@inproceedings{paperbot8837,
title = {TIGER: A Generating-Then-Ranking Framework for Practical Python Type Inference},
author = {Chong Wang and Jian Zhang and Yiling Lou and Mingwei Liu and Weisong Sun and Yang Liu and Xin Peng},
booktitle = {ICSE},
year = {2025},
doi = {10.1109/icse55347.2025.00019}
}