All models

GrammarT5

T5-style encoder-decoder for code that represents programs as tokenized grammar rule sequences.

Language · 791 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 (11 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
61.5M
Operations
791
Framework
PyTorch
Recurrent
No
Published
ICSE 2024
Cited by
14 (as of 3 November 2026)
Authors
Qihao Zhu, Qingyuan Liang, Zeyu Sun and others
License
Apache-2.0
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
m17099
Graph hash
b9dbbb7589c63f63c41f37f3dd76279569149610ada17667a69a837d0dd172d5
Skeleton hash
193f8fe25eb605de21c7e7bcedc55677e11ddd041e43b10c3db8d78b6a34ea8f
Architecture hash
36ec7505bf95447f5ffc5365348e5c18f69a9df5694bd952690f137e64373b4a
Diagram SHA-256
64056989230aeaa27867989d361f18932c47c49edd9ce7abc394d9319edbcbe2
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

GrammarT5 is a pretrained encoder-decoder model for programming languages that reads and writes code as grammar rules instead of a plain token sequence. Its authors argue that representing programs as token sequences leaves the syntactic structure implicit, which can hurt the understanding of that structure and permit syntactically incorrect code.

The representation is called Tokenized Grammar Rule Sequence (TGRS), a variant of the grammar rule sequence that integrates BPE sub-tokens. A language flag is attached to the non-terminals of each programming language so that grammar rules are not shared across languages, which the authors found leads to higher performance than a combined grammar. Two new pretraining tasks teach the tree structure: Edge Prediction has the decoder predict parent nodes step by step, and Sub-Tree Prediction masks several sub-trees in the AST and has the model regenerate them.

The model is built on the PyTorch implementation of T5 and follows the configuration of CodeT5. The paper implements two sizes, GrammarT5-small (60M) and GrammarT5-base (220M), both trained from scratch. Pretraining used maximum source and target lengths of 512 and 256. On MBPP, a Python program synthesis dataset, the paper reports that GrammarT5-base outperforms CodeT5-base by 9.2 points.

Key idea. GrammarT5 pretrains a T5-style encoder-decoder on Tokenized Grammar Rule Sequences, with language flags and two tree-aware tasks, Edge Prediction and Sub-Tree Prediction, so the model learns code syntax.

  • GrammarT5
  • grammar-integrated pretrained model
  • pretrained model for code
  • Tokenized Grammar Rule Sequence
  • TGRS
  • code generation
  • code summarization
  • code translation
  • syntax-guided code generation
  • encoder-decoder for code

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

Cite the paper

@inproceedings{Zhu_2024, series={ICSE ’24}, title={GrammarT5: Grammar-Integrated Pretrained Encoder-Decoder Neural Model for Code}, url={http://dx.doi.org/10.1145/3597503.3639125}, DOI={10.1145/3597503.3639125}, booktitle={Proceedings of the IEEE/ACM 46th International Conference on Software Engineering}, publisher={ACM}, author={Zhu, Qihao and Liang, Qingyuan and Sun, Zeyu and Xiong, Yingfei and Zhang, Lu and Cheng, Shengyu}, year={2024}, month=Apr, pages={1–13}, collection={ICSE ’24} }