Introduction
This article serves as a continuation of the previous work titled “Predicting Chemical Reactions: Template-Based and Template-Free Approaches”, in which the two primary strategies for predicting chemical reaction products were introduced. Expanding upon that article, this second focuses on the interpretability, and practical usability of the template-free approaches that are developed with GNN-based, and Transformer-based models. To provide a broader perspective, comparisons with the prediction interpretability of semi-template approaches (product prediction using reaction template and GNN) were also included.
To illustrate the capabilities and limitations of these approaches prediction interpretability, a case study using a sample reaction from the USPTO dataset (the same reaction used in the previous work, see reaction SMILES in Figure 2) is presented. The goal of this article is to give the reader a comprehensive understanding of how different template-free methods perform in terms of explainability when applied to the task of chemical product prediction.
GNN Prediction
When it comes to teaching Artificial Intelligence (AI) about chemistry, representing molecules as graphs can be a powerful idea because a molecule is represented like a social network: atoms are the people (nodes), and bonds are the relationships (edges) connecting them. This structure is a perfect fit for graph neural networks (GNNs), a type of model designed to pass information along such connections in a process called message passing. In a molecular graph, each atom shares and updates its state based on the atoms it is bonded to.
Instead of just feeding the AI a list of atoms, GNNs allow models to learn chemical reactivity from connectivity and context. By treating molecules as graphs, we give AI models a view of chemistry that is more reflective of real chemical behavior.
Fig.1 presents an example output from a GNN-based model. The model not only predicts the main product but also other elements can be predicted in the process, such as potential by-products and the most likely reaction site (i.e., the part of the molecule where the transformation is expected to occur). The predicted output is based on the model’s learned understanding of molecular structure and reactivity patterns. The overall method is valuable when the chemistry becomes complex or unconventional because the model can propose plausible products and reaction sites.
Fig.1 An example of chemical reaction product prediction with a GNN-based model (i.e., DGL-LifeSci). A reaction from the USTPO dataset was selected randomly and it is shown in the upper part. The trained GNN predicts product, reaction site and by-products. The atoms highlighted in red represent the most likely reaction site and the predicted bond change. DGL-LifeSci was trained on the USPTO dataset, which includes the tested reaction, explaining its accurate prediction.
Created by Author
GNN Interpretability
The essential aspect of explainability in graph-based models is their ability to localize the reaction site. This is typically achieved through a ranking model trained to assign probabilities to each atom and bond change, indicating how likely they are to participate in the reaction. This enables chemists to trace the logic behind the predicted product by revealing which parts of the molecule are most “active" in the prediction.
However, interpretability isn't without its challenges:
- Symmetrical atoms: In molecules with chemically equivalent atoms (i.e., meaning they have the same bonding environment and reactivity), the model might highlight just one reactive site. While this can appear inconsistent, it still leads to the correct product. This reveals a limitation in interpretability, not accuracy. A possible improvement is to consider both local and global reactivity patterns, helping resolve ambiguity when multiple equivalent sites exist.
- Multi-reactive systems: In more complex molecules with several non-equivalent reactive sites, the model may struggle to distinguish the primary site. Without additional context (e.g., solvent, temperature, or catalyst), it might assign moderate probabilities to several atoms, leading to diffuse or indecisive predictions.
GNN Key Advantages for Interpretability
One major advantage of GNN in reaction prediction is their built-in permutation invariance. In reactions like A + B → C, the input order (A then B, or B then A) is irrelevant. Traditional models often need specially formatted inputs, but GNNs—by design—treat all permutations of a molecular graph identically.
This symmetry-aware design aligns perfectly with the nature of chemistry, where reactivity depends on bonding and how electrons are distributed, not the input order. This makes them well-suited for chemical processes without being distracted by irrelevant input orderings, making them both more robust and more chemically intuitive.
Transformer Prediction
After exploring how GNNs learn reactivity from molecular graphs, attention can be turned to another approach that treats chemistry as a form of language. In this method, molecules are represented not as graphs but as character strings such as SMILES, SMARTS, etc.
This shift to using string-based representations opens the door for the application of language models, particularly Transformers. These models learn to recognize patterns in sequences, such as how certain reactants tend to transform under specific conditions.
To make this possible, tokens in chemical strings are converted into embedding vectors (i.e., dense representations that capture chemical meaning based on context, much like how words in a sentence gain meaning from their surroundings. Here, the Transformer updates the meaning (embedding) of each token by considering the entire reaction sequence (e.g., the full reaction SMILES string). This means it doesn’t just focus on local patterns, but instead learns how different parts of the reaction influence each other, capturing complex dependencies, such as how distant atoms or groups influence each other’s reactivity.
In our example (Figure 2), the model recognizes a Grignard-type reaction and infers the expected transformation pattern, the formation of a carbon–carbon bond. This shows how Transformers can integrate reaction type recognition and outcome prediction in one step offering a tool for chemical reasoning from a text-based input. When trained on large datasets, Transformer models effectively become large language models (LLMs) for chemistry that are capable of interpreting reaction sequences and generating chemically reasonable outcomes.
Fig.2 Learning reaction patterns with a Transformer-based LLM. What is showcased here is not mere pattern matching, but the application of learned chemical reasoning.
Created by Author
Transformer Interpretability
To better understand how Transformer-based models make predictions, we can look into their internal mechanism, specifically, the attention weights. These are numerical values that indicate which parts of the input the model focuses on when making a prediction. In the context of chemical reactions, attention scores can be extracted and visualized to identify which atoms or tokens the model considers most influential during the prediction process.
The idea is that the regions that receive the highest attention often align with chemically meaningful features, such as an electrophilic carbon in a carbonyl group or a leaving group in a substitution reaction. In this way, the model not only generates plausible outcomes but also offers insight into the rationale behind its decisions, providing a window into its learned chemical reasoning.
To illustrate this idea, Figure 3 shows a reaction input SMILES format along with the predicted product. Below the prediction, a heatmap visualizes the average attention weights from the last layer of the model across all attention heads. This allows us to trace which parts of the input were critical for predicting each part of the output. For example, the decoder token ‘ccc’ shows the highest attention to the encoder token ‘CCOC' (score: 0.0395; highlighted by the green box in heatmap), indicating that the model associated this part of the input with that specific fragment of the predicted product.
Fig.3 Visualization of attention weights in a Transformer model for a sample chemical reaction. The model assigns higher attention to chemically relevant tokens, reflecting its learned understanding of reaction mechanisms. Special characters such as ‘.’, ‘▁’ were omitted from the visualization for clarity.
Created by Author
Limitations of Interpretability in Transformer Models
While Transformer-based models show strong predictive performance in chemistry, they also present important interpretability challenges. A key limitation stands from the tokenization of SMILES strings, which is not chemically informed. Chemically meaningful substructures may be split into arbitrary tokens, reducing the interpretability of the learned representations.
In the example shown in Figure 3, attention weights were extracted from the last decoder layer to identify the most attended input tokens. Figure 4 presents a ranking of these tokens to explore their contribution to the prediction. By manually grouping tokens associated with each reactant (delimited by dots in SMILES), it is possible to reconstruct their approximate structures. However, even with these reconstructed fragments, it remains difficult to infer specific chemical transformations, such as bond formations or atom pairings from attention scores alone.
For trained chemists, the mechanism may be inferred from context and chemical intuition, but for non-experts, the connection between input and prediction remains incomprehensible.
For the case studied, one of the reconstructed reactants corresponds to the predicted reactive site identified in the GNN output, while the other appears to be a by-product. Without guidance from the GNN or explicit structural cues, however, the roles of these fragments in the reaction are difficult to determine, highlighting the limited interpretability of Transformer-based predictions.
Another issue arises from the handling of chirality. The largest reactant, which is also the one receiving the highest attention, corresponds to one of the reactants of the original reaction in the Figure 1, yet the SMILES representation lacks inherent recognition of chirality or symmetry. The same occurs for the predicted product shown in Figure 3 versus the true product in Figure 1. To ensure that a Transformer handles stereochemically accurate reactants and products, it must be trained on isomeric SMILES that explicitly encode stereochemistry (e.g., using @ or @@ symbols). Standard Transformer models do not account for molecular symmetry or chirality unless augmented with strategies such as reactant order permutation or symmetry-aware training. Without such enhancements, predictions may suffer from inconsistencies or reduced generalization across differently ordered but chemically equivalent inputs.
Fig.4 Ranking and structural interpretation of the most-attended encoder tokens.This figure shows the encoder tokens that received the highest cumulative attention across all decoder tokens in the final decoder layer. Attention scores were aggregated by looping over each decoder token and summing the attention values assigned to each encoder token (excluding non-chemical tokens such as ‘▁’, ‘.’, ‘(‘, ‘)’, ‘[‘, ‘]’). To interpret the prediction, the most-attended tokens were manually grouped based on reactant separation (using dots in SMILES format) and used to reconstruct approximate input structures. While this reconstruction provides some interpretability, it does not explicitly reveal which bonds form or break, limiting interpretability for non-experts.
Created by Author
Methods to Extend Interpretability of Predictions
To enhance the interpretability of predictions made by the Transformer-based model, we propose additional chemical analyses beyond attention score visualization. Building on the example in Figure 4, we used a Chemprop-based tool developed by the Momiyama Research Group to predict the chemical reactivity to identify the role (either electrophile or neutrophile) of the reconstructed structures derived from the most-attended encoder tokens. Since the tool estimates key reactivity parameters nucleophilicity and electrophilicity, it is required to consider all the reactants that can behave either as nucleophile or electrophile. Both the reconstructed structures and reactants are listed in Table 1. The counterion Cl- is skipped since its role in the reaction is to maintain electroneutrality.
The third molecule (C1CCOC1) in Table 1 is a solvent that can dissolve the other two molecules in the table (CC(C[Mg+])C and C1(C(N(OC)C)=O)C=NC(O)=CC=1), without reacting with either compound. Thus, attention can be drawn to the other molecules.
First, we compared the variances of Nu and El for CC(C[Mg+])C and C1(C(N(OC)C)=O)C=NC(O)=CC=1. The difference in variance is greater for CC(C[Mg+])C (12.040), making it a more distinct case for further analysis. In this molecule, the variance of Nu (1.905) is much smaller than that of El, which strongly indicates that CC(C[Mg+])C functions primarily as a nucleophile. In contrast, for C1(C(N(OC)C)=O)C=NC(O)=CC=1, the difference in Nu and El variance is around 2.3, suggesting ambivalent behavior (i.e., it may act as either a nucleophile or an electrophile) depending on the nature of the reaction partner. However, in this specific context, where CC(C[Mg+])C acts as a nucleophile, C1(C(N(OC)C)=O)C=NC(O)=CC=1 is likely functioning as an electrophile. With this analysis, chemists can infer the reaction sites being C15 and C6. However, such a task remains challenging for the non-expertise.
In summary, this kind of property-driven analysis can serve as a valuable complement to attention-based interpretations, helping to confirm the chemical roles of key reactants in the predicted product. However, it also underscores a broader limitation: interpreting Transformer predictions requires extensive post-processing and manual intervention, such as reconstructing molecular fragments from string tokens, extracting/reacting attention weights, and deciding reaction sites from the perspective of organic synthesis by expertise. Compared to the more mechanistically grounded outputs of GNNs, interpretability in Transformers is more indirect and labor-intensive.
Table 1. Prediction of reactivity parameters nucleophilicity and electrophilicity of the two reactants that contain the most-attended encoder tokens in the Transformer prediction result.
Semi-Template Prediction
A more comprehensive framework for chemical reaction prediction is offered by hybrid approaches that combine generalized reaction templates with GNNs. One such method is the semi-template approach, which not only predicts the reactive site and mechanism (as GNNs do) but also outputs a generalized reaction template, offering an additional layer of interpretability. For this section, we applied LocalTransform to the same example reaction analyzed earlier. As shown in Figure 5, the predicted generalized template aligns well with the reaction site identified by its built-in GNN, just as in Figure 1. It is worth noting that LocalTransform makes use of DGL library for molecular graphs (which is the same as in DGLl-fe-Sci), explaining the accurate prediction on both the product and reaction site. The key takeaway from this comparison, as highlighted in Figure 5, is how different modeling approaches offer varying levels and forms of interpretability.
Interestingly, the predicted reaction site given by the semi-template method aligns well with the reaction site analysis done with the tool developed by Momiyama group. It can be concluded that for interpretability purposes, the reaction site analysis and prediction can be considered.
In summary, the semi-template approach offers a compelling balance between accuracy and interpretability by combining the predictive power of GNNs with the mechanistic clarity of generalized reaction templates. In the example studied, it not only correctly identified the reaction site in agreement with the GNN model but also achieved a perfect product prediction due to alignment with the training data. However, further testing is required to confirm its accuracy for reactions involving novel chemistry or underrepresented reactant classes, even when using generalized reaction templates.
Fig.5 Comparison of interpretability across three different approaches for chemical product prediction. GNN: The predicted reaction site is directly highlighted in red, offering clear insight into the model's prediction mechanism. Semi-template (generalized reaction template + GNN): A predicted generalized reaction template is used to infer the reaction center, with reactive sites also highlighted in red. This approach benefits from both structural templates and graph-based reasoning. Transformer: Interpretability is achieved through manual extraction of encoder tokens with the highest attention weights. These tokens are used to reconstruct partial molecular structures, providing indirect insight into the model’s focus during prediction.
Created by Author
Conclusions
In this article, we explored the interpretability of three distinct approaches for chemical product prediction: GNN, Transformer, and Semi-template methods. GNNs offer intuitive interpretability by explicitly predicting reaction centers, enabling direct visualization of reactive atoms and clear mechanistic understanding. Transformer-based models, while powerful in capturing global context and reaction complexity, suffer from limited inherent interpretability due to non-chemically informed tokenization and require additional manual effort to extract meaningful insights via attention scores. The Semi-template approach provides enhanced interpretability by predicting both the reactive site and the transformation pattern. However, its dependence on known reaction templates might limit generalization beyond the training set. Together, these findings highlight that while all methods can achieve accurate predictions, their levels of interpretability, ease of insight extraction, and generalizability vary, making them suitable for different stages and needs in reaction modeling.
References
- Coley, C. W.; Jin, W.; Rogers, L.; Jamison, T. F.; Jaakkola, T. S.; Green, W. H.; Barzilay, R.; Jensen, K. F. A Graph-Convolutional Neural Network Model for the Prediction of Chemical Reactivity. Chem. Sci. 2018, 10 (2), 370–377. https://doi.org/10.1039/c8sc04228d.
- Li, M.; Zhou, J.; Hu, J.; Fan, W.; Zhang, Y.; Gu, Y.; Karypis, G. DGL-LifeSci: An Open-Source Toolkit for Deep Learning on Graphs in Life Science. ACS Omega 2021, 6 (41), 27233–27238. https://doi.org/10.1021/acsomega.1c04017.
- Sagawa, T.; Kojima, R. ReactionT5: A Large-Scale Pre-Trained Model towards Application of Limited Reaction Data. arXiv 2023. https://doi.org/10.48550/arxiv.2311.06708.
- Ucak, U. V.; Ashyrmamatov, I.; Lee, J. Improving the Quality of Chemical Language Model Outcomes with Atom-in-SMILES Tokenization. J. Cheminformatics 2023, 15 (1), 55. https://doi.org/10.1186/s13321-023-00725-9.
- Chen, S.; Jung, Y. Deep Retrosynthetic Reaction Prediction Using Local Reactivity and Global Attention. JACS Au 2021, 1 (10), 1612–1620. https://doi.org/10.1021/jacsau.1c00246.
- Chen, S.; Jung, Y. A Generalized-Template-Based Graph Neural Network for Accurate Organic Reactivity Prediction. Nat. Mach. Intell. 2022, 4 (9), 772–780. https://doi.org/10.1038/s42256-022-00526-z.
- Yoshikai, Y.; Mizuno, T.; Nemoto, S.; Kusuhara, H. Difficulty in Chirality Recognition for Transformer Architectures Learning Chemical Structures from String Representations. Nat. Commun. 2024, 15 (1), 1197. https://doi.org/10.1038/s41467-024-45102-8.
- Schwaller, P.; Laino, T.; Gaudin, T.; Bolgar, P.; Hunter, C. A.; Bekas, C.; Lee, A. A. Molecular Transformer: A Model for Uncertainty-Calibrated Chemical Reaction Prediction. ACS Cent. Sci. 2019, 5 (9), 1572–1583. https://doi.org/10.1021/acscentsci.9b00576.
- Tetko, I. V.; Karpov, P.; Deursen, R. V.; Godin, G. State-of-the-Art Augmented NLP Transformer Models for Direct and Single-Step Retrosynthesis. Nat. Commun. 2020, 11 (1), 5575. https://doi.org/10.1038/s41467-020-19266-y.
- Zhang, Y.; Wang, L.; Wang, X.; Zhang, C.; Ge, J.; Tang, J.; Su, A.; Duan, H. Data Augmentation and Transfer Learning Strategies for Reaction Prediction in Low Chemical Data Regimes. Org. Chem. Front. 2021, 8 (7), 1415–1423. https://doi.org/10.1039/d0qo01636e.
- Momiyama Lab. Chemical Reactivity Prediction App. 2023. Retrieved June 3, 2025. (Review only)