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

Fuente: arXiv
Gespeichert in:
Bibliographische Detailangaben
Hauptverfasser: Wang, Chong, Zhang, Jian, Lou, Yiling, Liu, Mingwei, Sun, Weisong, Liu, Yang, Peng, Xin
Format: Preprint
Veröffentlicht: 2024
Schlagworte:
Online-Zugang:
Tags: Tag hinzufügen
Keine Tags, Fügen Sie den ersten Tag hinzu!
_version_ 1866929456899162112
author Wang, Chong
Zhang, Jian
Lou, Yiling
Liu, Mingwei
Sun, Weisong
Liu, Yang
Peng, Xin
author_facet Wang, Chong
Zhang, Jian
Lou, Yiling
Liu, Mingwei
Sun, Weisong
Liu, Yang
Peng, Xin
contents 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.
format Preprint
id arxiv_https___arxiv_org_abs_2407_02095
institution arXiv
publishDate 2024
record_format arxiv
spellingShingle TIGER: A Generating-Then-Ranking Framework for Practical Python Type Inference
Wang, Chong
Zhang, Jian
Lou, Yiling
Liu, Mingwei
Sun, Weisong
Liu, Yang
Peng, Xin
Software Engineering
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.
title TIGER: A Generating-Then-Ranking Framework for Practical Python Type Inference
topic Software Engineering
url https://arxiv.org/abs/2407.02095