All models

NeuralInvariantRanker

A three-layer fully connected network that transforms text embeddings to rank LLM-generated loop invariants.

Language · 49 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 (24 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
7.1M
Operations
49
Framework
PyTorch
Recurrent
No
Published
Findings of EMNLP 2023
Cited by
2 (as of 29 October 2026)
Authors
Saikat Chakraborty, Shuvendu K. Lahiri, Sarah Fakhoury and others
License
MIT
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
m18860
Graph hash
6fc6842714ed5c3006781094b13aa5ea5c483819524e7975657ad597f4fe52ca
Skeleton hash
db3402fa154d26038784ed7715008eeb8d79a4efc43c16c134db464a9ead80bd
Architecture hash
beee7534aaf72191a6f378a6d9d3ecbfc178ba312754ba09e59dfd01614f0b7b
Diagram SHA-256
a50c33f466ac41d6051a2698fc3f432914bbb3acfcf4023392035d982a19a4e4
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

NeuralInvariantRanker, called iRank in the paper, ranks the loop invariants that a large language model proposes for a program, by how likely each is to be correct. A loop invariant is a fact that holds on every iteration of a loop, and verifying a program with loops comes down to finding one. The paper observes that language models can write well-formed invariants but often need many samples before one is correct. The ranker reorders the candidates so that the likely correct ones reach the verifier first.

The problem and each candidate invariant are first embedded by an existing embedding model, and a three-layer fully connected network then transforms those embeddings. Training is contrastive: the absolute cosine similarity between problem and invariant is pushed toward 1 for a correct invariant and toward 0 for a wrong one. With text-embedding-ada-002 embeddings, the hidden size is 1536.

On invariants generated by gpt-3.5, the paper reports that re-ranking moves the median rank of the verified invariant to 4, against an expected median rank of 31. The embeddings without training did not help: the paper finds no statistically significant difference between ranking by raw embeddings and the expected rank. Ranking is done by a purely neural model and needs no program verifier at inference time.

Key idea. The paper trains a contrastive ranker over LLM embeddings that places verified loop invariants ahead of incorrect ones, reducing the number of calls to the verifier.

  • NeuralInvariantRanker
  • iRank
  • loop invariant ranking
  • loop invariants
  • program verification
  • contrastive ranker
  • LLM-generated invariants
  • re-ranking
  • invariant synthesis

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

Cite the paper

@misc{chakraborty2024rankingllmgeneratedloopinvariants,
      title={Ranking LLM-Generated Loop Invariants for Program Verification}, 
      author={Saikat Chakraborty and Shuvendu K. Lahiri and Sarah Fakhoury and Madanlal Musuvathi and Akash Lal and Aseem Rastogi and Aditya Senthilnathan and Rahul Sharma and Nikhil Swamy},
      year={2024},
      eprint={2310.09342},
      archivePrefix={arXiv},
      primaryClass={cs.PL},
      url={https://arxiv.org/abs/2310.09342}, 
}