Bridging Molecular Graphs and Large Language Models

Runze Wang, Mingqi Yang, Yanming Shen

Introduction

Large Language Models (LLMs), such as Llama 3, have demonstrated remarkable capabilities in text-based reasoning and generation. However, these models remain fundamentally "blind" to graph-structured data, which is the primary language of chemistry and biology. Molecular structures are inherently three-dimensional and topological, making them difficult to represent through standard text strings. The Graph2Token framework addresses this gap by allowing LLMs to perceive molecular graphs as specialized tokens within their existing vocabulary, enabling sophisticated chemical reasoning without compromising the model's general intelligence.

The Challenge of Molecular Representation

Historically, researchers have attempted to integrate molecular data into LLMs using two primary strategies, both of which have significant drawbacks:

  1. Textualization: Molecules are converted into strings like SMILES (e.g., CC(C=C1)C=O). While readable, these strings often fail to convey the underlying geometry and connectivity of the molecule, leading to poor performance on complex structural tasks.
  2. Fine-tuning: The LLM backbone is trained directly on molecular datasets. This often results in "catastrophic forgetting," where the model loses its general-purpose reasoning and linguistic abilities as it over-specializes in chemical data.

Graph2Token proposes a third way: a lightweight alignment strategy that treats a molecular graph as a "new word" defined by the LLM’s existing internal concepts.

Methodology

The Graph2Token framework utilizes a two-stage training pipeline designed to bridge the modality gap between graphs and text efficiently.

Stage 1: Pre-training the Graph Encoder

The system employs a Graph Isomorphism Network (GIN) to encode molecular structures. This encoder is trained via contrastive learning—a method similar to CLIP—on a large corpus of molecule-text pairs. By aligning graph features with human-written descriptions, the encoder ensures that the resulting representations are semantically grounded before they ever reach the LLM.

Stage 2: The Graph Tokenizer

The core innovation lies in the Graph Tokenizer. Rather than forcing the LLM to learn an entirely new language, the framework maps graph features onto the LLM’s pre-trained token embeddings.

  • Vocabulary Compression: To manage the massive vocabulary of modern LLMs (e.g., 128k tokens), a compression module condenses graph features into a manageable set of semantic vectors.
  • Cross-Attention Alignment: The system uses graph features as a "query" to retrieve the most relevant information from the LLM’s own token space. Essentially, the model describes the graph using its own pre-existing "prior knowledge."
  • IUPAC Anchoring: To further stabilize the model, prompts include the molecule’s IUPAC name. Since these systematic names likely appeared in the LLM's original training data, they act as familiar anchors that activate the model's latent chemical knowledge.

Experimental Results

Graph2Token was evaluated across several rigorous benchmarks, including MoleculeNet (classification) and QM9 (regression). The researchers utilized multi-source training data from ChEBI and the Human Metabolome Database (HMDB), the latter of which provides critical data on rare and metabolism-related molecules.

Performance and Efficiency

The framework demonstrated superior performance, particularly in few-shot learning scenarios where data is scarce:

  • Classification: On the TOX21 dataset (using only 10% of training data), Graph2Token achieved a ROC-AUC of 72.1, significantly outperforming the previous state-of-the-art model, MolCA (68.5).
  • Regression: In predicting molecular energy gaps (HOMO-LUMO), the model reduced mean absolute error (MAE) by approximately 6-7% compared to existing graph-language models.
  • Parameter Efficiency: Perhaps most importantly, Graph2Token is incredibly efficient. It requires tuning only 8.6 million parameters (0.11% of the total model), compared to the 109 million parameters required by MolCA. This makes it accessible for researchers with limited computational resources.

Conclusion and Future Directions

Graph2Token proves that LLMs can be taught to "see" and understand complex molecular structures without the need for massive retraining or the risk of degrading their core capabilities. By treating graphs as semantic tokens, the framework provides a scalable and efficient bridge between structural biology and generative AI.

While the scarcity of high-quality biological data remains a challenge, future iterations of this work may integrate 3D geometric conformations directly into the tokenization process, further enhancing the LLM's spatial understanding of the molecular world.

Summary updated

BibTeX
@inproceedings{wang2025bridging,
  author = {Runze Wang and Mingqi Yang and Yanming Shen},
  title = {{Bridging Molecular Graphs and Large Language Models}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2025},
  doi = {10.1609/aaai.v39i20.35422},
}
Figure