arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2105.03595cs.SEcs.PL
收藏

静态推理满足深度学习:Python的混合类型推断方法

Static Inference Meets Deep Learning: A Hybrid Type Inference Approach for Python

Yun Peng, Cuiyun Gao, Zongjie Li, Bowei Gao, David Lo, Qirun Zhang, Michael Lyu

摘要:

对于像Python这样的动态规划语言,类型推断是一个重要而又具有挑战性的任务。静态类型推断技术可以精确地推断出具有足够静态约束的变量,但无法处理具有动态特征的变量。基于深度学习(DL)的方法是特征不可知的,但它们不能保证预测类型的正确性。它们的性能很大程度上取决于训练数据的质量(即,DL模型在训练数据集中很少出现的一些常见类型上表现不佳)。有趣的是,静态和基于DL的方法提供了互补的好处。不幸的是,据我们所知,基于静态推理和神经预测的精确类型推断还没有被利用,仍然是一个开放的挑战。特别是,很难将深度学习模型集成到基于规则的静态方法的框架中。本文填补了这一空白,提出了一种基于静态推理和深度学习的混合类型推断方法HiTyper。具体来说,我们的关键见解是记录每个函数中变量之间的类型依赖关系,并将依赖关系信息编码到类型依赖图(TDG)中。基于TDGs,我们可以很容易地集成类型推断规则在节点进行静态推理和类型拒绝规则来检查神经预测的正确性。HiTyper迭代地进行静态推断和基于DL的预测,直到TDG被完全推断。在两个基准数据集上的实验表明,HiTyper的性能优于最先进的DL模型,可以准确匹配10%以上的人类注释。HiTyper在推断稀有类型方面也实现了超过30%的增长。只考虑HiTyper的静态部分,它比现有的静态类型推断工具多推断2 ~ 3倍的类型。

英文摘要:

Type inference for dynamic programming languages such as Python is an important yet challenging task. Static type inference techniques can precisely infer variables with enough static constraints but are unable to handle variables with dynamic features. Deep learning (DL) based approaches are feature-agnostic, but they cannot guarantee the correctness of the predicted types. Their performance significantly depends on the quality of the training data (i.e., DL models perform poorly on some common types that rarely appear in the training dataset). It is interesting to note that the static and DL-based approaches offer complementary benefits. Unfortunately, to our knowledge, precise type inference based on both static inference and neural predictions has not been exploited and remains an open challenge. In particular, it is hard to integrate DL models into the framework of rule-based static approaches. This paper fills the gap and proposes a hybrid type inference approach named HiTyper based on both static inference and deep learning. Specifically, our key insight is to record type dependencies among variables in each function and encode the dependency information in type dependency graphs (TDGs). Based on TDGs, we can easily integrate type inference rules in the nodes to conduct static inference and type rejection rules to inspect the correctness of neural predictions. HiTyper iteratively conducts static inference and DL-based prediction until the TDG is fully inferred. Experiments on two benchmark datasets show that HiTyper outperforms state-of-the-art DL models by exactly matching 10% more human annotations. HiTyper also achieves an increase of more than 30% on inferring rare types. Considering only the static part of HiTyper, it infers 2x ~ 3x more types than existing static type inference tools.

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

↑