本文提出 TIPICAL 方法,结合深度相似性学习与新异性检测,过滤未知和错误预测,从而在 Python 类型推断中实现高置信度预测并超越 Type4Py 的 F1 表现。
摘要:
基于深度学习的类型推断方法正变得越来越流行,因为它们旨在弥补静态和动态分析方法的不足,例如高不确定性。然而,其实际应用仍存在争议,原因在于若干固有问题,例如来自不同软件领域的代码会涉及类型推断系统未知的数据类型。为了克服这些问题并获得高置信度预测,我们提出了 TIPICAL,一种将深度相似性学习与新异性检测相结合的方法。我们表明,通过成功过滤掉未知和不准确的预测数据类型,我们的方法能够以高置信度更好地预测数据类型,并相对于最先进的类型推断方法 Type4Py 取得更高的 F1 分数。此外,我们还研究了不同软件领域和数据类型频率如何影响我们方法的结果。
英文摘要:
Type inference methods based on deep learning are becoming increasingly popular as they aim to compensate for the drawbacks of static and dynamic analysis approaches, such as high uncertainty. However, their practical application is still debatable due to several intrinsic issues such as code from different software domains will involve data types that are unknown to the type inference system. In order to overcome these problems and gain high-confidence predictions, we thus present TIPICAL, a method that combines deep similarity learning with novelty detection. We show that our method can better predict data types in high confidence by successfully filtering out unknown and inaccurate predicted data types and achieving higher F1 scores to the state-of-the-art type inference method Type4Py. Additionally, we investigate how different software domains and data type frequencies may affect the results of our method.
Co-Evolution of Types and Dependencies: Towards Repository-Level Type Inference for Python Code
Technology Center of Software Engineering, Institute of Software, Chinese Academy of Sciences(中国科学院软件研究所软件工程中心);Key Laboratory of System Software (Chinese Academy of Sciences), Institute of Software, Chinese Academy of Sciences(中国科学院软件研究所系统软件重点实验室)
PCREQ: Automated Inference of Compatible Requirements for Python Third-party Library Upgrades
Nanjing University of Aeronautics and Astronautics(南京航空航天大学);Nanjing University(南京大学);Southern University of Science and Technology(南方科技大学);Beihang University(北京航空航天大学)
Type4Py: Practical Deep Similarity Learning-Based Type Inference for Python
Delft University of Technology(代尔夫特理工大学);Facebook(脸书)
动态语言,如Python和JavaScript,用静态类型换取开发人员的灵活性和生产力。缺少静态类型会导致运行时异常,并且是IDE支持薄弱的主要因素。为了缓解这些问题,PEP 484为Python引入了可选的类型注释。由于将类型改装到现有代码库是容易出错且费力的,因此已经提出了基于机器学习(ML)的方法来实现基于现有的部分注释的代码库的自动类型推断。然而,以前的基于ML的方法是在人类提供的类型注释上训练和评估的,这可能并不总是合理的,因此这可能限制了现实世界使用的实用性。在本文中,我们提出了Type4Py,一个基于深度相似性学习的分层神经网络模型。它学会在高维空间中区分相似和不相似的类型,从而产生类型集群。参数、变量和返回值的可能类型可以通过最近邻搜索来推断。与以前的工作不同,我们在经过类型检查的数据集上训练和评估了我们的模型,并使用平均倒数排名(MRR)来反映用户感知的性能。所获得的结果表明,Type4Py实现了77.1%的MRR,这比最先进的方法Typilus和TypeWriter分别大幅提高了8.1%和16.7%。最后,为了帮助开发人员改进类型,我们发布了一个Visual Studio Code扩展,它使用Type4Py为Python提供基于ML的类型自动完成。