Form follows Function: Text-to-Text Conditional Graph Generation based on Functional Requirements

Peter A. Zachares, Vahan Hovhannisyan, Alan Mosca, Yarin Gal · DOI

Introduction

Generating graph-structured data, such as molecular structures or knowledge graphs, has traditionally been approached as an imperative task. Models are typically provided with structural "recipes"—step-by-step descriptions of nodes and edges—and tasked with reconstructing the corresponding graph. However, in practical applications, the primary concern is often the function of the graph rather than its specific form. For instance, a chemist may seek a molecule with specific drug-likeness or valency properties without knowing the exact arrangement of atoms required to achieve them.

This paper introduces SGG-LLM (Serialized Graph Generator Large Language Model), a framework designed to bridge the gap between high-level functional requirements and structural graph generation. By fine-tuning LLMs with structural inductive biases, the authors enable models to "understand" connectivity while leveraging their inherent text-generation capabilities.

The Challenge of Functional Graph Generation

Current Large Language Models (LLMs) excel at processing linear sequences but struggle with the non-linear, multi-dimensional nature of graphs. The authors identify two primary hurdles:

  1. Functional Conditioning: The ability to generate a graph from abstract goals (e.g., "design a molecule with high drug-likeness") instead of structural blueprints.
  2. Structural Awareness: Providing a linear model with the "spatial" intuition necessary to navigate and construct complex node-edge relationships.

The SGG-LLM Framework

The core of the proposed solution is the integration of message-passing (MP) layers directly into the transformer architecture of a pre-trained LLM.

Architectural Innovations

The SGG-LLM architecture employs several key strategies to maintain stability and performance:

  • Interleaved Message Passing Layers: GraphSAGE layers are inserted between standard transformer layers. These layers allow the model to aggregate information from neighboring nodes during the autoregressive generation process.
  • Learned Gating Mechanism: To prevent the complex graph structures from disrupting the pre-trained LLM's internal representations, a tanh gating parameter is used. Initialized at zero, this allows the model to gradually incorporate structural information during training.
  • Graph Serialization with Disambiguation: Graphs are converted into a "bag-of-edges" text format. To handle duplicate node types (e.g., multiple Carbon atoms), a disambiguation token <D> followed by a unique identifier is introduced.
Overview of the SGG-LLM training and generation pipeline, highlighting the interleaved architecture.

Causal Graph Attention

A critical component of SGG-LLM is the Causal Graph Attention masking strategy. Because the model generates graphs autoregressively, it must only attend to previously generated elements. The authors designed a mask that combines standard causal attention with graph connectivity, ensuring that message-passing layers only share information from "past" nodes in the sequence.

The masking strategy for causal graph attention, ensuring the model remains autoregressive while respecting graph structure.

Experimental Evaluation

The researchers evaluated SGG-LLM across two distinct domains:

  1. Molecular Design (PCQM4M): A new benchmark was established using 2 million small molecules. Models were tasked with generating molecules based on functional properties like Valency Electrons and Quantitative Estimate of Drug-likeness (QED).
  2. Knowledge Graphs (WebNLG+ 2020): This benchmark tested the model's ability to generate subject-predicate-object triples from natural language descriptions.

Key Results

  • Accuracy: SGG-LLM significantly outperformed baselines such as grapher and regen. On the Valency dataset, it achieved a Mean Absolute Error (MAE) of 0.035, a stark improvement over regen's 2.282.
  • Parsability and Validity: The model achieved near-perfect parsability scores (~1.0), indicating that generated graphs were syntactically correct and chemically valid.
  • Diversity: The framework successfully handled one-to-many mappings, generating a diverse set of unique, valid molecules for a single functional prompt.

Key Insights

The study revealed that the gating mechanism is essential for convergence; without it, the model fails to integrate the disruptive graph data. Additionally, the authors found that equal weighting per example in the loss function—rather than weighting by token count—improved performance by preventing over-emphasis on the most complex graphs. Ultimately, the inclusion of message-passing layers proved that internal structural understanding is vital for achieving high functional accuracy.

Conclusion

SGG-LLM demonstrates that LLMs can be effectively taught to design graphs based on functional requirements by incorporating structural inductive biases. While challenges remain regarding computational scaling and extrapolation to out-of-distribution graphs, this work provides a robust foundation for functional, text-conditioned graph generation.

Summary updated

BibTeX
@misc{zachares2023form,
  author = {Peter A. Zachares and Vahan Hovhannisyan and Alan Mosca and Yarin Gal},
  title = {{Form follows Function: Text-to-Text Conditional Graph Generation based on Functional Requirements}},
  year = {2023},
  eprint = {2311.00444},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2311.00444},
}
Figure