betaFeedback

WorksComputer Science

DiffER2^2: Diffusion Ensembles for Retrosynthesis Prediction with SMILES Adapted Particle Guidance

Abstract

Computational retrosynthesis prediction has the potential to reduce development time for newly discovered drugs by automatically generating potential reactions for a target product. Data-driven approaches commonly treat this as a sequence-to-sequence generation task on SMILES strings. In this work, we construct ensembles of discrete-time and continuous-time diffusion models for molecular generation and incorporate guidance mechanisms for improved output diversity. We propose an adaptation of particle guidance to SMILES sequence generation which significantly improves the number of unique molecules generated by diffusion ensembles while increasing top-k accuracy. These results further expand the efficacy of discrete diffusion for SMILES generation, and our empirical analyses offer new insights into the capabilities of diffusion models for chemical retrosynthesis.

Introduction

The goal of retrosynthesis is to construct reactant molecules that can be used to synthesize a target product. Retrosynthesis prediction constitutes a pivotal step in the drug manufacturing pipeline. Repeatedly applying single-step retrosynthesis models to a given problem can result in full synthetic pathway discovery (Segler et al. [45]; Shen et al. [47]), further supporting pharmaceutical advancement for new drug modalities. However, even single-step retrosynthesis prediction is difficult, in part due to the diversity of reactant sets that might map to a single product. While forward synthesis prediction is primarily considered a surjective process with a deterministic output, retrosynthesis prediction is in many ways the opposite, with many possible outputs resulting from a single input. As a result, researchers have taken a particular interest in deep learning methods that hasten the process of retrosynthesis discovery by quickly and efficiently predicting multiple possible reactant sets from a given product molecule.

Numerous methodologies have been developed, from template-based methods that use mined reaction mechanisms to predict reactants to template-free approaches that directly predict string or graph representations of reactant molecules conditioned on the target product. The most successful of these template-free approaches use traditional transformer encoder-decoder architectures on SMILES (Weininger (1988)) string representations of the molecules, effectively treating the problem as a

Preprint. Under review. machine translation task ([69]). A recent approach, DiffER ([12]), explored the usage of discrete diffusion models for the retrosynthesis task and provided evidence that an ensemble of discrete-time diffusion models could be a practical approach for sampling from the posterior distribution of reactants. Differ outperformed the state-of-the-art R-SMILES ([69]) at top-1 accuracy on the commonly used USPTO-50k dataset ([34]), but suffered from low output diversity due to the nature of posterior sampling.

In this work, we extend upon the work of DiffER ([12]) by adapting their approach to include continuous-time discrete diffusion models and applying classifier-based particle guidance ([10]) to SMILES string generation. Both of these changes aim to improve the efficacy and output diversity of models over the original DiffER. A visual overview of the DiffER2^{2} ensemble approach is presented in Figure 1. The main improvements on the original DiffER methodology are as follows:

Overview of the DiffER² ensemble

Figure 1. Overview of the DiffER2^{2} ensemble. The DiffER2^{2} ensemble contains both continuous-time (C-DiffER) and discrete-time (DiffER) models to leverage differing capabilities between the two diffusion archetypes. Both normal sampling methods and SMILES adapted particle guidance are used to generate output. Output SMILES are ranked according to frequency of the canonical form. DiffERκ_{\kappa} indicates the value of κ\kappa as described in § 3.2.

  1. We incorporate continuous-time discrete diffusion models into the DiffER ensemble to leverage different capabilities of discrete-time and continuous-time diffusion.

  2. We explore the efficacy of SMILES-adapted guidance mechanisms to further enhance the diversity and accuracy of diffusion models for chemical retrosynthesis.

  3. Finally, we offer an in-depth exploration into the differing performance capabilities of auto-regressive and discrete-space diffusion models on the chemical retrosynthesis task.

By combining both continuous-time and discrete-time diffusion models with classifier-based particle guidance ([10]), we significantly improve ensemble performance and reduce oversampling of posterior peaks while maintaining or boosting top-k accuracy across the board. Our results enhance the efficacy of diffusion ensembles for SMILES generation while providing an empirical analysis of diffusion performance compared to auto-regressive approaches for sequence generation.

Related Work

Retrosynthesis Prediction

Data-driven models for retrosynthesis prediction are commonly divided into three approaches: template-based, semi-template, and template-free methods. Common template-based approaches include GLN ([13]) and LocalRetro ([6]). These approaches primarily focus on identifying locations in a molecule where reaction templates can be applied and ranking the efficacy and feasibility of those templates on the target area. Semi-template methods include the likes of GraphRetro ([50]), G2^{2}Retro ([7]), and GDiffRetro ([55]). These approaches generally work in a two-step manner: in the first step, a reaction center is first predicted from the product molecule, and the molecule is subsequently split into synthons. In the second step, each synthon is completed to construct a final reactant molecule. Notably, GDiffRetro ([55]) uses discrete-time diffusion processes to complete predicted synthons. Finally, template-free methods such as Chemformer ([27]), MEGAN (Sacha et al., 2021), R-Smiles [69], and DiffER [12] directly construct reactant molecules from the product molecule. This is most often done in a sequence-to-sequence manner using SMILES strings [27, 69, 12], though some approaches directly operate on graphs, such as the case of MEGAN [39], which iteratively builds the reactant molecule(s) through a series of edits. DiffER [12] is the first approach to use conditional discrete diffusion to accomplish the retrosynthesis prediction task, although their methodology suffers from reduced output diversity and high computational cost compared to auto-regressive decoding strategies. We primarily focus on template-free methods for performance comparison.

Discrete-Space Diffusion

Generative diffusion models have been a significant topic of research in recent years, and have achieved significant success in the realms of image generation [11, 65] and signal processing [65]. Though diffusion models traditionally operate in the continuous regime [49, 51, 52, 24, 40, 20, 67], significant effort has been made extending diffusion models to discrete spaces [25, 2, 17, 18, 21, 66, 14, 16]. Discrete-space models have demonstrated remarkable performance for molecular generation [61, 1, 26, 62, 43] and protein design (Gruver et al., 2023; Watson et al., 2022; Ni et al., 2023), but have struggled to out-compete their auto-regressive counterparts on discrete sequence generation. Furthermore, most work in this space has primarily focused on discrete-time diffusion. Only recently has discrete-space diffusion been extended to continuous-time implementations [5, 68, 63], which demonstrate improved modeling capabilities and sampling efficiency compared to their discrete-time parallels. Furthermore, incorporating recent advances in guidance mechanisms during diffusion sampling [3, 33, 15, 23] remains a challenge, due to the difficulty of applying gradient-based approaches on a discrete domain [41, 19]. Schiff et al. [41] recently adapted classifier-free and classifier-based guidance mechanisms for discrete diffusion and demonstrated promising results on molecular generation tasks, though more work needs to be done constructing and evaluating guidance mechanisms for discrete diffusion tasks.

Methods

Following the original DiffER [12], we treat retrosynthesis prediction as a discrete sequence-to-sequence generation task, where the target product is a conditional input to the diffusion generation akin to text-to-image models. We employ both discrete-time and continuous-time diffusion models. Like DiffER, we incorporate length prediction strategies to improve diffusion sampling as well as enable robust model ensembling. Finally, we adapt classifier-based particle guidance [10] to SMILES sequence generation to improve output diversity and reduce over-sampling of posterior peaks. By applying our techniques to SMILES generation, we are able to offer direct comparisons to prior works, and more clearly demonstrate the effectiveness of our diffusion ensembling and guidance methodologies. However, we recognize the existence of other molecular string representations such as SELFIES [30]. We offer a comparison to a SELFIES-based implementation of our work in Appendix A.4.

Preliminaries

Following the notation of Zhao et al. [68], let x0∼pdata(x0)x_0 \sim p_{\mathrm{data}}(x_0) be a categorical random variable representing the observed data with discrete distribution pdata(x0;K)p_{\mathrm{data}}(x_0; K). Let xt∼q(xt)x_t \sim q(x_t) be the latent variable at time t∈[0,1]t \in[0, 1] (continuous-time, max⁡t=T\max t = T) or xt∈{0,…,T}x_t \in\{0, \ldots, T\} (discrete-time) and xt∣s∼q(xt∣xs)x_{t\mid s} \sim q(x_t\mid x_s) be the conditional random variable. Let xt1:Lx∈{0,1}Lx×Kx_t^{1:L_x} \in\{0, 1\}^{L_x \times K} be a sequence of length LxL_x at time tt, and let xt[ℓ]x_t^{[\ell]} be the sequence indexed at position ℓ\ell. We assume each discrete random variable is governed by a categorical distribution C\mathcal{C} with probability distribution p∈[0,1]Kp \in[0,1]^K, where ∥p∥1=1\lVert p\rVert_1 = 1, such that xt∼C(xt;p)x_t \sim\mathcal{C}(x_t; p). Furthermore, let Qt∣s∈[0,1]K×KQ_{t\mid s} \in[0,1]^{K \times K} represent the transition matrix between times ss and tt, such that [Qt∣s]ij=q(xt=ei∣xs=ej)[Q_{t|s}]_{ij}=q(x_t=e_i|x_s=e_j), where ei,ej∈{0,1}Ke_i,e_j\in\{0,1\}^{K} are one-hot encoded vectors.

In the forward diffusion process, noise is added to observed data until it is indistinguishable from a stationary noise distribution. Zhao et al. [68] show that the forward diffusion process for discrete-time and continuous-time diffusion can be unified into a single forward diffusion process defined by the accumulated transition matrix Qˉt∣s\bar{Q}_{t|s}, with t>st>s:

Qˉt∣s=αˉt∣sI+(1−αˉt∣s)1m⊤,(1)\bar{Q}_{t|s}=\bar{\alpha}_{t|s}I+(1-\bar{\alpha}_{t|s})\mathbf{1}m^{\top}, \tag*{(1)}

where mm is a known probability distribution vector such that xT∼C(xT;m)x_T\sim\mathcal{C}(x_T;m), 1\mathbf{1} is vector of 1s, and αˉt∣s\bar{\alpha}_{t|s} is the accumulated noise schedule between time tt and time ss.

In the backward diffusion process, diffusion models aim to generate samples from pθ(xs∣xt)p_{\theta}(x_s|x_t) for some 0<s<t≤T0<s<t\leq T. This is commonly accomplished by taking pθ(xs∣xt)≈q(xs∣xt,x0)p_{\theta}(x_s|x_t)\approx q(x_s|x_t,x_0), where q(xs∣xt,x0)q(x_s|x_t,x_0) is the ss-step posterior distribution [25, 2]. Because x0x_0 is unknown, it is approximated by training a neural network model ftθf_t^\theta such that pθ(x0∣xt)=C(x0;ftθ(xt))p_{\theta}(x_0|x_t)=\mathcal{C}(x_0;f_t^\theta(x_t)). Thus, pθ(xs∣xt)p_{\theta}(x_s|x_t) can be estimated by sampling xs∼q(xs∣xt,ftθ(xt))x_s\sim q(x_s|x_t,f_t^\theta(x_t)). Analytically, this can be calculated as

q(xs∣xt,ftθ(xt))=C(xs;Qˉt∣sxt⊙Qˉt⊤ftθ(xt)xt⊤Qˉt⊤ftθ(xt)).(2)q(x_s|x_t,f_t^\theta(x_t))=\mathcal{C}\left(x_s;\frac{\bar{Q}_{t|s}x_t\odot\bar{Q}_t^{\top}f_t^\theta(x_t)}{x_t^{\top}\bar{Q}_t^{\top}f_t^\theta(x_t)}\right). \tag*{(2)}

This posterior calculation can be further reduced to simplify computation [68], which we follow in our work as well. We refer readers to Zhao et al. [68] for a more detailed overview of the unified diffusion methodology.

The primary point of difference between discrete-time and continuous-time diffusion models now lies in the loss functions. We train both continuous-time and discrete-time diffusion models using the simplified variational lower bound loss functions provided by Zhao et al. [68] alongside a cross-entropy loss.

DiffER Adapted Unified Diffusion

DiffER [12] incorporates the target product as an additional constraint to the diffusion generation process, akin to text-to-image generative diffusion models. Let y01:Ly∈{0,1}Ly×Ky_0^{1:L_y}\in\{0,1\}^{L_y\times K} be the target product sequence associated with the reactant sequence x01:Lxx_0^{1:L_x}. Here, both y0y_0 and x0x_0 are SMILES strings representing molecular structures, with x0x_0 containing one or more concatenated reactant SMILES. Because the target product is known in retrosynthesis prediction, the diffusion problem can be parameterized such that

pθ(x0∣xt,y0)=C(x0;ftθ(xt,y0)).(3)p_{\theta}(x_0|x_t,y_0)=\mathcal{C}(x_0;f_t^\theta(x_t,y_0)). \tag*{(3)}

This formulation guides the diffusion process by incorporating the target product as an additional input to the model. Here, ftθf_t^\theta usually takes the form of an encoder-decoder model, where the encoder processes y0y_0 and the decoder acts as the diffusion component on xtx_t.

Notably, one issue remains in that the length of the reactant sequence LxL_x is unknown a priori, which is necessary to properly instantiate xT∼C(xT;m)x_T\sim\mathcal{C}(x_T;m). Inspired by MaskPredict [16], DiffER [12] incorporates a length prediction component into the encoder half of ftθf_t^\theta, such that LxL_x can be estimated using some model fℓϕ:{0,1}L×K→RLf_\ell^\phi:\{0,1\}^{L\times K}\to\mathbb{R}^{L}, so that Lx≈arg⁡max⁡fℓϕ(y0)L_x\approx\arg\max f_\ell^\phi(y_0), where LL is an arbitrary maximum sequence length such that Lx<LL_x<L and Ly<LL_y<L for all x0,y0x_0,y_0 in the data distribution. For the chemical retrosynthesis task, LxL_x and LyL_y are often highly correlated: thus, to encourage active learning, fℓϕf_\ell^\phi is instead trained to predict the difference between LxL_x and LyL_y, i.e.,

Lx=Ly+(arg⁡max⁡fℓϕ(y0)−Γ),(4)L_x=L_y+\left(\arg\max f_\ell^\phi(y_0)-\Gamma\right), \tag*{(4)}

where Γ<L\Gamma<L is a sufficiently large constant allowing fℓϕf_\ell^\phi to effectively predict negative length changes. In practice, we set Γ=L2\Gamma=\frac{L}{2}, noting that the change in length will never be larger than half of the product sequence.

Current et al. [12] show experimentally that if fℓϕf_{\ell}^{\phi} is a perfect length-prediction model, then discrete-time diffusion outperforms all other methodologies for top-1 predictions by a significant margin, exhibiting that sequence length information can be highly informative when predicting reactant SMILES. However, the authors note that in practice, fℓϕf_{\ell}^{\phi} cannot be sufficiently trained to accomplish such a notable performance increase due to 1.) the distribution of (Lx−Ly)(L_x-L_y) is heavily biased, 2.) the SMILES encoding of a molecule can produce sequences of varying length, forcing fℓϕ(y0)f_{\ell}^{\phi}(y_0) to learn a one-to-many mapping, and 3.) accurate length prediction requires complex understanding of chemical reagents, molecular reactivity, and molecular structure, and is itself a nontrivial problem.

To remedy problems 1. and 2., DiffER (Current et al. [12]) randomly appends Lp∼U{1,κ}L_p \sim\mathcal{U}\{1,\kappa\} padding tokens to the SMILES representations of reactants, where κ\kappa is a set hyperparameter. This padding procedure smooths the distribution of (Lx−Ly)(L_x-L_y) and allows flexibility in the output size of generated reactants. A detailed overview of this procedure is provided in Appendix § 7.§ 1. To reduce reliance on the choice of κ\kappa, DiffER trains multiple diffusion models ftθκf_t^{\theta_\kappa} with different κ\kappa, producing an ensemble of models which generate possible reactants. This approach provides better coverage of the posterior distribution than a single model. We follow this same approach, but additionally incorporate continuous-time models and classifier-based guidance sampling into the ensemble.

SMILES Adapted Particle Guidance for Chemical Generation

Aside from the incorporation of continuous-time diffusion models into the DiffER methodology and the formalization of said methodology, our other primary motivation of this work is to explore the usage of classifier-based guidance mechanisms on the DiffER ensemble models to improve output diversity. Classifier-based guidance steers diffusion sampling toward a specific classification cc by sampling from a tempered distribution pγ(xs∣c,xt)∝p(c∣xs)γpθ(xs∣xt)p^\gamma(x_s|c,x_t) \propto p(c|x_s)^\gamma p_\theta(x_s|x_t), where pθ(xs∣xt)p_\theta(x_s|x_t) is the diffusion model, p(c∣xs)p(c|x_s) is a classifier, and γ\gamma is the temperature parameter (Schiff et al. [41]):

log⁡pγ(xs∣c,xt)=γlog⁡p(c∣xs,xt)+log⁡p(xs∣xt).(5)\log p^\gamma(x_s|c,x_t)=\gamma\log p(c|x_s,x_t)+\log p(x_s|x_t). \tag*{(5)}

Schiff et al. [41] formalize classifier-based guidance for discrete-space diffusion specifically, with the assumption that pγ(xs∣c,xt)p^\gamma(x_s|c,x_t) factorizes independently across tokens. We follow their work to apply classifier-based guidance to our models.

SMILES Adapted Particle Guidance

One of the primary limitations of employing diffusion models for highly conditioned molecular generation tasks lies in the over-sampling of posterior peaks ([12, 55]), resulting in reduced diversity and number of unique generated molecules. To this end, we take inspiration from Corso et al. [10] to encourage greater output diversity during sampling through guidance. Corso et al. apply the gradient of a potential function log⁡Φt(xt(1),xt(2),…,xt(n))\log\Phi_t(x_t^{(1)},x_t^{(2)},\ldots,x_t^{(n)}) to encourage greater output diversity, where xt(i)x_t^{(i)} are independent samples from the diffusion model at time tt. The potential function is constructed such that higher scores are given to distant point pairs:

log⁡Φt(xt(1),xt(2),…,xt(n))=αˉt2∑i,jK(xt(i),xt(j)),(6)\log\Phi_t(x_t^{(1)},x_t^{(2)},\ldots,x_t^{(n)})=\frac{\bar{\alpha}_t}{2}\sum_{i,j}\mathcal{K}(x_t^{(i)},x_t^{(j)}), \tag*{(6)}

where K\mathcal{K} is a pairwise similarity kernel. Furthermore, the potential function is weighted by the noise schedule αˉt\bar{\alpha}_t such that the guidance effect is stronger at earlier timesteps rather than later ones. Unfortunately, it is non-trivial to construct a differentiable similarity kernel between noised SMILES strings due to the non-singular nature of SMILES representations: the same molecule may be represented by many different SMILES sequences of various atom orderings.

To remedy this, we construct the potential function such that it maximizes the probability that Xt={xt(1),xt(2),…,xt(n)}X_t=\{x_t^{(1)},x_t^{(2)},\ldots,x_t^{(n)}\} are noisy variants of different molecules. Let m0(i)m_0^{(i)} be the molecular form of the denoised sequence x0(i)x_0^{(i)}. Then we aim to maximize the probability

⋃i≠jp(m0(i)≠m0(j)∣xt(i),xt(j))=∏i≠jp(m0(i)≠m0(j)∣xt(i),xt(j)),(7)\bigcup_{i\ne j}p(m_0^{(i)}\ne m_0^{(j)}|x_t^{(i)},x_t^{(j)})=\prod_{i\ne j}p(m_0^{(i)}\ne m_0^{(j)}|x_t^{(i)},x_t^{(j)}), \tag*{(7)}

which factors as a result of the independence of generated SMILES. Taking the log, we can construct the potential function as

log⁡Φt(Xt)=∑i≠jlog⁡p(m0(i)≠m0(j)∣xt(i),xt(j)).(8)\log\Phi_t(X_t)=\sum_{i\ne j}\log p(m_0^{(i)}\ne m_0^{(j)}|x_t^{(i)},x_t^{(j)}). \tag*{(8)}

We train a classifier to estimate p(m0(i)≠m0(j)∣xt(i),xt(j))p(m_0^{(i)} \ne m_0^{(j)} \mid x_t^{(i)}, x_t^{(j)}). Recognizing that the parameterized diffusion model ftθf_t^\theta is already trained to produce an estimate of the de-noised sequences, we train an additional classifier fKΦf_K^\Phi to detect if x^0,t(i)=ftθ(xt(i))\hat{x}_{0,t}^{(i)} = f_t^\theta(x_t^{(i)}) and x^0,t(j)=ftθ(xt(j))\hat{x}_{0,t}^{(j)} = f_t^\theta(x_t^{(j)}) represent the same denoised molecular structure, i.e.,

p(m0(i)≠m0(j)∣xt(i),xt(j))=fKΦ(x^0,t(i),x^0,t(j))=(fKΦ∘ftθ)(xt(i),xt(j)).(9)p(m_0^{(i)} \ne m_0^{(j)} \mid x_t^{(i)}, x_t^{(j)}) = f_K^\Phi(\hat{x}_{0,t}^{(i)},\hat{x}_{0,t}^{(j)}) = (f_K^\Phi\circ f_t^\theta)(x_t^{(i)},x_t^{(j)}). \tag*{(9)}

This parameterization results in the final potential function

log⁡Φt(Xt)=∑i≠jlog⁡((fKΦ∘ftθ)(xt(i),xt(j))).(10)\log\Phi_t(X_t) = \sum_{i \ne j} \log\left((f_K^\Phi\circ f_t^\theta)(x_t^{(i)},x_t^{(j)})\right). \tag*{(10)}

Applying Potential Functions via Classifier-based Guidance

Rather than using this potential function directly, we instead construct a classifier on xt(i)x_t^{(i)} alone, recognizing that applying the classifier individually for all xt(i)∈Xtx_t^{(i)} \in X_t reproduces the potential function:

log⁡pΦ(⟦m^0,t(i)∉M^t/{m^0,t(i)}⟧∣xt(i),Xt)=∑j≠ilog⁡((fKΦ∘ftθ)(xt(i),xt(j))).(11)\log p_\Phi(\llbracket\hat{m}_{0,t}^{(i)} \notin\hat{M}_t/\{\hat{m}_{0,t}^{(i)}\}\rrbracket\mid x_t^{(i)},X_t) = \sum_{j \ne i} \log\left((f_K^\Phi\circ f_t^\theta)(x_t^{(i)},x_t^{(j)})\right). \tag*{(11)}

Here, m^0,t(i)\hat{m}_{0,t}^{(i)} is the molecular form of x^0,t(i)\hat{x}_{0,t}^{(i)}, M^t\hat{M}_t is the set of molecules {m^0,t(1),…,m^0,t(n)}\{\hat{m}_{0,t}^{(1)}, \ldots, \hat{m}_{0,t}^{(n)}\} associated with XtX_t, and I\mathbb{I} is the indicator function. For the sake of clarity, we will refer to I[m^0,t(i)∉M^t/{m^0,t(i)}]\mathbb{I}[\hat{m}_{0,t}^{(i)} \notin\hat{M}_t/\{\hat{m}_{0,t}^{(i)}\}] as the guidance class cc. We add the further stipulation that if x^0,t(i)\hat{x}_{0,t}^{(i)} is not a valid SMILES string or if m^0,t(i)\hat{m}_{0,t}^{(i)} is not a valid molecule, then the indicator function defaults to False.

We finalize our guidance strategy by follow the approach of Schiff et al. [41] to apply classifier guidance to discrete sequences. This results in the posterior estimate

log⁡pΦ,θγ(xs∣c,xt)=∑ℓ=1Llog⁡(pΦ(c∣x~)γpθ(xs[ℓ]∣xt)∑x~pΦ(c∣x~)γpθ(xs[ℓ]∣xt)).(12)\log p_{\Phi,\theta}^\gamma(x_s \mid c,x_t) = \sum_{\ell=1}^{L} \log\left(\frac{p_\Phi(c\mid\tilde{x})^\gamma p_\theta(x_s^{[\ell]}\mid x_t)}{\sum_{\tilde{x}}p_\Phi(c\mid\tilde{x})^\gamma p_\theta(x_s^{[\ell]}\mid x_t)}\right). \tag*{(12)}

where x~=[xt1:ℓ−1,xsℓ,xtℓ+1:L]\tilde{x}=[x_t^{1:\ell-1},x_s^\ell,x_t^{\ell+1:L}] is the sequence such that x~\tilde{x} and xtx_t are equal at all positions ℓ′≠ℓ\ell' \ne\ell and x~\tilde{x} and xsx_s are equal at position ℓ\ell. We set γ=αˉt\gamma=\bar{\alpha}_t to weight the guidance effect similarly to Equation (6). Finally, we use the first-order Taylor approximation of log⁡pΦ\log p_\Phi to efficiently compute the classifier pΦ(c∣x~)p_\Phi(c\mid\tilde{x}) using only a single forward pass (Schiff et al., [41]):

log⁡pΦ(c∣x~)=(x~−xt)⊤∇xtlog⁡pΦ(c∣xt)+log⁡pΦ(c∣xt).(13)\log p_\Phi(c\mid\tilde{x}) = (\tilde{x}-x_t)^\top\nabla_{x_t}\log p_\Phi(c\mid x_t) + \log p_\Phi(c\mid x_t). \tag*{(13)}

We refer readers to Schiff et al. [41] for detailed proofs of this result.

Training and implementation details for fKΦf_K^\Phi are provided in Appendix § 7.§ 2. During inference, fKΦf_K^\Phi is incorporated in a manner reminiscent of reinforcement learning, allowing the model to learn and adapt throughout the diffusion process.

Experiments

Experimental Setup. We train and test our models on the USPTO-50K dataset (Lowe, [34]), a commonly used set of patented reactions that provides SMILES strings for both reactants and products and widely regarded as the benchmark dataset for retrosynthesis prediction. Reaction solvents are not included in the retrosynthesis task. Each pair of products and reactants is augmented 20 times according to Zhong et al. [69], producing a final dataset of 1M root-aligned SMILES pairs. We use the augmented train, validation, and test sets provided by Zhong et al.1

The DiffER2^2 ensemble contains eight individually trained diffusion models, depicted in Figure 1. Each model shares the same network architecture, differentiated only by the diffusion parameters and padding augmentation described in § 3.2. Four of the diffusion models follow the original DiffER training (Current et al., [12]) with losses adjusted according to Zhao et al. [68]: these models operate in discrete-time with padding parameter κ∈{20,40,60,80}\kappa\in\{20, 40, 60, 80\}. The remaining four models operate in continuous-time, each paralleling their discrete-time counterparts with a padding parameter κ∈{20,40,60,80}\kappa\in\{20, 40, 60, 80\}. Further details on model architecture are provided in Appendix § 7.§ 3. Models which include particle guidance described in § 3.3 are denoted DiffER2^{2}PG and DiffER2^{2}PG+. In DiffER2^{2}PG, guidance sampling is run instead of the standard sampling procedure. In DiffER2^{2}PG+, guidance sampling is run alongside standard sampling procedures, resulting in an output distribution that combines DiffER2^{2} and DiffER2^{2}PG.

Evaluation Metrics. We evaluate our models using standard top-kk accuracy metrics. The DiffER2^{2} ensemble is run on each product in the test set and generated reactants are ranked by frequency, with the most generated reactant having the highest ranking. The top-kk accuracy is defined as the proportion of reactions in which the ground-truth reactant is in the top-kk ranks. Top-kk accuracy is reported for k∈{1,3,5,10}k \in\{1, 3, 5, 10\}. We compare the DiffER2^{2} ensemble with a wide range of template-based, semi-template, and template-free methods for retrosynthesis prediction. However, we primarily focus on comparing performance against other template-free methods. In addition to top-kk accuracy, we include results for round-trip accuracy using a forward synthesis model in Appendix § 7.§ 5 and provide a case study on a ring-forming reaction in the main results and three other reactions in Appendix § 7.8.

Property-Specific Performance Analysis. We additionally analyze how model performance compares against various structural properties of the SMILES sequences to better understand model performance. These properties include the target length difference between product and reactant SMILES, the edit distance between product and reactant SMILES, if the target reaction is ring adding/ring removing, and the number of branches in the target SMILES, each detailed in Appendix § 7.7. For each property, we calculate the slope and significance of a regression between the property statistic and the top-kk accuracy. In addition to these results, we report the performance of DiffER2^{2}PG across different reaction types in Appendix § 7.§ 6. We analyze how different molecular structures correlate with model performance in Appendix § 7.9. Finally, we analyze the attention maps for a non-ensemble diffusion model in Appendix § 7.10.

Results

Top-K accuracies for the DiffER2^{2} ensemble are reported in Table 1. DiffER2^{2}PG+ achieves the best top-1, top-3, and top-5 (statistically tied with R-SMILES) among template-free models and the second-best top-10 accuracy behind R-SMILES [69]. R-SMILES achieves the best top-5 and top-10 performance, but lags behind DiffER2^{2}PG+ for k=1,3k = 1, 3. DiffER2^{2}PG+ may better estimate posterior peaks for SMILES sequences than R-SMILES, but it still struggles to sample from lower probability regions in the posterior. This result is paralleled in GDiffRetro [55], a semi-template method that utilizes diffusion sampling techniques. GDiffRetro achieves remarkable k=1k = 1 accuracy, the highest of all baseline models, but struggles to produce strong results for higher values of kk compared to other methods. Sun et al. [55] suggest this may be due to the oversampling of posterior peaks, which is also observed in our models. By employing an ensemble of diffusion models and incorporating SMILES-adapted particle guidance, DiffER2^{2}PG+ can mitigate some of

CategoryModelK=13510
Template-basedGLN [13]52.569.075.683.7
Template-basedLocalRetro [6]53.477.585.992.4
Semi-templateRetroPrime [58]51.470.874.0_76.1_
Semi-templateG²Retro [7]_53.9__74.6__80.7_86.6
Semi-templateGDiffRetro [55]58.979.181.9-
Template-freeMEGAN [39]48.170.778.486.1
Template-freeR-SMILES [69]56.379.286.291.0
Template-freeDiffER [12]_57.6_79.084.187.4
Template-freeDiffER²_57.6__79.5_85.3{sup}†`88.2
Template-freeDiffER²PG57.479.485.4{sup}†`88.6{sup}†`
Template-freeDiffER²PG+57.779.8_86.1{sup}†`__89.9{sup}†`_

Table 1. Top-K accuracy for a select set of baseline models. A full table of results can be found in Appendix A.4. The best performing model in each category is bolded, while the second-best performing model is underlined. A † indicates results that are statistically significant from DiffER at the 95% level.

this bias and provide greater coverage of the posterior, as evidenced by our stronger performance for k>1k > 1 compared to GDiffRetro. Compared to the original DiffER [12], the DiffER² ensembles all achieve stronger results than the discrete-time only ensemble, particularly for higher values of kk. This suggests that including continuous-time models greatly improves the diversity of output reactants. Notably, there is minimal difference between all DiffER methodologies for top-1 accuracy, indicating that the location of posterior peaks for the various ensembles may be similar, but that the shape of the distribution for lower probability samples is different. Interestingly, the top-kk performances of DiffER² and DiffER²PG are remarkably similar despite the latter ensemble producing more reactants.

Figure 2 shows box plots of the unique reactants generated by each ensemble for products in the test set. The greater number of unique molecules produced by DiffER²PG indicates that the SMILES-adapted particle guidance methodology does result in greater output diversity and reduced sampling of posterior peaks. The combined result of DiffER²PG+ has an even greater number of unique molecules, indicating that the difference between sample sets generated from DiffER² and DiffER²PG is substantial. Notably, this result may be impacted by the limited number of samples taken from each model in the ensemble, which may not reflect the full posterior distribution for each model. Regardless, DiffER²PG is an effective approach to improving output diversity while maintaining comparable performance to DiffER². This is desirable because multiple reactants could produce the same product, thus validating accuracy, and output diversity is critical. Like Current et al. [12], we observe that fewer molecules are sampled when the top-1 result is accurate, indicating that the models still over-sample from posterior peaks to the deficit of output diversity. However, these effects are lessened compared to DiffER.

Box plot showing the number of unique molecules produced by the various DiffER² ensembles

Figure 2. Box plot showing the number of unique molecules produced by the various DiffER2^{2} ensembles. "K=1 is False" indicates reactions that do not have an accurate top-1 reactant. "K=1 is True" indicates reactions that do have an accurate top-1 reactant. "Overall" includes all reactions.

Case Study. A case study on an N-heterocyclization reaction with dihalides for the DiffER²PG+ ensemble is presented in Figure 3. Additional case studies are presented in Appendix § 7.8. The target reaction is a reaction of a primary amine with a dihalide in an alkaline aqueous medium to form a heterocyclic ring [28]. While the ensemble model predicts this reaction, it is only predicted 4% of the time, making it the third most frequently predicted reaction. The top-ranked predicted reaction is a Borch reductive amination [4] in which a carbonyl group is reacted with a secondary amine in the presence of a reducing agent to produce a tertiary amine. Unfortunately, due to the presence of multiple carbonyl groups in the predicted reactant, this reaction will likely produce unwanted byproducts. The second-ranked reaction is a substitution reaction with a mesylate ester and a secondary amide nucleophile. Again, this reaction does produce the desired product, but may produce byproducts due to the electrophilicity of the carbamate group, which may react with the amine nucleophile.

Case study on an N-heterocyclization reaction with dihalides

Figure 3. Case study on a N-heterocyclization reaction with dihalides. From left to right: the source product, the ground-truth reactant(s), and the top-3 predicted reactant(s) for the DiffER2^{2}PG+ ensemble. Red highlighting indicates differences between the source product and the reactants. The value in parentheses indicates the rate at which the reactant(s) are produced by the ensemble.

To recap, all three top-ranked reactions could be used to form the target product, but only the 3rd reaction, which matches the ground truth, would limit the creation of byproducts. Notably, this reactant is not produced by the original DiffER ensemble (Current et al. [12]), demonstrating that DiffER2^{2}PG+ significantly improves output diversity to benefit performance. In this case study, as well as those presented in Appendix § 7.8, DiffER2^{2}PG+ demonstrates significant capability to predict reactants that could be used to produce the desired product, though some reactions may be suboptimal due to the possibility of undesirable side products. Thus, while the models can learn appropriate reaction mechanisms and patterns, the predicted forward reaction’s purity may not be considered by the models. Future work should consider approaches that include reducing the possibility of side products as an objective. Furthermore, ambiguity in the optimality of reactants could be mitigated by providing additional guidance to the model in a human-in-the-loop setting.

Property Results. Figure 4 shows the results of the property-specific performance analysis described in § 4 for top-1 accuracy, with additional results available in Appendix § 7.7. These results highlight substantial differences in the capabilities of DiffER2^{2}PG+ and R-SMILES. DiffER2^{2}PG+ is significantly more capable at predicting reactant SMILES with a larger increase in sequence length than the auto-regressive model. This result also helps explain the increased capability of diffusion models to predict ring-removing reactions, as these are often reactions with a high increase in sequence length. This difference in capability can be understood via the attention maps for the diffusion models: rather than building up the sequence token-by-token like an auto-regressive model, the diffusion models work backward, attending to the full-sequence length in early layers then decreasing the attended length as the model goes deeper (see Appendix § 7.10). Thus, diffusion models may be "less inclined" to produce shorter sequences.

Lines of best fit between top-k accuracy and reactant properties

Figure 4. Lines of best fit between top-k accuracy and reactant properties for the DiffER2^{2}PG+ and R-SMILES (Zhong et al. [69]) models. All slopes are significantly different from 0 (p<0.01p < 0.01) except Edit Distance.

In contrast, diffusion models seem less capable of modeling ring-adding reactions than auto-regressive models, though this difference is only significant for k>1k > 1. Both models have a negative association with the edit distance between product and reactant SMILES, except for top-1 accuracy, in which DiffER2^{2}PG+ has no significant relationship with the edit distance. This suggests that some reactions with large edits remain "easy" for DiffER2^{2}PG+ to predict. Both models struggle to generate sequences with highly non-sequential behavior, as evidenced by the negative relationship between performance and branch count. Overall, DiffER2^{2}PG+ outperforms R-SMILES conditioned on all properties except for ring-adding reactions.

Conclusion

In this work, we introduce SMILES-adapted particle guidance to encourage output diversity in diffusion models for SMILES generation on the chemical retrosynthesis task. Combining this guidance mechanism with the ensemble approach of DiffER [12], we can significantly increase the number of unique molecules generated while improving top-kk accuracy metrics on benchmark datasets. Furthermore, we offer an in-depth empirical analysis on the capabilities and limitations of discrete diffusion for SMILES generation compared to traditional auto-regressive approaches. In future work, we aim to investigate additional guidance methods for SMILES diffusion models to reduce byproducts and explore applications of rectified linear flows for SMILES generation.

Reproducibility

We detail all model architectures and hyperparameters used to produce DiffER2^{2} in Appendix § 7.§ 3. We follow the methods outlined in § 3 and Appendix § 7.§ 2 alongside the experimental setup in § 4 to train and evaluate our models. All code used to produce the results of DiffER2^{2} will be made publicly available.

Appendix

Details on DiffER's Padding Procedure

During training, DiffER [12] randomly appends padding tokens to the SMILES representations of reactants. The target reactant sequence x01:Lxx_0^{1:L_x} is randomly padded on the right by a sequence of padding tokens with random length, such that

x0′=[x01:Lx,ep1:Lp] and xt∼q(xt∣x0′),(14)x_0' = \left[x_0^{1:L_x}, e_p^{1:L_p}\right] \text{ and } x_t \sim q(x_t|x_0'), \tag*{(14)}

where epe_p is the one-hot encoder vector of the pad token and Lp∼U{1,κ}L_p \sim U\{1,\kappa\}, with U{1,κ}U\{1,\kappa\} being the discrete uniform distribution between 1 and some constant κ>1∈N\kappa> 1 \in\mathbb{N}. The choice of κ\kappa allows the diffusion model to strike a balance between effective length prediction with ftϕf_t^\phi and allowing ftθf_t^\theta to determine the sequence length by predicting padding tokens during sampling.

We can show that the variant padding methodology is in effect a moving average kernel on the distribution of (Lx−Ly)(L_x-L_y) with width κ\kappa. Let Lx−y∈[−L/2,L/2]L_{x-y} \in[-L/2,L/2] denote the difference (Lx−Ly)(L_x-L_y) with probability distribution Lx−y∼C(Lx−y;pℓ)L_{x-y} \sim\mathcal{C}(L_{x-y};p_\ell), where the probability vector pℓp_\ell is calculated from the training data distribution. Let Lx−y′∼C(Lx−y′;pℓ′)L'_{x-y} \sim\mathcal{C}(L'_{x-y};p'_\ell) represent the difference distribution after random padding with probability vector pℓ′p'_\ell, and let Pi∣j=P(Lx−y′=i∣Lx−y=j)P_{i|j}=P(L'_{x-y}=i|L_{x-y}=j) be the probability that a sequence pair with difference jj maps to a difference of ii for the padded sequence. Then

pℓi′=∑j=1LPi∣j⋅pℓj=1κ∑j=1LpℓjI[i−κ≤j<i]=1κ∑j=i−κi−1pℓj.(15)p'_{\ell i} = \sum_{j=1}^{L} P_{i|j}\cdot p_{\ell j} = \frac{1}{\kappa}\sum_{j=1}^{L}p_{\ell j}\mathbb{I}[i-\kappa\le j < i] = \frac{1}{\kappa}\sum_{j=i-\kappa}^{i-1}p_{\ell j}. \tag*{(15)}

Thus, pℓ′p'_\ell is a moving average of the previous κ\kappa indices of pℓp_\ell. In effect, the padding methodology reduces the heavy bias observed in the distribution of Lx−yL_{x-y} by smoothing the probability vector pℓp_\ell.

Training Details for Particle Guidance Model

Algorithm 1 Pseudocode for particle guidance sampling procedure.

Inputs: target product y0y_0, timesteps TT, number of samples NN, diffusion model encoder fencoderθf^\theta_{encoder}, diffusion model decoder fdecoderθf^\theta_{decoder}, noise schedule αˉt\bar{\alpha}_t

Output: Sampled reactants {x^0(1),x^0(2),…,x^0(N)}\{\hat{x}_0^{(1)},\hat{x}_0^{(2)},\ldots,\hat{x}_0^{(N)}\}

  1. for ii in 1 to NN do

  2. Initialize y0(i)=Augment⁡(y0)y_0^{(i)}=\operatorname{Augment}(y_0) according to Zhong et al.Zhong et al. [69]

  3. Initialize xT(i)=C(xT;m)x_T^{(i)}=\mathcal{C}(x_T;m) from noise distribution

  4. Compute encoder memory Hi=fencoderθ(y0(i))H_i=f^\theta_{encoder}(y_0^{(i)})

  5. end for

  6. for tt in TT to 1 do

  7. s=t−1s=t-1

  8. Let Xt={xt(1),xt(2),…,xt(n)}X_t=\{x_t^{(1)},x_t^{(2)},\ldots,x_t^{(n)}\}

  9. for ii in 1 to NN do

  10. Predict x^0(i)←fdecoderθ(xt(i),Hi,t)\hat{x}_0^{(i)} \leftarrow f^\theta_{decoder}(x_t^{(i)},H_i,t)

  11. Compute pΦ(c=1∣xt(i),Xt)p_\Phi(c=1|x_t^{(i)},X_t) according to equation 11

  12. Compute xs(i)x_s^{(i)} according to equations 12 and 13

  13. Update fKΦf^\Phi_K and fencoderθf^\theta_{encoder} using classifier loss (Binary Cross Entropy)

  14. end for

  15. end for

  16. x^0(i)←fdecoderθ(xt(i),Hi,t)\hat{x}_0^{(i)} \leftarrow f^\theta_{decoder}(x_t^{(i)},H_i,t)

  17. Return {x^0(1),x^0(2),…,x^0(N)}\{\hat{x}_0^{(1)},\hat{x}_0^{(2)},\ldots,\hat{x}_0^{(N)}\}

The guidance model fKΦf^\Phi_K is trained in a reinforcement learning paradigm during inference with no explicit pretraining. Recognizing that the encoder portion of the diffusion model fencoderθf^\theta_{encoder} is time-independent and already adept at recognizing molecular structure, we construct fKΦf^\Phi_K as an additional classification head following an fencoderθf^\theta_{\mathrm{encoder}}. Let Hi1:Li∈RLi×dH_i^{1:L_i} \in\mathbb{R}^{L_i \times d} be the hidden representation of a SMILES sequence x(i)∈{0,1}Li×Kx^{(i)} \in\{0,1\}^{L_i \times K} with hidden size dd and length LiL_i obtained from the encoder model, i.e., Hi1:Li=fencoderθ(x(i))H_i^{1:L_i}=f_{\mathrm{encoder}}^\theta(x^{(i)}). Let H(i)=1Li∑ℓ=1LiHi[ℓ]H^{(i)}=\frac{1}{L_i}\sum_{\ell=1}^{L_i}H_i^{[\ell]} be the hidden representation average over the sequence length. The classifier model is constructed as a function of the difference between the mean hidden representations for strings x(i),x(j)x^{(i)},x^{(j)} along the sequence length:

fKΦ(x(i),x(j))=σ(ΦT(H(i)−H(j))),(16)f_{\mathrm{K}}^{\Phi}(x^{(i)},x^{(j)})=\sigma\left(\Phi^{\mathsf{T}}\left(H^{(i)}-H^{(j)}\right)\right), \tag*{(16)}

where Φ∈Rd\Phi\in\mathbb{R}^{d} are the model parameters. By averaging over the sequence length LiL_i to construct H(i)H^{(i)}, we help remove the effect of sequence ordering on the classification. This is desirable due to non-singular nature of SMILES representations.

During inference, we train fKΦf_{\mathrm{K}}^{\Phi} in a manner akin to reinforcement learning. Note that fKΦf_{\mathrm{K}}^{\Phi} is not explicitly pretrained aside from the encoder model fencoderθf_{\mathrm{encoder}}^\theta. We allow both the classifier weights Φ\Phi and the encoder weights θencoder\theta_{\mathrm{encoder}} to be optimized during sampling. Note that because the encoder model is only run once at the beginning of sampling, changing the weights of fencoderθf_{\mathrm{encoder}}^\theta during future sampling steps does not directly affect the overall diffusion model ftθf_t^\theta. Pseudocode for the joint training/sampling procedure for fKΦf_{\mathrm{K}}^{\Phi} is provided in algorithm 1.

Details on Model Architectures and Diffusion Parameters

All models in the DiffER2^2 ensembles take the form of standard encoder-decoder transformers with 6 layers, 8 attention heads, a latent size of 512, a feed-forward layer of size 2048, and GeLU activation Hendrycks & Gimpel [22]. All models are trained using an Adam optimizer with learning rate 0.0001 and a dropout rate of 0.1 for 90 epochs. Both discrete-time and continuous-time models are trained using a log-linear noise schedule and are sampled over 100 diffusion timesteps. All models are trained on a single Nvidia A6000 GPU with 48GB memory.

Complete Table of Top-K Accuracy

A full table of top-k metrics is provided in Table 2. This table includes additional baseline approaches for computerized retrosynthesis prediction from prior literature as well as results for the singular C-DiffER and C-DiffER20_{20} diffusion models. These results highlight the advantages of the ensemble approaches, which produce sample distributions with higher top-k accuracy than the singular diffusion models. Notably, C-DiffER does achieve stronger performance than C-DiffER20_{20} (which includes the DiffER adapted length prediction described in section 3.2), demonstrating the inherent bias in the length prediction model, but still shows reduced performance compared to R-SMILES, indicating that a single diffusion model may be an insufficient approximation of the reactant posterior. These results may also change if a greater number of samples were taken from the C-DiffER models.

CategoryModelK=1K=13510
Template-basedRetrosim Coley et al. [9]37.354.763.374.1
Neuralsym Segler & Waller [44]44.465.372.478.9
GLN Dai et al. [13]52.569.075.683.7
LocalRetro Chen & Jung [6]53.477.585.992.4
Semi-templateG2Gs Shi et al. [48]48.967.672.575.5
GraphRetro Somnath et al. [50]53.768.372.275.5
RetroXpert Yan et al. [64]50.461.162.363.4
RetroPrime Wang et al. [58]51.470.874.076.1
G²Retro Chen et al. [7]53.974.680.786.6
GDiffRetro Sun et al. [55]58.979.181.9-
Template-freeSeq2Seq Liu et al. [32]37.452.457.061.7
Levenshtein Sumner et al. [53]41.548.150.051.4
GTA Seo et al. [46]51.167.674.881.6
Graph2SMILES Tu & Coley [56]51.266.370.473.9
Dual-TF Sun et al. [54]53.369.773.075.0
MEGAN Sacha et al. [39]48.170.778.486.1
Chemformer Irwin et al. [27]54.3-62.363.0
Retroformer Wan et al. [57]53.271.176.682.1
Tied transformer Kim et al. [29]47.167.273.578.5
R-SMILES Zhong et al. [69]56.379.286.291.0
DiffER Current et al. [12]57.679.084.187.4
C-DiffER55.973.375.876.8
C-DiffER₂₀54.572.675.676.5
C-DiffERₛₑₗfᵢₑₛ54.372.375.277.5
DiffER²57.679.585.388.2
DiffER²PG57.479.485.488.6
DiffER²PG+57.779.886.189.9

Table 2. Complete top-KK accuracy comparison to baseline models. DiffER² is the ensemble model and C-DiffER are the individual continuous-time diffusion models. The best performing model in each category is bolded, while the second-best performing model is <u>underlined</u>.

C-DiffERSelfies_{\mathrm{Selfies}} indicates the C-DiffER model trained using SELFIES molecular representations Krenn et al., [30], an alternative to SMILES string representations. Unlike SMILES, SELFIES is 100% robust, with every SELFIES string representing a valid molecular structure. SELFIES has been proposed as an alternative to SMILES for molecular generation tasks due to the guaranteed validity of outputs, which do not suffer from the harsh syntactic constraints of SMILES. Notably, however, the SELFIES-based implementation of C-DiffER does not seem to significantly improve performance compared to SMILES-based models, and in fact exhibits a lower top-1 accuracy than the SMILES-based version. As kk increases, the performances become more similar, with the SELFIES-based implementation exhibiting a slightly stronger top-10 accuracy. This indicates that the choice of string-encoding has little impact on the performance of the retrosynthetic diffusion model. This is likely due to the already high per-sample validity (89.4%) of SMILES strings produced by C-DiffER, which limits the impact of SELFIES’ guaranteed validity on the model’s performance. Furthermore, these results support the findings of Leon et al. [31], which found that SMILES-based models often perform better than their SELFIES counterparts on a variety of molecular prediction tasks.

Round-Trip Accuracy

to further evaluate our models, we compute the top-k round-trip accuracy score using the forward model of R-Smiles (Zhong et al. [69]). The round-trip accuracy is calculated by running a forward synthesis prediction model on the predicted reactants of the retrosynthesis model and computing the rate at which the original input product is recovered. We use the forward prediction model of R-Smiles, which achieves a top-1 accuracy of 91% on the USPTO-50K dataset. However, we note that the accuracy of the forward model is likely lower for retrosynthesis predictions due to the lack of reagent predictions in the retrosynthesis benchmark, which are generally included as input to the forward model. Due to the lack of reagent information amongst retrosynthesis models, the forward model must make assumptions about reagents used, possibly reducing the performance of the model when applied to the outputs of present retrosynthesis models.

The top-kk round-trip accuracy results are presented in Table 3. These scores support the conclusions obtained from the ground-truth top-kk accuracy presented in Table 1: DiffER2^{2}PG+ consistently obtains the highest accuracy scores among the proposed models, significantly improving upon DiffER for k=5k = 5 and k=10k = 10. Furthermore, DiffER2^{2}PG+ maintains the best top-1 accuracy among the tested models, though the round-trip accuracies for k=1k = 1 differ only slightly. Notably, the difference in performance between DiffER2^{2} and DiffER2^{2}PG is significantly greater when analyzing round-trip accuracy versus ground-truth accuracy, indicating that the output distribution obtained using SMILES-adapted particle guidance sampling maintains not only improves output diversity but also predicts quality reactions. These results further support the conclusion that the proposed DiffER2^{2} changes significantly improve the output diversity and efficacy of diffusion models for template-free retrosynthesis prediction.

ModelK=1K=13510
R-SMILES Zhong et al. [69]53.866.773.782.1
DiffER Current et al. [12]53.864.770.175.6
DiffER²54.165.270.675.5
DiffER²PG54.466.071.877.6
DiffER²PG+54.466.172.0†78.4†

Table 3. Top-KK round-trip accuracy for select models. A † indicates results that are significantly different from DiffER at the 95% level.

Reaction Type Performance

Schneider et al. [42] reports the results of the DiffER2^{2}PG+ ensemble across reaction types as determined by Schneider et al. Notably, the performance of the ensemble model is inconsistent across reaction types. This has been similarly observed in other literature [7, 12], and is an unsurprising result due to the differing degree of structural changes across different reaction types. The performance of the ensemble model for is lowest for heterocycle formation, functional group interconversion, and C-C bond formation. While all three reaction types exhibit low top-1 accuracy (<40%< 40\%), functional group interconversion and C-C bond formation are able to achieve moderately strong results (>75%> 75\%) for top-10 accuracy, a significant increase in performance. This suggests that the models are capable of learning reaction patterns associated with these reaction types, but may be unable to discern when they are appropriate to be used without additional guidance. In contrast, heterocycle formation still achieves limited performance (∼65%\sim65\% accuracy) for k=10k = 10, indicating that the reaction patterns of heterocycle formation may be less understood by the diffusion models.

In all three cases, much of the difficulty in predicting patented reactions may be attributed to ambiguity in the goals of the single-step retrosynthesis task. Unlike multi-step retrosynthetic planning, which aims to produce a reaction pathway from a core set of available reactions, single-step retrosynthesis models are generally unaware of the availability of reactants. Furthermore, as exemplified in the case studies later presented in appendix A.8, there are multiple possible reactants that could be used to produce the target product, and ambiguity in why one reactant may be preferential over another makes training a capable retrosynthesis model a daunting task. If we can develop methods to better inform the retrosynthesis model when one reaction may be beneficial over another, we may be better able to construct robust and useful retrosynthesis predictors.

In contrast to the poor performance of heterocycle formation, functional group interconversion, and C-C bond formation, all other reactions types achieve strong (∼90%\sim90\% or greater) top-10 accuracy, with some even achieving considerable top-1 accuracy (>70%> 70\%). Many of these reaction types utilize common or routine reactions: functional group addition, for instance, has extremely low diversity in reactants. While the target product is different for each sample, the vast majority of functional group additions in the test set are bromination reactions featuring N-bromosuccinimide as a reactant, a commonly used reagent for its bromine-donating properties. This commonality of reactants is also observed in the protections subset. In contrast, the high-support acylation and related processes and heteroatom alkylation and arylation subsets exhibits a wider diversity of reactants, but all with a shared mechanism which is effectively learned by the ensemble models, with the main point of decision being where to "split" the product. As there are generally few locations where small molecules may be "split" effectively, these reaction subsets will tend toward higher performance, particularly as kk increases. Overall, reaction types that are learned well by the DiffER2^2PG+ tend to have consistent and common reaction patterns with limited possible locations for a reaction center.

Property Coefficient Analysis for DiffER2^2 Models

In this appendix, we offer an analysis of the DiffER2^2 models by regressing model performance with a variety of target reaction properties. These properties were selected due to the insight they give into the comparable and contrasting capabilities of diffusion and auto-regressive models on SMILES reactions. These properties are:

  1. Target Length Difference: the difference in sequence length Lx−LyL_x - L_y between the product SMILES and the target reactant SMILES. This property was chosen to characterize differing capabilities between diffusion models and auto-regressive models and can serve as a proxy for the leaving group size.

  2. Edit Distance: the Levenshtein distance between the product and reactant SMILES. This property characterizes how sequence similarity between the product and reactant affects performance.

  3. Ring Adding: If the number of rings in the product is greater than the number of rings in the reactant. This is indicative of ring formation. This represents a significant change in molecular and SMILES structure.

  4. Ring Removing: If the number of rings in the product is less than the number of rings in the reactant. Oftentimes, this is indicative of a large leaving group containing a ring structure rather than a true ring opening. This represents a significant change in molecular and SMILES structure.

  5. Branch Count: the number of branches in the target reactant SMILES. This is computed as the number of ‘(’ tokens in the SMILES string. This represents structural complication in the SMILES string and molecular structure.

For each property, we report the slope of a line of best fit between the property statistic and the top-kk accuracy. A positive slope indicates that the model tends to perform well when the property statistic is high, and a negative slope indicates worse performance. In addition, we report the significance of each coefficient compared to the coefficients achieved by Root-aligned SMILESZhong et al. [69] to highlight significant differences between auto-regressive and diffusion models. This is accomplished by constructing the zz-statistic z=(βDiffER−βRSmiles)/SEDiffER2+SERSmiles2z = (\beta_{DiffER} - \beta_{RSmiles}) / \sqrt{SE^2_{DiffER} + SE^2_{RSmiles}}, where β\beta is the slope and SESE is the standard error Clegg et al. [8]. These results are reported for the DiffER2^2 ensemble and the continuous-time C-DiffER and C-DiffER20_{20} models in Table 5, with a visualization of the best fit lines for each property provided in Figure 5.

PropertyModelK=1K=1310
Target Length Diff.C-DiffER-0.0092 (<u>+0.0035</u>)-0.0108 (+0.0023)-0.0104 (+0.0024)
Target Length Diff.C-DiffER20_{20}-0.0071 (+0.0056)-0.0084 (+0.0047)-0.0072 (+0.0055)
Target Length Diff.DiffER2^{2}-0.0078 (+0.0049)-0.0090 (+0.0041)-0.0066 (+0.0061)
Target Length Diff.DiffER2^{2}PG-0.0074 (+0.0052)-0.0075 (+0.0056)-0.0060 (+0.0067)
Target Length Diff.DiffER2^{2}PG+-0.0085 (<u>+0.0041</u>)-0.0090 (+0.0041)-0.0057 (+0.0070)
Edit DistanceC-DiffER0.0003 (+0.0020)-0.0020 (+0.0007)-0.0024 (+0.0000)
Edit DistanceC-DiffER20_{20}0.0003 (<u>+0.0021</u>)-0.0021 (+0.0007)-0.0016 (+0.0008)
Edit DistanceDiffER2^{2}0.0000 (+0.0017)-0.0019 (+0.0009)-0.0015 (+0.0010)
Edit DistanceDiffER2^{2}PG0.0005 (<u>+0.0022</u>)-0.0014 (+0.0014)-0.0016 (+0.0009)
Edit DistanceDiffER2^{2}PG+0.0000 (+0.0017)-0.0019 (+0.0009)-0.0015 (+0.0010)
Ring AddingC-DiffER-0.2823 (-0.1016)-0.2895 (-0.0601)-0.3083 (-0.1189)
Ring AddingC-DiffER20_{20}-0.2592 (-0.0786)-0.3513 (-0.1219)-0.3400 (-0.1506)
Ring AddingDiffER2^{2}-0.2826 (-0.1020)-0.3274 (-0.0980)-0.3571 (-0.1677)
Ring AddingDiffER2^{2}PG-0.2897 (-0.1091)-0.3867 (-0.1574)-0.3273 (-0.1379)
Ring AddingDiffER2^{2}PG+-0.3009 (-0.1203)-0.3565 (-0.1271)-0.3320 (-0.1426)
Ring RemovingC-DiffER-0.2316 (+0.0403)-0.2397 (+0.0048)-0.2258 (-0.0136)
Ring RemovingC-DiffER20_{20}-0.1891 (<u>+0.0828</u>)-0.1782 (<u>+0.0662</u>)-0.1656 (+0.0466)
Ring RemovingDiffER2^{2}-0.2166 (+0.0553)-0.1821 (<u>+0.0624</u>)-0.1397 (<u>+0.0726</u>)
Ring RemovingDiffER2^{2}PG-0.1878 (<u>+0.0841</u>)-0.1453 (+0.0992)-0.0957 (+0.1166)
Ring RemovingDiffER2^{2}PG+-0.2088 (+0.0631)-0.1585 (+0.0860)-0.0854 (+0.1268)
Branch CountC-DiffER-0.0079 (+0.0050)-0.0106 (+0.0023)-0.0132 (-0.0020)
Branch CountC-DiffER20_{20}-0.0081 (+0.0048)-0.0106 (+0.0024)-0.0098 (+0.0015)
Branch CountDiffER2^{2}-0.0071 (+0.0058)-0.0100 (+0.0030)-0.0070 (<u>+0.0043</u>)
Branch CountDiffER2^{2}PG-0.0073 (+0.0055)-0.0085 (+0.0044)-0.0082 (+0.0031)
Branch CountDiffER2^{2}PG+-0.0069 (+0.0059)-0.0094 (+0.0036)-0.0070 (<u>+0.0043</u>)

Table 5. Coefficients between reaction properties and performance metrics for the DiffER2^{2} ensemble and the C-DiffER model. The value in parenthesis indicates the change in coefficient compared to coefficients obtained using R-Smiles Zhong et al. [69]. Values that are significantly different from 0 are underlined at the 95% level and bolded at the 99% level.

Lines of best fit between model performance and reactant properties for the DiffER2PG+ and R-SMILES models

Figure 5. Lines of best fit between model performance and reactant properties for the DiffER2^{2}PG+ and R-SMILES Zhong et al. [69] models.

Table 5 reports the slope coefficients, significance, and difference in coefficient values compared to R-SMILES for each property for each of the DiffER2^2 models as well as the C-DiffER models. Figure 5 offers a visualization of the lines of best fit for k=1k = 1, k=3k = 3, and k=10k = 10 performance conditioned on each of the analyzed properties. The results for k=3k = 3 and k=10k = 10 support the same conclusions discussed in the main text for k=1k = 1, primarily that:

  1. Diffusion models with length prediction are significantly more capable at predicting ground-truth reactions with larger increases in reactant SMILES length from the product SMILES compared to auto-regressive methods;

  2. Diffusion ensembles are significantly more capable at predicting ring-removing reactions compared to auto-regressive methods, but struggle to predict ring-adding reactions;

  3. Both diffusion models and auto-regressive models are negatively impacted by an increased edit distance between product and reactant SMILES as well as an increased branch count in the target reactant.

Notably, however, many of the observed performance differences between R-SMILES and the DiffER2^{2} models become more significant at larger kk, indicating that the trends observed at k=1k = 1 remain consistent across when more unique molecules are generated by the models. Furthermore, this highlights the capability for both model archetypes to predict common reaction rules that are likely to be used with high probability, resulting in k=1k = 1 distributions that perform more similarly than the more diverse k=10k = 10 molecule sets.

One interesting difference between DiffER2^{2}PG+ and R-SMILES that becomes more significant at k=10k = 10 is the effect of branch count on model performance. While DiffER2^{2}PG+ has higher slope for all values of kk, the difference is only significant for k=10k = 10, as shown in Table 5. This difference in performance however is better observed in Figure 5, which also shows the difference in bias between DiffER2^{2}PG+ and R-SMILES. Notably, when the branch count is low, R-SMILES performs slightly better than DiffER2^{2}PG+, indicating the auto-regressive model may be stronger when the reactant SMILES has a highly sequential nature. However, as the number of branch terms in the reactant SMILES increases, the non-auto-regressive diffusion ensembles begin to exhibit stronger performance. This suggests that the diffusion models may be slightly more capable of generating SMILES sequences with non-sequential properties compared to state-of-the-art auto-regressive models.

Case Study

In this section, we present three additional case studies on the DiffER2^{2}PG+ ensemble. These reactions were selected to demonstrate the strengths and weakness of the ensemble. Table 6 displays the source product, target reactant(s), and top-3 reactant(s) predicted by the DiffER2^{2}PG+ ensemble.

CaseSourceTargetRank 1Rank 2Rank 3
Case 1: Nitro Reduction to AnilineSource moleculeTarget reactant*Rank: 1 (78.7%)Rank: 2 (9.2%)Rank: 3 (6.4%)
Case 2: Carbonyl Reduction to AlcoholSource moleculeTarget reactantRank: 1 (44.9%)Rank: 2 (22.0%)*Rank: 3 (15.3%)
Case 3: Deprotection using Methoxymethyl EtherSource moleculeTarget reactantRank: 1 (34.2%)Rank: 2 (26.5%)Rank: 3 (22.7%)

Table 6. Case Studies. From left to right: the source product, the ground-truth reactant(s), and the top-3 predicted reactant(s) for the DiffER2PG+\mathrm{DiffER}^{2}\mathrm{PG+} ensemble. Red highlighting in the source molecule indicates the ground truth change. Red highlighting in the true and predicted reactant(s) indicates differences between the source product and the reactants.

Case 1: Nitro Reduction to Aniline. Case 1 presents a reduction of a nitro group (O=N−O−\mathrm{O=N-O^{-}}) to a primary aromatic amine (NH2\mathrm{NH_{2}}). This is a common reaction that is generally achieved through metal catalyzed reduction of the nitro group, often using Pd, Zn, Fe, or Ni. This same reaction is the most commonly predicted reaction by the ensemble model, encompassing 78.7% of all generated reactions. Instead of the nitro reduction, the second and third ranked reactions both take the form of an N-dealkylation to form a secondary amine. The rank 2 reaction is a proposed desterification in which the tert-butyl ester is reacted with a strong base such as NaOH to form an intermediate carboxylic acid and subsequently heated to decarboxylize, resulting in the target product. This is a viable alternative to the target reaction. The rank 3 reaction may be accomplished by Pt-catalyzed reaction with O2\mathrm{O_{2}} or by acid hydrolysis with hydrobromic or hydroiodic acid Najmi et al. [36]. This reaction is also a viable alternative to the target reaction. Each of the top-3 reactions proposed by the ensemble is a viable way to synthesize the desired product. Reactions may be limited by the availability of the generated reactant(s).

Case 2: Carbonyl Reduction to Alcohol. Case 2 presents a common carbonyl reduction to an alcohol, in which a carbonyl group (C=O\mathrm{C=O}) is reacted with LiAlH4\mathrm{LiAlH_{4}} or NaBH4\mathrm{NaBH_{4}} to form an alcohol (C−OH\mathrm{C-OH}). This reaction is the third-most popular reaction produced by the ensemble model, appearing 15.3% of the time. In contrast to the target reaction, The proposed rank 1 and rank 2 reactions add larger structural changes to core molecule, and may be reactions that could have been used during prior synthesis of the ground truth reactant. The rank 1 reaction is an aldehyde reaction with a Grignard reagent. This is a common and viable method to produce the product molecule. The rank 2 reaction is a proposed Suzuki cross-coupling, in which a boronic ester (R1−B(OR)2\mathrm{R_{1}-B(OR)_{2}}) is reacted with an organohalide (R2−X\mathrm{R_{2}-X}) using a Palladium catalyst in the presence of a base to produce the target product (R1−R2\mathrm{R_{1}-R_{2}}). The Suzuki coupling may also be a viable alternative to the ground truth reaction. Like case 1, each of the top-3 reactants may be suitable methods to synthesize the desired product, limited primarily by the availability of reactants.

Case 3: Deprotection using Methoxymethyl Ether. Finally, case 3 presents a deprotection reaction in which a Methoxymethyl ether is removed via a silica-supported sodium hydrogen sulfate catalyst in dichloromethane solution Ramesh et al. [38]. Unfortunately, this reaction is not one of the top-3 reactions predicted by the ensemble, instead being produced at rank 7. The rank 1 prediction of the ensemble is a hydrolysis reaction in which a ketone is reduced to an alcohol, and is generally considered a common and trivial reaction. The rank 2 reaction is also a deprotection reaction involving a benzyl ether, which is removed using a metal catalyst in a hydrogen atmosphere. This is also a common and trivial reaction. Finally, the rank 3 predicted reaction is a acidic cleavage of a methyl ester. However, because this reaction is often done in an acidic environment, the presence of an ester Table 6: Case Studies. From left to right: the source product, the ground-truth reactant(s), and the top-3 predicted reactant(s) for the DiffER2PG+\mathrm{DiffER}^{2}\mathrm{PG+} ensemble. Red highlighting in the source molecule indicates the ground truth change. Red highlighting in the true and predicted reactant(s) indicates differences between the source product and the reactants.

group in the product/reactant may lead to unwanted byproducts. This reaction is non-trivial and is likely suboptimal compared to the rank 1, rank 2, and ground-truth reactions.

These case studies demonstrate both the effectiveness and pitfalls of the DiffER2PG+\mathrm{DiffER}^{2}\mathrm{PG+} ensemble. As evidenced in all cases, the diffusion ensemble is capable of learning many common reaction patterns, but struggles to predict the ground-truth when many possible alternatives are present. While the reactions proposed by the DiffER2\mathrm{DiffER}^{2} ensembles will generally produce the target, the model does not necessarily account for the availability of reactants or for the possible formation of side products, which may limit the models effectiveness. Furthermore, as evidenced by cases 2 and 3, it is not always clear what type of reaction is being desired: the model may be prone to larger structural changes (such as the top-2 reactants of case 2) over smaller changes that are necessary for preparing the molecule for future synthesis steps, such as protections, deprotections, and reductions. Moreover, the model may be biased toward reaction patterns that result in "easier" structural changes of the molecule, such as the top-2 reactions in the main case study (Figure 3), in which the ensemble prefers reactants in which two structures are “added” together over the more “advanced” ring-forming reaction. Nevertheless, for each product in the case studies, DiffER2PG+\mathrm{DiffER}^{2}\mathrm{PG+} does generate the target reactant(s) within the top-10 predictions, and in many cases provides viable alternate reactions. These case studies demonstrate that the diffusion ensemble is capable of learning effective reaction processes.

Performance Analysis with Molecular Fingerprints

Morgan fingerprints Morgan [35] are a commonly used methodology for constructing feature vectors from molecule structures. The core of the method is built around substructure matching: each feature vector is a set number of bits, which each bit in the feature indicating whether or not a specific substructure is present in the molecule. These substructures capture the environment of atoms in a set radius and are generated using a hashing algorithm provided by the original authors Morgan [35]. Because Morgan fingerprints capture many important characteristics of a molecule structure, we aim to investigate how the performance of the DiffER2^{2} models may be impacted by the presence of specific fingerprints in the target reactant(s), which could highlight specific substructures the ensembles may be biased against. Additionally, we note that because Morgan fingerprints are constructed using a hashing function, Morgan bits are not necessarily unique indicators, as multiple substructures may map to a single index. However, they are still a useful tool for visualizing how performance relates to particular substructures.

We generate Morgan fingerprints with 2048 bits and a radius of 2 for the target reactants and analyze the correlation between the top-10 performance of the DiffER2^{2}PG+ model and each bit in the generated fingerprint. We visualize the Morgan bits that have the most positive correlation with model performance as well as the Morgan bits that have the most negative correlation with model performance. All analyzed correlations are statistically significant at the 99% (p<0.01p < 0.01) level. Visuals are produced by randomly selecting a reactant from the test set that has the associated fingerprint bit and visualizing the atom and neighborhood that produced the positive bit value. Atoms highlighted blue represent the central atom, while atoms highlighted yellow represent atoms in an aromatic ring. Atoms with gray highlights are in aliphatic rings.

Figure 6 visualizes the Morgan fingerprints that have the most positive correlation with model performance for k=10k = 10. These bits tend to be substructures with well-known and highly utilized reaction mechanisms and reactivity rules. For instance, fingerprint A1 has the highest correlation with model performance, and represents an aliphatic secondary amine. Reactions with aliphatic secondary amines are well known and highly studied in organic synthesis, appearing in ∼25%\sim25\% of the test set. These reactions are commonly alkylation reactions, in which the amine is reacted with an alkyl halide to form new bonds and larger structures. Many fingerprints containing amines also exhibit positive correlation with model performance (A3, B2, B4, B5). Other notable fingerprints with positive correlation include: aryl halides (A2), which are commonly used in substitution reactions and as directing groups; carboxylic acids (A5) and alcohols (B3), two of the most studied functional groups in organic chemistry; halides (C3); and sulfonyl chlorides (A4), all of which are commonly used groups in organic synthesis.

The 10 Morgan fingerprints with the highest positive correlation to Top-10 accuracy

Figure 6. The 10 Morgan fingerprints with the highest positive correlation to Top-10 accuracy for the DiffER2^{2}PG+ ensemble. "r" is the correlation value and "N" is the number of reactants in the test set that have the corresponding fingerprint. All correlations are statistically significant (p<0.01p < 0.01).

In contrast, fingerprints that have significant negative correlation with model performance tend to be rarer, have ambiguity in the reaction, or introduce complexity in the SMILES sequence structure. Figure 7 visualizes the Morgan fingerprints that have the most negative correlation with model performance for k=10k = 10. Many of these structures have a large number of branches or structural complexity (C3, C5, D2, D3, D4, D5), requiring SMILES structures with high non-sequential behavior. Many of these fingerprints may also require SMILES strings which detail stereochemistry of the molecule (D1, D2), further compounding the complexity of the SMILES string. In other cases, the fingerprint may require complexity in the SMILES string, but rather may represent ambiguity in the reactant. This is likely the case with C2, which represents a halide in the form of iodine. For many reactions, the explicit halide used may be interchangeable between Cl, Br, and I, as many chemical properties are shared between the three halogens with only subtle differences in reactivity and stability. A similar ambiguity may explain C4. Many reactions with alkenes result in the elimination of the C=C bond and the addition of new functional groups. To "reverse" this reaction, the retrosynthesis model would be have to identify a specific C-C bond as the reaction center. Because C-C bonds are extremely common, the model may have difficulty choosing these bonds as reaction centers, opting instead to target groups that are more commonly used in reactions. This behavior is readily observed in Appendix § 7.§ 6, Table 4, which shows that the DiffER²PG+ ensemble exhibits a reduced capability to predict reactions which form C-C bonds.

Reaction TypeK=13510Support
Heteroatom alkylation and arylation58.581.187.591.21516
Acyclation and related processes70.189.993.595.51190
Deprotections55.280.887.190.5822
C-C bond formation41.364.973.981.5567
Reductions56.678.485.589.4463
Functional group interconversion39.656.070.375.3182
Heterocycle formation32.252.263.366.790
Oxidations60.281.986.791.683
Protections70.189.694.095.567
Functional group addition78.387.087.091.323

Table 4. Top-K accuracy metrics by reaction type for the DiffER2^{2}PG+ ensemble. Support indicates the number of reactions of the associated type in the test set.

The 10 Morgan fingerprints with the highest negative correlation to Top-10 accuracy

Figure 7. The 10 Morgan fingerprints with the highest negative correlation to Top-10 accuracy for the DiffER²PG+ ensemble. "r" is the correlation value and "N" is the number of reactants in the test set that have the corresponding fingerprint. All correlations are statistically significant (p<0.01p < 0.01).

Attention Map Analysis

Our final results are an analysis of the attention maps for a single continuous-time diffusion model with full sequence padding (C-DiffER). This model was used to better understand how the attention of the model changes throughout the diffusion process without the bias of a length-prediction component as described in § 3.2. We provide visualizations of the attention maps for both the self attention and attention on the input product for each layer in the transformer model for t=0.5t = 0.5. Additionally, we map the attention on specific atoms in the SMILES sequences to the atoms they represent in the input and output molecular structures.

Figure 8 and Figure 9 show the attention maps for layers 1, 2, 3 and 4, 5, 6, respectively for a amine alkylation reaction. This reaction reacts an alkyl halide with an amine and is successfully produced as a top-1 reactant by the C-DiffER model. These attention maps demonstrate how the construction of the SMILES sequence differs from auto-regressive methods. Rather than building the sequence from the beginning, the attention maps suggest that the diffusion model works backward, attending to the full-length sequence initially and decreasing the attended sequence length as the model goes deeper. This helps explain why the diffusion models may have a stronger affinity for generating reactants with a larger change in sequence length over the product SMILES: unlike auto-regressive models, which may be likely to predict a STOP token earlier in the sequence, diffusion models attend to the maximum possible sequence at each step in the diffusion process, allowing for the full sequence to be predicted over during each estimate of x0x_0. As the iteration number increases, the diffusion model becomes more confident in its output of padding tokens at later timesteps, attending to those positions less after the first couple layers.

C-DiffER attention maps for layers 1, 2, and 3, showing source attention, self attention, attention on the source molecule, and attention on the output molecule

Figure 8. C-DiffER attention maps for layers 1, 2, and 3 on a reaction from the test set halfway through sampling, t=0.5t = 0.5. From left to right: attention on the input product SMILES y0y_0, attention on the noisy sample xtx_t, attention mapped to the input product molecule, and attention mapped to the final predicted output molecule.

C-DiffER attention maps for layers 4, 5, and 6

Figure 9. C-DiffER attention maps for layers 4, 5, and 6 on a reaction from the test set halfway through sampling, t=0.5t = 0.5. From left to right: attention on the input product SMILES y0y_0, attention on the noisy sample xtx_t, attention mapped to the input product molecule, and attention mapped to the final predicted output molecule.

In the early self attention layers, the diffusion model appears to try and understand the general structure of the SMILES string, estimating the level of noise and confidence in the input xtx_t. This can be observed in the way sequence attention is spread across the entire sequence for each token rather than focused on tokens with similar locality. After the first layer, the self attention mechanism places much more emphasis on nearby positions, but still attends very little to each tokens’ own position, indicating that the model is not confident in the fidelity of a one-to-one input mapping between xtx_t and xsx_s. Interestingly, in the final self attention layer, significant attention is placed around the reaction centers in the generated reactants. Source attention layers tend to place attention near non-carbon

atoms in the target product early on, expanding to carbon atoms only in the later layers. While this may simply be an indication that these atoms are "unique" in the molecule compared to the carbon atoms, they may also be used as "anchors" to build the generated reactant(s) around. This could also explain why the models struggle to predict C-C bond formation reactions, as it would require the model to identify a common C-C bond as a reaction center, which may not have any significant uniqueness compared to other structures in the product molecule.

Another interesting feature of note is the repetitive attention patterns the predicted padding tokens place on the end of the product SMILES, notable in layers 2 and 3. Rather than the padding tokens placing attention on a single end token, the attention is stratified in a diagonal formation in groups of 10-12 tokens, attending primarily to the last 10-12 tokens of the product SMILES. This pattern is also observed in attention maps for other reactions, suggesting consistency in this behavior, which fades in the last couple layers. Repetition is a common phenomena also observed in large language models, which may repeat during inference time. The model only begins to reduce attention on later timesteps after this repetition begins, suggesting that it may use the repetition to "detect" padding locations. In the final layers of the transformer, attention on the source sequence is rather sparse and closely matches the attention maps observed by R-SMILES Zhong et al. [69], with the attention patterns "matching" tokens between the input and output SMILES.

The attention map analysis offers some insight into the workings of the diffusion models, and may help inform future model creation. While we offer some theories behind the meaning of these attention maps as it relations to SMILES generation for chemical retrosynthesis, significantly more investigation and experimentation needs to be done before our theories can be confirmed. We hope these attention maps provide some insight into the capabilities and methods of transformer diffusion models and promote further research into the explainability of transformer diffusion models.

References

  1. [1]Amira Alakhdar, Barnabas Poczos, and Newell Washburn. Diffusion models in de novo drug design. Journal of Chemical Information and Modeling, 64(19):7238–7256, 2024.DOI
  2. [2]Jacob Austin, Daniel D Johnson, Jonathan Ho, Daniel Tarlow, and Rianne Van Den Berg. Structured denoising diffusion models in discrete state-spaces. Advances in Neural Information Processing Systems, 34:17981–17993, 2021.arxiv.org/abs/2107.03006
  3. [3]Arpit Bansal, Hong-Min Chu, Avi Schwarzschild, Soumyadip Sengupta, Micah Goldblum, Jonas Geiping, and Tom Goldstein. Universal guidance for diffusion models. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 843–852, 2023.arxiv.org/abs/2302.07121
  4. [4]Richard F Borch. Reductive amination with sodium cyanoborohydride: N, n-dimethylcyclohexylamine: Cyclohexanamine, 4, 4-dimethyl-. Organic Syntheses, 52:124–124, 2003.
  5. [5]Andrew Campbell, Joe Benton, Valentin De Bortoli, Thomas Rainforth, George Deligiannidis, and Arnaud Doucet. A continuous time framework for discrete denoising models. Advances in Neural Information Processing Systems, 35:28266–28279, 2022.arxiv.org/abs/2205.14987
  6. [6]Shuan Chen and Yousung Jung. Deep retrosynthetic reaction prediction using local reactivity and global attention. JACS Au, 1(10):1612–1620, 2021.DOI
  7. [7]Ziqi Chen, Oluwatosin R Ayinde, James R Fuchs, Huan Sun, and Xia Ning. G 2 retro as a two-step graph generative models for retrosynthesis prediction. Communications Chemistry, 6(1):102, 2023.DOI
  8. [8]Clifford C. Clogg, Eva Petkova, and Adamantios Haritou. Statistical methods for comparing regression coefficients between models. American Journal of Sociology, 100(5):1261–1293, 1995. ISSN 00029602, 15375390. URL http://www.jstor.org/stable/2782277.DOI
  9. [9]Connor W Coley, Luke Rogers, William H Green, and Klavs F Jensen. Computer-assisted retrosynthesis based on molecular similarity. ACS central science, 3(12):1237–1245, 2017.DOI
  10. [10]Gabriele Corso, Yilun Xu, Valentin De Bortoli, Regina Barzilay, and Tommi Jaakkola. Particle guidance: non-iid diverse sampling with diffusion models. arXiv preprint arXiv:2310.13102, 2023.arxiv.org/abs/2310.13102
  11. [11]Florinel-Alin Croitoru, Vlad Hondru, Radu Tudor Ionescu, and Mubarak Shah. Diffusion models in vision: A survey. IEEE Transactions on Pattern Analysis and Machine Intelligence, 45(9):10850–10869, 2023.DOI
  12. [12]Sean Current, Ziqi Chen, Xia Ning, et al. Differ: Categorical diffusion models for chemical retrosynthesis. In NeurIPS 2024 Workshop on AI for New Drug Modalities, 2024.arxiv.org/abs/2505.23721
  13. [13]Hanjun Dai, Chengtao Li, Connor Coley, Bo Dai, and Le Song. Retrosynthesis prediction with conditional graph logic network. Advances in Neural Information Processing Systems, 32, 2019.arxiv.org/abs/2001.01408
  14. [14]Sander Dieleman, Laurent Sartran, Arman Rosn̄nani, Nikolay Savinov, Yaroslav Ganin, Pierre H Richëmond, Arnaud Doucet, Robin Strudel, Chris Dyer, Conor Durkan, et al. Continuous diffusion for categorical data. arXiv preprint arXiv:2211.15089, 2022.arxiv.org/abs/2211.15089
  15. [15]Dave Epstein, Allan Jabri, Ben Poole, Alexei Efros, and Aleksander Holynski. Diffusion self-guidance for controllable image generation. Advances in Neural Information Processing Systems, 36:16222–16239, 2023.arxiv.org/abs/2306.00986
  16. [16]Marjan Ghazvininejad, Omer Levy, Yinhan Liu, and Luke Zettlemoyer. Mask-predict: Parallel decoding of conditional masked language models. arXiv preprint arXiv:1904.09324, 2019.arxiv.org/abs/1904.09324
  17. [17]Shansan Gong, Mukai Li, Jiangtao Feng, Zhiyong Wu, and LingPeng Kong. Diffuseq: Sequence to sequence text generation with diffusion models. arXiv preprint arXiv:2210.08933, 2022.arxiv.org/abs/2210.08933
  18. [18]Shansan Gong, Mukai Li, Jiangtao Feng, Zhiyong Wu, and Lingpeng Kong. Diffuseq-v2: Bridging discrete and continuous text spaces for accelerated seq2seq diffusion models. arXiv preprint arXiv:2310.05793, 2023.arxiv.org/abs/2310.05793
  19. [19]Nate Gruver, Samuel Stanton, Nathan Frey, Tim GJ Rudner, Isidro Hötzel, Julien Lafrance-Vanasse, Arvind Rajpal, Kyunghyun Cho, and Andrew G Wilson. Protein design with guided discrete diffusion. Advances in neural information processing systems, 36:12489–12517, 2023.arxiv.org/abs/2305.20009
  20. [20]Shuyang Gu, Dong Chen, Jianmin Bao, Fang Wen, Bo Zhang, Dongdong Chen, Lu Yuan, and Baining Guo. Vector quantized diffusion model for text-to-image synthesis. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pp. 10696–10706, 2022.arxiv.org/abs/2111.14822
  21. [21]Zhengfu He, Tianxiang Sun, Kuanning Wang, Xuanjing Huang, and Xipeng Qiu. Diffusion-bert: Improving generative masked language models with diffusion models. arXiv preprint arXiv:2211.15029, 2022.arxiv.org/abs/2211.15029
  22. [22]Dan Hendrycks and Kevin Gimpel. Gaussian error linear units (gelus). arXiv preprint arXiv:1606.08415, 2016.
  23. [23]Jonathan Ho and Tim Salimans. Classifier-free diffusion guidance. arXiv preprint arXiv:2207.12598, 2022.arxiv.org/abs/2207.12598
  24. [24]Jonathan Ho, Ajay Jain, and Pieter Abbeel. Denoising diffusion probabilistic models. Advances in neural information processing systems, 33:6840–6851, 2020.arxiv.org/abs/2006.11239
  25. [25]Emiel Hoogeboom, Didrik Nielsen, Priyank Jaini, Patrick Forré, and Max Welling. Argmax flows and multinomial diffusion: Learning categorical distributions. Advances in Neural Information Processing Systems, 34:12454–12465, 2021.arxiv.org/abs/2102.05379
  26. [26]Emiel Hoogeboom, Victor Garcia Satorras, Clément Vignac, and Max Welling. Equivariant diffusion for molecule generation in 3d. In International conference on machine learning, pp. 8867–8887. PMLR, 2022.arxiv.org/abs/2203.17003
  27. [27]Ross Irwin, Spyridon Dimitriadis, Jiazhen He, and Esben Jannik Bjerrum. Chemformer: a pre-trained transformer for computational chemistry. Machine Learning: Science and Technology, 3(1): 015022, 2022.DOI
  28. [28]Yuhong Ju and Rajender S Varma. Aqueous n-heterocyclization of primary amines and hydrazines with dihalides: microwave-assisted syntheses of n-azacycloalkanes, isoindole, pyrazole, pyrazolidine, and phthalazine derivatives. The Journal of organic chemistry, 71(1):135–141, 2006.pubmed.ncbi.nlm.nih.gov/16388628
  29. [29]Eunji Kim, Dongseon Lee, Youngchun Kwon, Min Sik Park, and Youn-Suk Choi. Valid, plausible, and diverse retrosynthesis using tied two-way transformers with latent variables. Journal of Chemical Information and Modeling, 61(1):123–133, 2021.DOI
  30. [30]Mario Krenn, Florian Häse, AkshatKumar Nigam, Pascal Friederich, and Alán Aspuru-Guzik. SELFIES: a robust representation of semantically constrained graphs with an example application in chemistry. CoRR, abs/1905.13741, 2019. URL http://arxiv.org/abs/1905.13741.
  31. [31]Miguelangel Leon, Yuriy Perezhonin, Fernando Peres, Aleš Popović, and Mauro Castelli. Comparing smiles and selfies for tokenization for enhanced chemical language modeling. Scientific Reports, 14 (1):25016, 2024.DOI
  32. [32]Bowen Liu, Bharath Ramsundar, Prasad Karthwkar, Jade Shi, Joseph Gomes, Quang Luu Nguyen, Stephen Ho, Jack Sloane, Paul Wender, and Vijay Pande. Retrosynthetic reaction prediction using neural sequence-to-sequence models. ACS central science, 3(10):1103–1113, 2017.arxiv.org/abs/1706.01643
  33. [33]Xihui Liu, Dong Huk Park, Samaneh Azadi, Gong Zhang, Arman Chopikyan, Yuxiao Hu, Humphrey Shi, Anna Rohrbach, and Trevor Darrell. More control for free! image synthesis with semantic diffusion guidance. In Proceedings of the IEEE/CVF winter conference on applications of computer vision, pp. 289–299, 2023.arxiv.org/abs/2112.05744
  34. [34]Daniel Lowe. Chemical reactions from US patents (1976-Sep2016). 6 2017. doi: 10.6084/m9.figshare. 5104873.v1. URL https://figshare.com/articles/dataset/Chemical_reactions_ from_US_patents_1976–Sep2016/5104873.
  35. [35]Harry L Morgan. The generation of a unique machine description for chemical structures-a technique developed at chemical abstracts service. Journal of chemical documentation, 5(2):107–113, 1965.DOI
  36. [36]Ali Alipour Najmi, Rainer Bischoff, and Hjalmar P Permentier. N-dealkylation of amines. Molecules, 27(10):3293, 2022.DOI
  37. [38]C Ramesh, N Ravindranath, and Biswanath Das. Simple, efficient, and selective deprotection of phenolic methoxymethyl ethers using silica-supported sodium hydrogen sulfate as a heterogeneous catalyst1. The Journal of Organic Chemistry, 68(18):7101–7103, 2003.pubmed.ncbi.nlm.nih.gov/12946158
  38. [39]Mikołaj Sacha, Mikołaj Błaz, Piotr Byrski, Paweł Dąbrowski-Tumański, Mikołaj Chrominski, Rafał Loska, Paweł Włodarczyk-Pruszyński, and Stanisław Jastrzębski. Molecule edit graph attention network: modeling chemical reactions as sequences of graph edits. Journal of Chemical Information and Modeling, 61(7):3273–3284, 2021.arxiv.org/abs/2006.15426
  39. [40]Chitwan Saharia, William Chan, Saurabh Saxena, Lala Li, Jay Whang, Emily L Denton, Kamyar Ghasemipour, Raphael Gontijo Lopes, Burcu Karagol Ayan, Tim Salimans, et al. Photorealistic text-to-image diffusion models with deep language understanding. Advances in neural information processing systems, 35:36479–36494, 2022.arxiv.org/abs/2205.11487
  40. [41]Yair Schiff, Subham Sekhar Sahoo, Hao Phung, Guanghan Wang, Sam Boshar, Hugo Dalla-torre, Bernardo P de Almeida, Alexander Rush, Thomas Pierrot, and Volodymyr Kuleshov. Simple guidance mechanisms for discrete diffusion models. arXiv preprint arXiv:2412.10193, 2024.arxiv.org/abs/2412.10193
  41. [42]Nadine Schneider, Nikolaus Stiefl, and Gregory A Landrum. What’s what: The (nearly) definitive guide to reaction role assignment. Journal of chemical information and modeling, 56(12):2336–2346, 2016.DOI
  42. [43]Arne Schneuing, Charles Harris, Yuangi Du, Kieran Didi, Arjan Jamsh, Ilia Igashov, Weitao Du, Carla Gomes, Tom L Blundell, Pietro Lio, et al. Structure-based drug design with equivariant diffusion models. Nature Computational Science, 4(12):899–909, 2024.arxiv.org/abs/2210.13695
  43. [44]Marwin HS Segler and Mark P Waller. Neural-symbolic machine learning for retrosynthesis and reaction prediction. Chemistry–A European Journal, 23(25):5966–5971, 2017.DOI
  44. [45]Marwin HS Segler, Mike Preuss, and Mark P Waller. Planning chemical syntheses with deep neural networks and symbolic ai. Nature, 555(7698):604–610, 2018.DOI
  45. [46]Seung-Woo Seo, You Young Song, June Yong Yang, Seohui Bae, Hankook Lee, Jinwoo Shin, Sung Ju Hwang, and Eunho Yang. Gta: Graph truncated attention for retrosynthesis. In Proceedings of the AAAI Conference on Artificial Intelligence, volume 35, pp. 531–539, 2021.
  46. [47]Yuning Shen, Julia E Borowski, Melissa A Hardy, Richmond Sarpong, Abigail G Doyle, and Tim Cernak. Automation and computer-assisted planning for chemical synthesis. Nature Reviews Methods Primers, 1(1):1–23, 2021.
  47. [48]Chence Shi, Minkai Xu, Hongyu Guo, Ming Zhang, and Jian Tang. A graph to graphs framework for retrosynthesis prediction. In International conference on machine learning, pp. 8818–8827. PMLR, 2020.arxiv.org/abs/2003.12725
  48. [49]Jascha Sohl-Dickstein, Eric Weiss, Niru Maheswaranathan, and Surya Ganguli. Deep unsupervised learning using nonequilibrium thermodynamics. In International conference on machine learning, pp. 2256–2265. PMLR, 2015.
  49. [50]Vignesh Ram Somnath, Charlotte Bunne, Connor Coley, Andreas Krause, and Regina Barzilay. Learning graph models for retrosynthesis prediction. Advances in Neural Information Processing Systems, 34:9405–9415, 2021.arxiv.org/abs/2006.07038
  50. [51]Yang Song and Stefano Ermon. Generative modeling by estimating gradients of the data distribution. Advances in neural information processing systems, 32, 2019.arxiv.org/abs/1907.05600
  51. [52]Yang Song, Jascha Sohl-Dickstein, Diederik P Kingma, Abhishek Kumar, Stefano Ermon, and Ben Poole. Score-based generative modeling through stochastic differential equations. arXiv preprint arXiv:2011.13456, 2020.arxiv.org/abs/2011.13456
  52. [53]Dean Sumner, Jiazhen He, Amol Thakkar, Ola Engkvist, and Esben Jannik Bjerrum. Levenshtein augmentation improves performance of smiles based deep-learning synthesis prediction. 2020.DOI
  53. [54]Ruoxi Sun, Hanjun Dai, Li Li, Steven Kearnes, and Bo Dai. Towards understanding retrosynthesis by energy-based models. Advances in Neural Information Processing Systems, 34:10186–10194, 2021.
  54. [55]Shengyin Sun, Wenhao Yu, Yuxiang Ren, Weitao Du, Liwei Liu, Xuecang Zhang, Ying Hu, and Chen Ma. Gdiffretro: Retrosynthesis prediction with dual graph enhanced molecular representation and diffusion generation. arXiv preprint arXiv:2501.08001, 2025.arxiv.org/abs/2501.08001
  55. [56]Zhengkai Tu and Connor W Coley. Permutation invariant graph-to-sequence model for template-free retrosynthesis and reaction prediction. Journal of chemical information and modeling, 62(15):3503–3513, 2022.arxiv.org/abs/2110.09681
  56. [57]Yue Wan, Chang-Yu Hsieh, Ben Liao, and Shengyu Zhang. Retroformer: Pushing the limits of end-to-end retrosynthesis transformer. In International Conference on Machine Learning, pp. 22475–22490. PMLR, 2022.arxiv.org/abs/2201.12475
  57. [58]Xiaorui Wang, Yuquan Li, Jiez hong Qiu, Guangyong Chen, Huanxiang Liu, Benben Liao, Chang-Yu Hsieh, and Xiaojun Yao. Retroprime: A diverse, plausible and transformer-based method for single-step retrosynthesis predictions. Chemical Engineering Journal, 420:129845, 2021.DOI
  58. [61]Minkai Xu, Lantao Yu, Yang Song, Chence Shi, Stefano Ermon, and Jian Tang. Geodiff: A geometric diffusion model for molecular conformation generation. arXiv preprint arXiv:2203.02923, 2022.arxiv.org/abs/2203.02923
  59. [62]Minkai Xu, Alexander S Powers, Ron O Dror, Stefano Ermon, and Jure Leskovec. Geometric latent diffusion models for 3d molecule generation. In International Conference on Machine Learning, pp. 38592–38610. PMLR, 2023.arxiv.org/abs/2305.01140
  60. [63]Zhe Xu, Ruizhong Qiu, Yuzhong Chen, Huiyuan Chen, Xiran Fan, Menghai Pan, Zhichen Zeng, Mahashweta Das, and Hanghang Tong. Discrete-state continuous-time diffusion for graph generation. arXiv preprint arXiv:2405.11416, 2024.arxiv.org/abs/2405.11416
  61. [64]Chaochao Yan, Qianggang Ding, Peilin Zhao, Shuangjia Zheng, Jinyu Yang, Yang Yu, and Junzhou Huang. Retroxpert: Decompose retrosynthesis prediction like a chemist. Advances in Neural Information Processing Systems, 33:11248–11258, 2020.arxiv.org/abs/2011.02893
  62. [65]Ling Yang, Zhilong Zhang, Yang Song, Shenda Hong, Runsheng Xu, Yue Zhao, Wentao Zhang, Bin Cui, and Ming-Hsuan Yang. Diffusion models: A comprehensive survey of methods and applications. ACM Computing Surveys, 56(4):1–39, 2023.arxiv.org/abs/2209.00796
  63. [66]Hongyi Yuan, Zheng Yuan, Chuanqi Tan, Fei Huang, and Songfang Huang. Seqdiffuseq: Text diffusion with encoder-decoder transformers. arXiv preprint arXiv:2212.10325, 2022.arxiv.org/abs/2212.10325
  64. [67]Lvmin Zhang, Anyi Rao, and Maneesh Agrawala. Adding conditional control to text-to-image diffusion models. In Proceedings of the IEEE/CVF International Conference on Computer Vision, pp. 3836–3847, 2023.arxiv.org/abs/2302.05543
  65. [68]Lingxiao Zhao, Xueying Ding, Lijun Yu, and Leman Akoglu. Unified discrete diffusion for categorical data. arXiv preprint arXiv:2402.03701, 2024.arxiv.org/abs/2402.03701
  66. [69]Zipeng Zhong, Jie Song, Zunlei Feng, Tiantao Liu, Lingxiang Jia, Shaolun Yao, Min Wu, Tingjun Hou, and Mingli Song. Root-aligned smiles: a tight representation for chemical reaction prediction. Chemical Science, 13(31):9023–9034, 2022.DOI

Paper details

vlnc:W_qse2wbze
Version
v1 · latest
Published
Fresh — added to the Hub within the last 30 days
Added
License
CC BY 4.0
Usage

views · 0

downloads · 0

A view counts once per browser per day, a download each time the PDF is requested.

  • Computer Science

Not recorded for this paper

View statement
Looking for related papers…
Contents