arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2407.02095cs.SE
收藏

TIGER:一种面向实用Python类型推断的生成-排序框架

TIGER: A Generating-Then-Ranking Framework for Practical Python Type Inference

Chong Wang, Jian Zhang, Yiling Lou, Mingwei Liu, Weisong Sun, Yang Liu, Xin Peng

AI总结:

针对现有Python类型推断方法难处理复杂泛型和用户自定义类型的问题,本文提出两阶段生成-排序框架TIGER,在ManyTypes4Py数据集上显著提升了相关类型的推断准确率。

摘要:

Python的动态类型系统兼具灵活性与表达力,但也可能引发与类型相关的错误,因此亟需自动化类型推断来强化类型提示。现有基于学习的方法虽展现出可观的推断准确率,却难以应对全面处理各类类型的实际挑战,包括复杂泛型类型和(未见过的)用户自定义类型。\n 本文提出TIGER,这是一种两阶段的生成-排序(GTR)框架,旨在有效处理Python多样的类型类别。TIGER利用经微调的预训练代码模型,训练了一个以跨度掩码为目标的生成模型,以及一个采用对比训练目标的相似度模型。该方法使TIGER能在生成阶段生成包括复杂泛型在内的广泛类型候选,并在排序阶段结合用户自定义类型进行精准排序。我们在ManyTypes4Py数据集上的评估表明,TIGER在各类类型范畴内均优于现有方法,值得注意的是,在Top-5精确匹配指标下,其推断用户自定义类型和未见过类型的准确率分别提升了11.2%和20.1%。此外,实验结果不仅验证了TIGER的优异性能与效率,也凸显了其生成与排序阶段在提升自动化类型推断方面的重要性。

英文摘要:

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 generic 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 generics 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.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑