All models

TypeT5

A CodeT5-based model that fills in Python type annotations using context chosen by static analysis.

Language · 1,466 operations Checked

100%

Showing the top corner; full diagram not loaded yetShowing a small copy; full diagram not loaded yetLarge diagram, not loaded yet

Open SVG

Loading diagram (62 KB)

Open in a new tab

Click or tap a spot to read it up close. Scroll or drag inside the diagram to move through it. Zoom with + and − or Ctrl and scroll. Press 0 for the whole graph. Swipe inside the diagram to move through it. Use + and − to zoom.

At a glance

Parameters
222.9M
Operations
1,466
Framework
PyTorch
Recurrent
No
Published
ICLR 2023
Cited by
4 (as of 28 October 2026)
Authors
Jiayi Wei, Greg Durrett, Isil Dillig
License
BSD-3-Clause
Checked
Passed: the trace was replayed operation by operation and matched the model's own output for this input.

Files

The diagram is a drawing of a TorchLens trace of the source code. It contains no code or weights.

Details
Stable ID
m21093
Graph hash
cee28da714b8c27bc3b1eceb53d5bcf5a69ac4def006f907b86312719438f25f
Skeleton hash
fb9db3c096168d1e61637653a5ad5a0a77555f869eb16dd536fb2e83966c517e
Architecture hash
61e2ad020608e7d7ddbe952998c545b6b2782da94f0e3a47a2dfbdc4688f8286
Diagram SHA-256
e9c557d23e9fc07354de5e63ecec4b1b7249fdc2b55fc8e317e364f0fe1dd3df
TorchLens version
2.36.0
Renderer
graphviz 2.43.0+pyvips 3.2.0+libvips 8.18.7+render-opts@06c1f0d3
Check
Forward pass replayed in PyTorch

What it is

TypeT5 predicts missing type annotations in Python code by treating type prediction as a code infilling task. The network is a fine-tuned CodeT5, a Transformer sequence-to-sequence model. The paper notes that earlier methods were accurate on the most common types but often performed poorly on rare or complex ones.

Marker tokens are inserted where a type is wanted, and the model outputs the token sequence that encodes the types for the marked locations. Static analysis decides what else the model reads: it builds a usage graph, whose nodes are code elements and whose edges are direct usages, and TypeT5 uses that graph to construct the model's input. The paper limits the total input to 4096 subword tokens.

At inference TypeT5 decodes iteratively, traversing the usage graph twice and adding type signatures from its own predictions to the context, with the second pass in the reverse direction of the first. The paper reports higher overall accuracy than the systems it compares with, particularly on rare and complex types, and fewer type errors. The experiments use the BetterTypes4Py dataset, and the repository says training takes about 11 hours on a single Quadro RTX 8000 GPU.

Key idea. TypeT5 casts type inference as code infilling with CodeT5, uses static analysis to build each prediction's context, and decodes iteratively so earlier type predictions inform later ones.

  • typet5
  • type inference
  • python type inference
  • type annotation prediction
  • type prediction
  • code infilling
  • static analysis
  • seq2seq type inference

AI-written summary, based on the paper and checked automatically against it; not reviewed by a person. Corrections welcome.

Cite the paper

@misc{wei2023typet5seq2seqtypeinference,
      title={TypeT5: Seq2seq Type Inference using Static Analysis}, 
      author={Jiayi Wei and Greg Durrett and Isil Dillig},
      year={2023},
      eprint={2303.09564},
      archivePrefix={arXiv},
      primaryClass={cs.SE},
      url={https://arxiv.org/abs/2303.09564}, 
}