Explaining Graph Neural Networks with Large Language Models: A Counterfactual Perspective on Molecule Graphs

Yinhan He, Zaiyi Zheng, Patrick Soga, Yaochen Zhu, Yushun Dong, Jundong Li

Introduction

Graph Neural Networks (GNNs) have emerged as a cornerstone for predicting molecular properties, with applications ranging from drug toxicity screening to identifying novel antiviral treatments. Despite their predictive power, GNNs operate as "black boxes," offering little insight into the chemical logic behind their classifications. To address this, researchers have turned to Graph Counterfactual Explanations (GCE). A counterfactual explanation identifies the minimal structural modification required to flip a model's prediction—for instance, changing a molecule's classification from "non-toxic" to "toxic."

Conceptual overview of Graph Counterfactual Explanations (GCE) in molecular property prediction, showing how small structural changes can flip a model's label.

The Challenge of Chemical Counterfactuals

Existing GCE methods face two primary hurdles. First, they often rely on abstract mathematical optimizations, such as random walks or deep learning heuristics, which produce explanations that are difficult for human experts to interpret. Second, these models frequently lack domain-specific chemical knowledge. Without an understanding of chemical valency and stability, traditional GCE methods may propose "hallucinated" molecules—structures that are mathematically valid within the graph domain but physically impossible to synthesize in a laboratory.

The LLM-GCE Framework

To bridge this gap, a new framework called LLM-GCE has been proposed. This approach utilizes Large Language Models (LLMs) to provide the "chemical common sense" that traditional GNNs lack. The framework adopts a "Director-Actor" paradigm: the LLM acts as the Director, providing high-level chemical reasoning, while a specialized Graph Autoencoder acts as the Actor, translating those instructions into precise structural changes.

The LLM-GCE architecture integrates graph neural networks with LLMs through contrastive pretraining, counterfactual text pair generation, and a dynamic feedback loop.

The architecture consists of three core components:

  1. Contrastive Pretraining: A BERT-based text encoder is pretrained to align its embeddings with a GNN's graph embeddings. This ensures the system can map natural language chemical terms (e.g., "benzene ring") to specific subgraphs.
  2. Counterfactual Text Pair (CTP) Generation: Instead of directly editing the graph, the LLM generates a high-level instruction, such as "replace the carbonyl group with a hydroxylamine group." This CTP is then processed by a decoder to reconstruct the modified graph.
  3. Dynamic Feedback Loop: To ensure the validity of the explanation, the system employs an iterative loop. If a proposed modification fails to flip the GNN's prediction, the result is serialized back into text, and the LLM is prompted to suggest an alternative functional group.

Experimental Results

The researchers evaluated LLM-GCE across five standard molecular benchmarks, including AIDS, Mutagenicity, and BBBP (Blood-Brain Barrier Penetration). The results demonstrate a significant advancement in chemical feasibility. In the BBBP dataset, LLM-GCE achieved a validity score of 38.25% under strict chemical feasibility checks (using RDKit), whereas all baseline models scored below 10%. Furthermore, LLM-GCE identified "closer" counterfactuals, meaning it found more subtle and precise modifications than previous state-of-the-art methods.

Conclusion

LLM-GCE represents a significant step toward making GNNs chemically literate. By offloading high-level reasoning to LLMs and structural execution to graph decoders, the framework produces explanations that are both human-understandable and scientifically grounded. Future work will look toward extending this framework to 3D molecular structures and incorporating human-in-the-loop evaluations to further validate the utility of these explanations in real-world drug discovery pipelines.

Summary updated

BibTeX
@inproceedings{he2024explaining,
  author = {Yinhan He and Zaiyi Zheng and Patrick Soga and Yaochen Zhu and Yushun Dong and Jundong Li},
  title = {{Explaining Graph Neural Networks with Large Language Models: A Counterfactual Perspective on Molecule Graphs}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2024},
  doi = {10.18653/v1/2024.findings-emnlp.415},
}
Figure