Bridging Molecular Graphs and Large Language Models

Runze Wang, Mingqi Yang, Yanming Shen

TL;DR

Graph2Token is a novel framework that allows Large Language Models (LLMs) to understand molecular graphs effectively without altering a single weight of the LLM backbone. By mapping graph structures directly into the LLM's existing token vocabulary space using a cross-attention mechanism, it fully preserves the LLM's powerful few-shot generalization capabilities for biochemical classification and regression tasks.

What Problem Does This Paper Address?

While Large Language Models (LLMs) are phenomenal at processing natural language, they struggle with graph-structured data like molecules. To make LLMs "chemical-literate," current approaches typically do one of two things:

  1. Textualization: Flatten the molecular graph into text strings like SMILES or SELFIES. However, this strips away crucial 2D/3D structural topology and often leads to model hallucinations.
  2. Graph-Language Tuning: Use a trainable projector (like a Q-Former) to map graph features into the LLM's embedding space, often combined with Parameter-Efficient Fine-Tuning (PEFT) like LoRA.

The catch with the second approach is that fine-tuning the LLM—even slightly—can distort its internal semantic space. In data-scarce scenarios (few-shot learning), this leads to catastrophic forgetting, degrading the LLM's ability to generalize to unseen tasks or handle large shifts in data distributions.

The authors of this paper ask a fundamental question: Can we harness the rich prior knowledge of LLMs to understand molecular graphs without fine-tuning the LLM backbone at all?

Different approaches of applying LLMs to molecules.

Methods

The authors introduce Graph2Token, a two-stage framework designed to treat a molecular graph as a special token (<|graph|>) and describe it using the LLM's existing vocabulary.

Overall training process of Graph2Token.
  • Stage 1: Graph-Text Alignment: A Graph Isomorphism Network (GIN) and a text BERT encoder are trained via contrastive learning (using an InfoNCE loss, similar to CLIP). This brings molecular graph structures and textual descriptions closer together in a shared feature space.
  • Stage 2: Graph Tokenization via Vocabulary Retrieval: To feed the graph into a frozen LLM, the framework uses a unique Graph Tokenizer. Because LLM vocabularies are massive (e.g., 32k to 128k tokens), a Vocabulary Compressor first condenses the token embeddings into a smaller set of semantic vectors. Then, a Cross Association and Retrieval module uses cross-attention: the graph features act as queries ($Q$), while the compressed LLM token embeddings act as keys ($K$) and values ($V$). This effectively "looks up" the closest concepts in the LLM's existing vocabulary to represent the novel graph token.

The prompt fed to the completely frozen LLM includes the molecule's IUPAC name (acting as a textual anchor), the newly synthesized graph token, the task description, and an instruction placeholder (<|value|>) which maps to a lightweight task head for final predictions.

Illustration of Graph2Token’s architecture on aligning a graph token with LLM vocabulary.

Datasets

  • Pre-training (Stage 1): The authors compiled a multi-source molecular-text dataset combining ChEBI and the Human Metabolome Database (HMDB). HMDB specifically adds rare and human-metabolism-related molecules, enriching the biological context.
  • Evaluation (Classification): Evaluated on 15 tasks from MoleculeNet, including BBBP (Blood-Brain Barrier Penetration), BACE, HIV, and TOX21.
  • Evaluation (Regression): Evaluated on quantum chemistry datasets QM9 and PubChemQC to predict energy properties like HOMO, LUMO, and the HOMO-LUMO gap.

Key Insights and Ideas

  • Vocabulary as a Prior Knowledge Base: Instead of forcing the LLM to understand a brand-new continuous vector space, Graph2Token forces the graph encoder to speak the LLM's native tongue. It treats the pre-trained token embeddings as a discrete knowledge base to draw from.
  • The Power of Freezing: By keeping the LLM backbone 100% frozen, the model retains its core reasoning and instruction-following capabilities, preventing the hallucinations and performance drops typically seen when fine-tuning on small molecular datasets.
  • IUPAC Names as Anchors: Including IUPAC names directly in the prompt helps activate the LLM's latent scientific knowledge, bridging the gap between the raw graph structure and textual chemical literature.

Key Results

  • Superior Few-Shot Classification: In 5% and 10% few-shot learning setups on MoleculeNet, Graph2Token consistently outperformed graph-based models and state-of-the-art graph-language models like MolCA. For instance, when trained on BACE/BBBP/HIV and evaluated on the unseen tasks of TOX21 (10% shot), Graph2Token achieved an ROC-AUC of 72.1, compared to MolCA's 67.2.
  • Accurate Regression: On the PubChemQC-IUPAC regression tasks, Graph2Token achieved a 7.1% (5-shot) and 6.4% (10-shot) reduction in Mean Absolute Error (MAE) compared to MolCA, proving highly resilient against hallucinations in numerical predictions.
  • Extreme Parameter Efficiency: Graph2Token only tunes 8.60 million parameters (representing a mere 0.11% training ratio for a Llama3-8B backbone). This is vastly more efficient than MolCA (109.09M parameters / 7.65% ratio).

Limitations and Future Work

The authors note that the framework's performance is inherently tied to the quality and diversity of the initial graph-text paired dataset used in Stage 1. If the pre-training data lacks coverage of certain chemical spaces, the graph encoder may struggle to generate accurate query patterns.

For future work, the authors suggest expanding this vocabulary-alignment strategy to other complex, non-textual modalities and broader graph-reasoning tasks outside of the biochemical domain.

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