Abstract
Recent advancements in computational chemistry have increasingly focused on synthesizing molecules based on textual instructions. Integrating graph generation with these instructions is complex, leading most current methods to use molecular sequences with pre-trained large language models. In response to this challenge, we propose a novel framework, named $\textbf{UTGDiff (Unified Text-Graph Diffusion Model)}$, which utilizes language models for discrete graph diffusion to generate molecular graphs from instructions. UTGDiff features a unified text-graph transformer as the denoising network, derived from pre-trained language models and minimally modified to process graph data through attention bias. Our experimental results demonstrate that UTGDiff consistently outperforms sequence-based baselines in tasks involving instruction-based molecule generation and editing, achieving superior performance with fewer parameters given an equivalent level of pretraining corpus. Our code is available at https://github.com/ran1812/UTGDiff.
Introduction
Designing new molecules—whether for drug discovery or materials science—requires balancing complex structural constraints and functional properties. While natural language offers a flexible way for scientists to describe these goals (e.g., "a molecule that is a sulfur oxide and acts as a food bleaching agent"), translating these instructions into valid molecular structures remains a significant challenge.
Existing approaches generally fall into two categories, both with inherent flaws:
- Sequence-based models: These treat molecules as strings (like SMILES). However, strings are fragile; a single character change can destroy the 2D structural meaning, and they lack explicit information about atom connectivity and neighborhood relationships.
- Graph Diffusion models: These generate 2D graphs directly but often treat text instructions as a static global vector. This prevents fine-grained injection—where specific parts of a sentence guide specific parts of a growing molecule—and prevents the text representation from evolving as the molecule is constructed.
Methodology: The UTGDiff Framework
UTGDiff moves away from the traditional "text encoder + graph decoder" architecture in favor of a Unified Text-Graph Transformer. This approach enables fine-grained, bidirectional interaction between text and chemistry.
Key Architectural Innovations
- Shared Vocabulary and Tokenization: Atoms (e.g., [C], [O], [S]) are treated as discrete tokens, similar to words. This allows a standard Transformer (initialized from RoBERTa) to process text and molecular nodes in the same sequence, inheriting the reasoning capabilities of pre-trained language models.
- Discrete Diffusion (Absorbing State): Instead of adding Gaussian noise to coordinates, the model uses a discrete diffusion process. During training, nodes and edges are randomly replaced with a
[MASK]token. The model learns to "denoise" the graph by predicting the original atom and bond types. - Structural Awareness via Attention Bias: Since Transformers are inherently sets, the authors incorporate edge information by adding a learnable attention bias to the self-attention mechanism. This bias is updated layer-by-layer, allowing the model to maintain molecular structure while attending to text.
- Dynamic Text Integration: Unlike models with static text encoders, UTGDiff updates text tokens in every layer alongside graph tokens. This allows the model to "re-interpret" instructions as the molecular structure becomes clearer during the denoising process.
Experimental Evaluation
The model was evaluated across several diverse tasks and datasets:
- Pretraining: A massive corpus including PubChem-324K (text-molecule pairs), ZINC20 (molecular graphs), and PubMed abstracts.
- Instruction-based Generation: Evaluated on the ChEBI-20 dataset, containing over 33,000 molecule-instruction pairs.
- Multi-Property Control: Tested on a Polymer dataset where instructions are numerical targets for gas permeability ($O_2, N_2, CO_2$).
- Molecule Editing: Evaluated using Mol-Instructions for tasks like retrosynthesis and forward reaction prediction.
Results and Discussion
UTGDiff demonstrates state-of-the-art performance across multiple benchmarks, proving that a unified architecture is more parameter-efficient than multimodal systems.
Key Findings
- Superior Similarity: On the ChEBI-20 benchmark, UTGDiff achieved a Morgan Fingerprint Tanimoto Similarity (FTS) of 0.724, outperforming the much larger MolT5-large (0.684).
- Exact Matches: The model achieved an Exact Match rate of 37.4%, a significant improvement over the 31.1% achieved by autoregressive text-based models.
- Property Control: In polymer generation, UTGDiff reduced the Mean Absolute Error (MAE) for property targets by an average of 19% compared to the previous state-of-the-art, Graph-DiT.
- Efficiency and Generalization: Despite having only 125M parameters, UTGDiff showed robust zero-shot generalization to unseen instructions (PCDes dataset) without retraining.
Conclusion and Future Work
UTGDiff represents a significant step forward in instruction-based molecular generation by unifying text and graph representations within a single diffusion framework. While the model achieves high chemical validity, future work will focus on ensuring 100% adherence to valence rules and scaling the pretraining corpus. Additionally, extending the model from 2D graph topologies to 3D conformer generation remains a promising direction for future research.
Summary updated