Matching-while-Decoding: Enhancing Template-Free Retrosynthesis via Explicit Structural Alignment

Kaipeng Zeng, Jiarui Shen, Yi Jiang, Shiyue Wang, Lin Yao, Tong Zhu, Junchi YanNeurIPS 2026

TL;DR

When chemists synthesize a new molecule, most of the molecular structure stays intact from start to finish—only a few bonds actually change. Yet, many generative AI models for chemistry treat this process like translating a sentence from scratch, ignoring the obvious structural overlap. MatchRetro fixes this by forcing a neural network to explicitly point back to the exact atom in the target molecule it is "copying" as it generates the starting ingredients, delivering top-tier accuracy and much higher chemical reliability.

What Problem Does This Paper Address?

Imagine trying to figure out the recipe for a Lego castle just by looking at the finished build. This is retrosynthesis—working backward from a target molecule (like a promising new drug) to find the simpler chemical ingredients (reactants) needed to make it in a single reaction step.

Early AI models relied on rigid libraries of known reaction rules ("templates"), which fail whenever chemistry gets creative outside the rulebook. Newer "template-free" models ditch the rules and treat chemistry like machine translation: they encode the target molecule and decode the reactants as SMILES strings—a clever text notation that flattens 3D molecular graphs into 1D sequences of letters and symbols.

Here’s the catch: in real-world organic chemistry, reactions are local. Most of the molecular scaffold is preserved between reactants and products. Standard sequence generators ignore this fundamental truth, regenerating the entire reactant string from thin air. Previous researchers tried to help models notice the overlap by carefully ordering the text sequences to look as similar as possible. However, flattening a complex graph into text is brittle; one tricky ring-opening reaction and the text sequences look completely different, causing the model to lose track of which atom went where.

Methods

Instead of hoping the model implicitly notices text similarities, the authors introduce MatchRetro and a paradigm called Matching-while-Decoding. Using a graph-to-sequence architecture, the model reads the product as a 2D molecular graph (via a standard graph encoder, $\text{EGAT}^+$) and writes the reactants as a SMILES sequence—but with a twist. For every single token it generates, it must also explicitly state its provenance (where it came from).

Figure 1: Overview of MatchRetro a) Example of explicit structural alignment. b) Visual illustration of the causal mask for parallel training. c) Pipeline of hierarchical autoregressive generation.

At each decoding step, MatchRetro runs a hierarchical conditional cascade:

  1. Semantic Prediction: First, a Transformer decoder predicts the next SMILES token (e.g., a Carbon atom 'C' or a syntax bracket '(').
  2. Origin Check (Leaving Group Classification): If it’s a syntax symbol, it gets a null tag ($-1$). If it’s a physical atom, a binary classifier asks: Was this atom absent from the final product? (Chemists call atoms discarded during a reaction leaving groups, tagged here as $-2$).
  3. Structural Matching: If the atom * did* survive into the final product, a matching network links it directly to its exact corresponding node in the input product graph.

To keep track of both where an atom came from in the graph and when it appeared in the text without scrambling the signals, the decoder uses dual-positional representations: additive embeddings for spatial graph origins, and Rotary Position Embeddings (RoPE) for sequence order.

Normally, a multi-step cascade like this would break the fast, parallel training that makes Transformers great, because step 2 needs to peek at the answer to step 1 without cheating on future steps. The authors solve this with a custom causal attention mask, concatenating two versions of the sequence ("posed" with structural tags, and "raw" without) so the entire cascade trains cleanly in a single parallel pass.

Datasets

No new benchmarks were introduced. The model is pre-trained on non-reaction molecular data (graph-to-SMILES translation) to learn basic chemical syntax, and then fine-tuned and evaluated on three standard public retrosynthesis benchmarks derived from US patent literature:

  • USPTO-50K (~50,000 reactions)
  • USPTO-MIT
  • USPTO-FULL (the largest, noisy, full-scale benchmark)

Key Insights and Ideas

  • Resolving the Augmentation Trade-off: In SMILES-based AI, a common trick is Test-Time Augmentation (TTA)—feeding the model multiple randomized text variations of the same molecule at test time and pooling the answers. Surprisingly, existing models suffer a stark trade-off: some require TTA to perform well (collapsing on standard "canonical" inputs), while strong graph-aligned models actually get worse when TTA is applied. Because MatchRetro ties randomized text sequences back to deterministic graph indices, it gets the best of both worlds: rock-solid baseline accuracy that smoothly scales up when given extra TTA compute.
  • Exact-Match Isn't Everything: Chemistry has multiple valid routes to the same destination. Even when MatchRetro misses the exact reactants written in the patent, its predictions are frequently chemically valid alternatives, outperforming peers when checked by an independent forward-reaction AI oracle.
  • Chirality Wins: Explicit node-matching helps the decoder preserve tricky 3D atomic handedness (chirality) better than pure sequence models by grounding generation in the local graph neighborhood.

Key Results

MatchRetro establishes a premier balance of accuracy and chemical plausibility across benchmarks:

  • USPTO-MIT: Sets new state-of-the-art records across all augmented metrics, hitting 61.1% Top-1 and 87.6% Top-10 accuracy (and 86.3% Top-10 even without TTA).
  • USPTO-FULL (with TTA): Achieves state-of-the-art deeper recall at 68.3% Top-3, 73.2% Top-5, and 77.8% Top-10—crucial metrics because synthesis-planning algorithms expand multiple candidate branches rather than trusting just one guess.
  • USPTO-50K: Reaches 91.2% Top-10 canonically (best among template-free models) and 92.6% Top-10 with TTA.
Table 3: Top-k round-trip accuracy on USPTO- 50K. *: TTA. Bold: best; underlined: second best.
  • Chemical Feasibility (Round-Trip Accuracy): When predicted reactants are fed back into a forward-synthesis oracle (Molecular Transformer) to see if they actually yield the target product, MatchRetro beats all evaluated baselines across every threshold on USPTO-50K, scoring 81.8% Top-1 and 63.2% Top-10.

Limitations and Future Work

The authors highlight two honest trade-offs:

  1. Sensitivity to Bad Labels: Because MatchRetro learns via explicit structural supervision, it relies heavily on accurate atom-to-atom mapping annotations in the training data, making it less forgiving of noisy datasets than unsupervised methods.
  2. Compute Overhead: Predicting both a token and its structural provenance effectively doubles the sequence length during training and increases the output work per step during inference.

(Specific future work directions beyond serving as an engine for multi-step synthesis planning are not explicitly detailed in the main text, though addressing graph encoder blind spots—like directional double-bond $E/Z$ stereochemistry—is noted via their error analysis).

Summary updated

Abstract

Single-step retrosynthesis prediction serves as the core operational unit for automated synthesis planning and remains a fundamental computational challenge in pharmaceutical design. While a critical prior in organic chemistry is that chemical reactions typically preserve the majority of the molecular scaffold, current template-free deep learning models struggle to effectively exploit this characteristic. Existing methods attempt to exploit this by minimizing sequence-level edit distance through carefully chosen graph traversal orders. However, this structural correspondence is only indirectly induced and remains highly sensitive to imperfect traversal heuristics, which limits its effectiveness for complex transformations. To address this limitation, we introduce the Matching-while-Decoding paradigm, replacing implicit sequence alignment with direct structural supervision. We operationalize this paradigm within a graph-to-sequence architecture that explicitly maps generated reactant tokens back to the input product graph during decoding. Furthermore, our hierarchical autoregressive formulation utilizes a custom causal attention mask to enable highly efficient, single-pass parallel training. Extensive experiments across the USPTO-50K, USPTO-MIT, and USPTO-FULL benchmarks reveal a critical accuracy and robustness trade-off in existing methodologies, where models either over-rely on augmentation or fail to leverage it. Our approach uniquely resolves this bottleneck by delivering highly competitive canonical accuracy while scaling exceptionally well with test-time augmentation, establishing new state-of-the-art records on USPTO-MIT and augmented USPTO-FULL. By providing this balanced stability across diverse inference protocols, our approach emerges as a highly promising foundation for dependable single-step retrosynthesis prediction.
BibTeX
@inproceedings{zeng2026matching,
  author = {Kaipeng Zeng and Jiarui Shen and Yi Jiang and Shiyue Wang and Lin Yao and Tong Zhu and Junchi Yan},
  title = {{Matching-while-Decoding: Enhancing Template-Free Retrosynthesis via Explicit Structural Alignment}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=uh3Ctp0Yfw},
}
Figure