paperbot · PL 论文追踪

全部论文 待读 收藏

P2 Type4Py

Type4Py:基于深度相似度学习的 Python 类型推断
ICSE Proceedings of the 44th International Conference on Software Engineering2022匹配度 4/10 · Type4Py 属于机器学习用于程序语言中的类型推断,与“AI→PL”方向有较宽泛的关联,但它不是基于 LLM/Agent 的方法,也不涉及静态分析在 ML/Agentic 程序中的应用、浮点程序分析或贝叶斯程序分析。因此与用户当前核心研究画像匹配度有限。引用 81 inbox
Amir M. Mir, Evaldas Latoškinas, Sebastian Proksch, Georgios Gousios
crossref: 2026-09-12dblp: 2026-09-12arxiv: 2026-09-12

AI 速览

一句话:提出 Type4Py,用深度相似度学习的层次神经网络在类型空间中聚类,为 Python 参数、变量与返回值推断类型。

动态语言(如 Python、JavaScript)用静态类型换取灵活性,但缺乏静态类型会导致运行时异常并削弱 IDE 支持。PEP 484 引入可选类型标注,但为现有代码补全类型既易错又费力。已有机器学习方法多基于未必可靠的人工标注类型训练与评估,限制实用性。本文提出 Type4Py,一种基于深度相似度学习的层次化神经网络:它学习在高维空间中区分相似与不相似的类型并形成聚类,再通过最近邻搜索为参数、变量与返回值推断候选类型。作者在经类型检查的数据集上训练与评估,以平均倒数排名(MRR)衡量性能。Type4Py 达到 77.1% 的 MRR,较 Typilus 和 Typewriter 分别提升 8.1% 与 16.7%,并发布了 VS Code 扩展用于 Python 类型自动补全。

问题
动态语言缺少静态类型会导致运行时异常且 IDE 支持弱,而人工为现有代码补全类型既费时又易错;已有 ML 方法基于未必健全的人工标注来评估,限制了实际可用性。
方法
提出 Type4Py,一种基于深度相似度学习的层次化神经网络,在高维空间学习区分相似与不相似的类型以形成类型聚类,并通过最近邻搜索为参数、变量与返回值推断候选类型。
评估
在经类型检查的数据集上训练与评估,使用平均倒数排名(MRR)衡量用户感知性能;Type4Py 达到 77.1% 的 MRR,较 Typilus 和 Typewriter 分别提升 8.1% 与 16.7%,并发布了 VS Code 扩展。
原文摘要(Abstract)

Dynamic languages, such as Python and Javascript, trade static typing for developer flexibility and productivity. Lack of static typing can cause run-time exceptions and is a major factor for weak IDE support. To alleviate these issues, PEP 484 introduced optional type annotations for Python. As retrofitting types to existing code-bases is error-prone and laborious, machine learning (ML)-based approaches have been proposed to enable automatic type infer-ence based on existing, partially annotated codebases. However, previous ML-based approaches are trained and evaluated on human-provided type annotations, which might not always be sound, and hence this may limit the practicality for real-world usage. In this paper, we present TYPE4Py, a deep similarity learning-based hier-archical neural network model. It learns to discriminate between similar and dissimilar types in a high-dimensional space, which results in clusters of types. Likely types for arguments, variables, and return values can then be inferred through the nearest neigh-bor search. Unlike previous work, we trained and evaluated our model on a type-checked dataset and used mean reciprocal rank (MRR) to reflect the performance perceived by users. The obtained results show that TYPE4Py achieves an MRR of 77.1 %, which is a substantial improvement of 8.1% and 16.7% over the state-of-the-art approaches Typilus and Typewriter, respectively. Finally, to aid developers with retrofitting types, we released a Visual Stu-dio Code extension, which uses TYPE4Py to provide ML-based type auto-completion for Python.

链接与引用

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

BibTeX
@inproceedings{MirLPG22,
  title = {Type4Py},
  author = {Amir M. Mir and Evaldas Latoškinas and Sebastian Proksch and Georgios Gousios},
  booktitle = {ICSE},
  year = {2022},
  doi = {10.1145/3510003.3510124}
}