paperbot · PL 论文追踪

全部论文 待读 收藏

P1 Generative Type Inference for Python

面向 Python 的生成式类型推断
ASE 2023 38th IEEE/ACM International Conference on Automated Software Engineering (ASE)2023匹配度 6/10 · Typegen 将静态分析的依赖图与推理步骤转成 CoT 提示,用 LLM 改进 Python 类型推断,属于“AI→PL”中利用 LLM 改进静态分析的方向,有直接交集。但它不涉及 Agentic 程序、浮点程序分析、贝叶斯程序分析或形式化验证,且实验主要基于较旧/较小模型,缺少工业落地或新 benchmark 贡献,因此匹配度中等。引用 25 inbox
Yun Peng, Chaozheng Wang, Wenxuan Wang, Cuiyun Gao, Michael R. Lyu
crossref: 2026-09-12dblp: 2026-09-12arxiv: 2026-09-12

AI 速览

一句话:提出 Typegen,将静态分析步骤转为思维链提示,实现少样本、可解释的 Python 类型推断。

Python 的动态类型易导致类型错误,现有推断方法存在覆盖低、依赖大量标注、忽略静态规则且不可解释等问题。本文提出 Typegen,一种少样本生成式类型推断方法:它把静态分析的类型推断步骤转化为基于类型依赖图(TDG)的思维链(COT)提示,并结合代码片段与类型提示构造示例,使语言模型通过上下文学习生成类似推理链;采用输入-解释-输出策略同时给出解释和类型预测。实验表明,仅用五个示例,Typegen 在参数类型和返回值类型预测的 top-1 Exact Match 上分别比最佳基线 Type4Py 提升 10.0% 和 22.5%,并比 1.3B 至 175B 大语言模型的零样本表现提升 27% 至 84%。

问题
Python 动态类型系统容易产生类型错误,而现有自动类型推断方法分别受限于低覆盖率、大量高质量标注需求、忽略静态类型规则以及结果不可解释。
方法
Typegen 将静态分析的类型推断步骤转换为基于类型依赖图(TDG)的思维链提示,结合代码片段和类型提示进行少样本上下文学习,并用输入-解释-输出策略生成解释与类型预测。
评估
在 Python 类型推断任务上,仅用五个示例与传统基线和不同规模大语言模型零样本结果对比,以 top-1 Exact Match 评估。
原文摘要(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. Existing type inference approaches can be generally grouped into three categories, i.e., rule-based, supervised, and cloze- style approaches. The rule-based type inference approaches can ensure the accuracy of predicted variable types, but they suffer from low coverage problems caused by dynamic features and external calls. Supervised type inference approaches, while feature-agnostic and able to mitigate the low coverage problem, 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 by leveraging the general knowledge in powerful pre-trained code models. However, their performance is limited since they ignore the domain knowledge from static typing rules which reflect the inference logic. What is more, their predictions are not interpretable, hindering developers' understanding and verification of the results. This paper introduces Typegen, a few-shot generative type inference approach that incorporates static domain knowledge from static analysis. Typegen creates chain-of-thought (COT) prompts by translating the type inference steps of static analysis into prompts based on the type dependency graphs (TDGs), enabling language models to learn from how static analysis infers types. By combining COT prompts with code slices and type hints, TypegEnconstructs example prompts from human annotations. Typeg Enonly requires very few annotated examples to teach language models to generate similar COT prompts via in-context learning. Moreover, Typeg Enenhances the interpretability of results through the use of the input- explanation-output strategy, which generates both explanations and type predictions in COT prompts. Experiments show that Typegen outperforms the best baseline Type4Py by 10.0% for argument type prediction and 22.5 % in return value type prediction in terms of top-l Exact Match by using only five examples. Furthermore, Typeg Enachieves substantial improvements of 27 % to 84 % compared to the zero-shot performance of large language models with parameter sizes ranging from 1.3B to 175B in terms of top-I Exact Match.

链接与引用

DOI 原文 · arXiv · PDF(开放获取) · DBLP

BibTeX
@inproceedings{abs-2307-09163,
  title = {Generative Type Inference for Python},
  author = {Yun Peng and Chaozheng Wang and Wenxuan Wang and Cuiyun Gao and Michael R. Lyu},
  booktitle = {ASE},
  year = {2023},
  doi = {10.1109/ase56229.2023.00031}
}