Type4Py: Practical Deep Similarity Learning-Based Type Inference for Python
Not on the map. Why?
Abstract (arXiv)
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 codebases is error-prone and laborious, machine learning (ML)-based approaches have been proposed to enable automatic type inference 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 hierarchical 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 neighbor 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 Studio Code extension, which uses Type4Py to provide ML-based type auto-completion for Python.
Key facts. Cited by 19 papers in the map (data through 7 Oct 2026). Builds on 11 of its 62 references that are in the map. First posted on arXiv 12 Jan 2021.
Builds on
11 of 62 references.
References · 11
- 2014Adam: A Method for Stochastic Optimizationcited by 36,960
- 2019PyTorch: An Imperative Style, High-Performance Deep Learning Librarycited by 20,160
- 2013Distributed Representations of Words and Phrases and their Compositionalitycited by 3,462
- 2015Pointer Networkscited by 882
- 2020On the Bottleneck of Graph Neural Networks and its Practical Implicationscited by 624
- 2018The Adverse Effects of Code Duplication in Machine Learning Models of Codecited by 123
- 2020LambdaNet: Probabilistic Type Inference using Graph Neural Networkscited by 44
- 2019TypeWriter: Neural Type Prediction with Search-based Validationcited by 32
- 2020Typilus: Neural Type Hintscited by 29
- 2020OptTyper: Probabilistic Type Inference by Optimising Logical and Natural Constraintscited by 14
- 2018Triplet-based Deep Similarity Learning for Person Re-Identificationcited by 3
Built on by
Citing papers per year: 2022: 1; 2023: 7; 2024: 7; 2025: 3; 2026: 1.
19 papers.
Sort:
By area:
- 2024LiveCodeBench: Holistic and Contamination Free Evaluation of Large Language Models for Codecited by 1,906
- 2024EffiBench: Benchmarking the Efficiency of Automatically Generated Codecited by 62
- 2023Bias Testing and Mitigation in LLM-based Code Generationcited by 53
- 2024EffiLearner: Enhancing Efficiency of Generated Code via Self-Optimizationcited by 28
- 2024MHPP: Exploring the Capabilities and Limitations of Language Models Beyond Basic Code Generationcited by 25
- 2025EffiBench-X: A Multi-Language Benchmark for Measuring Efficiency of LLM-Generated Codecited by 24
- 2023Deep Learning for Code Intelligence: Survey, Benchmark and Toolkitcited by 22
- 2024EffiCoder: Enhancing Code Generation in Large Language Models through Efficiency-Aware Fine-tuningcited by 15
- 2023TypeT5: Seq2seq Type Inference using Static Analysiscited by 12
- 2024Measuring the Influence of Incorrect Code on Test Generationcited by 9
- 2023LExecutor: Learning-Guided Executioncited by 7
- 2023Type Prediction With Program Decomposition and Fill-in-the-Type Trainingcited by 6
7 more
- 2025Treefix: Enabling Execution with a Tree of Prefixescited by 2
- 2022Cross-Domain Evaluation of a Deep Learning-Based Type Inference Systemcited by 1
- 2023An Exploratory Literature Study on Sharing and Energy Use of Language Models for Source Codecited by 1
- 2023DocGen: Generating Detailed Parameter Docstrings in Pythoncited by 0
- 2024Inferring Pluggable Types with Machine Learningcited by 0
- 2025Automated Type Annotation in Python Using Large Language Modelscited by 0
- 2026AgentExecutor: Partial Code Execution via Agentic Context Generationcited by 0
- 2026AgentExecutor: Partial Code Execution via Agentic Context Generation6 Aug 2026
- 2025Automated Type Annotation in Python Using Large Language Models1 Aug 2025
- 2025EffiBench-X: A Multi-Language Benchmark for Measuring Efficiency of LLM-Generated Code19 May 2025
- 2025Treefix: Enabling Execution with a Tree of Prefixes21 Jan 2025
- 2024EffiCoder: Enhancing Code Generation in Large Language Models through Efficiency-Aware Fine-tuning14 Oct 2024
- 2024Measuring the Influence of Incorrect Code on Test Generation14 Sep 2024
- 2024Inferring Pluggable Types with Machine Learning21 Jun 2024
- 2024EffiLearner: Enhancing Efficiency of Generated Code via Self-Optimization24 May 2024
- 2024MHPP: Exploring the Capabilities and Limitations of Language Models Beyond Basic Code Generation19 May 2024
- 2024LiveCodeBench: Holistic and Contamination Free Evaluation of Large Language Models for Code12 Mar 2024
- 2024EffiBench: Benchmarking the Efficiency of Automatically Generated Code3 Feb 2024
- 2023Deep Learning for Code Intelligence: Survey, Benchmark and Toolkit30 Dec 2023
7 more
- 2023DocGen: Generating Detailed Parameter Docstrings in Python11 Nov 2023
- 2023Bias Testing and Mitigation in LLM-based Code Generation3 Sep 2023
- 2023An Exploratory Literature Study on Sharing and Energy Use of Language Models for Source Code5 Jul 2023
- 2023Type Prediction With Program Decomposition and Fill-in-the-Type Training25 May 2023
- 2023TypeT5: Seq2seq Type Inference using Static Analysis16 Mar 2023
- 2023LExecutor: Learning-Guided Execution5 Feb 2023
- 2022Cross-Domain Evaluation of a Deep Learning-Based Type Inference System19 Aug 2022
- 2024EffiBench: Benchmarking the Efficiency of Automatically Generated Codecited by 62
- 2023Bias Testing and Mitigation in LLM-based Code Generationcited by 53
- 2024EffiLearner: Enhancing Efficiency of Generated Code via Self-Optimizationcited by 28
- 2024MHPP: Exploring the Capabilities and Limitations of Language Models Beyond Basic Code Generationcited by 25
- 2025EffiBench-X: A Multi-Language Benchmark for Measuring Efficiency of LLM-Generated Codecited by 24
- 2023Deep Learning for Code Intelligence: Survey, Benchmark and Toolkitcited by 22
- 2024EffiCoder: Enhancing Code Generation in Large Language Models through Efficiency-Aware Fine-tuningcited by 15
- 2023TypeT5: Seq2seq Type Inference using Static Analysiscited by 12
- 2024Measuring the Influence of Incorrect Code on Test Generationcited by 9
- 2023LExecutor: Learning-Guided Executioncited by 7
- 2023Type Prediction With Program Decomposition and Fill-in-the-Type Trainingcited by 6
- 2025Treefix: Enabling Execution with a Tree of Prefixescited by 2
12 most cited of 17 All 17 (JSON)
- 2025Automated Type Annotation in Python Using Large Language Models1 Aug 2025
- 2025EffiBench-X: A Multi-Language Benchmark for Measuring Efficiency of LLM-Generated Code19 May 2025
- 2025Treefix: Enabling Execution with a Tree of Prefixes21 Jan 2025
- 2024EffiCoder: Enhancing Code Generation in Large Language Models through Efficiency-Aware Fine-tuning14 Oct 2024
- 2024Measuring the Influence of Incorrect Code on Test Generation14 Sep 2024
- 2024Inferring Pluggable Types with Machine Learning21 Jun 2024
- 2024EffiLearner: Enhancing Efficiency of Generated Code via Self-Optimization24 May 2024
- 2024MHPP: Exploring the Capabilities and Limitations of Language Models Beyond Basic Code Generation19 May 2024
- 2024EffiBench: Benchmarking the Efficiency of Automatically Generated Code3 Feb 2024
- 2023Deep Learning for Code Intelligence: Survey, Benchmark and Toolkit30 Dec 2023
- 2023DocGen: Generating Detailed Parameter Docstrings in Python11 Nov 2023
- 2023Bias Testing and Mitigation in LLM-based Code Generation3 Sep 2023
12 newest of 17 All 17 (JSON)