Manuscript Offprint

arXiv:2610.23766

Logic-Guided Graph Denoising Diffusion Models

Samuel Cognolato, Luciano Serafini, Alessandro Sperduti, Andrea Cavallaro

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original. This text is shared under the same licence.

Abstract

Graph diffusion models are competitive approaches for generating complex graph-structured data. However, when such distributions have strict structural constraints, diffusion models may fail to capture them exactly, resulting in the generation of invalid graphs. In this paper, we propose a method for grounding graph diffusion models in domain-specific knowledge via First Order Logic (FOL), leveraging its expressive and interpretable formalism to impose structural constraints on the generative process. We incorporate domain knowledge using classifier guidance, a technique that conditions the diffusion model's distribution on external variables to exert control over the sampled data. During the generative process, classifier guidance steers the denoising trajectory to optimize an objective function, which we define as a fuzzy and differentiable relaxation of the logical rules. Our methodology requires only the specification of constraints in FOL, whose satisfaction is encouraged at inference time to guide a pre-trained generative model. We evaluate our approach by comparing the unconditional generation of knowledge graphs with our logic-guided framework, which incorporates domain ontologies as structural constraints during inference. This approach significantly increases the proportion of generated graphs that satisfy the ontological constraints.

1 Introduction

Graph generation involves learning an underlying data distribution to facilitate the synthesis of novel, realistic graph structures. Graph diffusion models (Jo, Lee, and Hwang 2022; Vignac et al. 2023; Huang et al. 2023; Cognolato et al. 2026; Cognolato, Sperduti, and Serafini 2026) and flow-matching models (Eijkelboom et al. 2024; Qin et al. 2024) can model distributions over graphs with discrete labels and continuous attributes. In some applications, such as biology, graphs need to satisfy domain-specific rules (Rigoni, Navarin, and Sperduti 2020) that define whether a graph is well-formed. However, neural generative models lack a mechanism to explicitly enforce structural constraints, which requires specialized techniques to tackle them. Thus, the problem of constrained graph generation, i.e., sampling graphs from a subspace of elements satisfying a set of constraints, has gained traction (Liu et al. 2018; Rigoni, Navarin, and Sperduti 2025; Madeira et al. 2024).

First Order Logic (FOL) (Barwise 1977) may serve as a unified approach to encode and combine heterogeneous constraints. FOL can be used to formalize properties in graphs, where node and edge labels are represented as unary and binary predicates, respectively (Cai, Fürer, and Immerman 1992). The rules may act on single nodes, their neighbors, and the type or direction of the relations, e.g., bipartiteness and transitivity. FOL rules may also act considering the whole graph structure, e.g., requiring the presence of a specific node type. The ability to operate both locally and globally provides a tool for controlling the structure and content of graphs. This setup has enabled the definition of ontologies for knowledge graphs, providing a schema for otherwise unstructured data (Gruber 1993).

In this paper, we propose LTN-guidance, a methodology for injecting domain knowledge as FOL constraints into the generative process of graph diffusion models (Vignac et al. 2023), without any additional training. Our aim is to increase the probability of sampling valid graphs. First, we propose a graph signature, i.e., the collection of symbols defining the vocabulary of the first order language, enabling the definition of logical formulas over labeled graphs. During generation, we use classifier guidance (Dhariwal and Nichol 2021) to steer a pre-trained diffusion model toward optimizing rule satisfaction (the external objective function). Our method provides the target FOL constraints as Logic Tensor Network (LTN) (Badreddine et al. 2022) differentiable functions. A mechanism based on Focal Loss (Lin et al. 2017) allows adaptive reweighting of constraints, increasing the contribution of less satisfied sentences in the generative process. Finally, we propose cheaper implementations of LTN functions, e.g., for implementing cardinality constraints over edges.

Our main contributions are:

  1. A graph signature that allows the definition of logical rules over labeled graphs. We integrate the signature with axioms to ensure label exclusivity;

  2. A plug-and-play method for steering graph diffusion models with knowledge in FOL. During inference, FOL constraints are translated to differentiable functions through Logic Tensor Network, and used to steer a pretrained unconditional model with classifier guidance.

Preprint

  1. We evaluated a popular graph diffusion model, DiGress (Vignac et al. 2023), with and without our technique, for the generation of small knowledge graphs from the IntelliGraphs benchmark (Thanapalasingam et al. 2023) against knowledge graph embedding and LLM-based approaches. We observe an improvement in validity, achieving > 95% in most datasets.

  2. We performed generation with new rules, compatible and conflicting with the data, to evaluate the conditional in-distribution and out-of-distribution validity, respectively. LTN-guidance consistently shows responsiveness to input formulas by producing a high fraction of valid graphs.

To the best of our knowledge, this is the first inference-time FOL constraints guidance framework for graph diffusion.

References (48)

  • Pytorch 2: Faster machine learning through dynamic python bytecode transformation and graph compilation
  • Structured denoising diffusion models in discrete state-spaces
  • Logic tensor networks
  • An introduction to first-order logic
  • An optimal lower bound on the number of variables for graph identification
  • Generating in-distribution counterfactual explanation for graph neural networks
  • D4: Distance diffusion for a truly equivariant molecular design
  • FLAGG: Flexible Autoregressive Graph Generation
  • RDF 1.1 concepts and abstract syntax
  • Herbrand's Theorem
  • Diffusion models beat gans on image synthesis
  • A Generalization of Transformer Networks to Graphs
  • Pytorch lightning
  • Fast Graph Representation Learning with PyTorch Geometric
  • A translation approach to portable ontology specifications
  • Denoising diffusion probabilistic models
  • N.; Polleres, A.; Rashid, S. M.; Rula, A.; Schmelzeisen, L.; Sequeda, J.; Staab, S.; and Zimmermann, A. 2021
  • Conditional diffusion based on discrete graph structures for molecular graph generation
  • Score-based generative modeling of graphs via the system of stochastic differential equations
  • Focal loss for dense object detection
  • Constrained graph variational autoencoders for molecule design
  • Generative Modelling of Structurally Constrained Graphs
  • Knowledge graphs: Opportunities and challenges
  • Advancing retrosynthesis with retrieval-augmented graph generation
  • Defog: Discrete flow matching for graph generation (opens arXiv in a new tab)
  • Conditional constrained graph variational autoencoders for molecule design
  • RGC-VAE: relational graph conditioned variational autoencoder for molecule design
  • IntelliGraphs: Datasets for Benchmarking Knowledge Graph Generation (opens arXiv in a new tab)
  • On Evaluation Metrics for Graph Generative Models
  • Complex embeddings for simple link prediction
  • The complexity of enumeration and reliability problems
  • Lifted probabilistic inference by first-order knowledge compilation
  • DiGress: Discrete Denoising diffusion for graph generation
  • Provcreator: Synthesizing complex heterogeneous graphs with node and edge attributes (opens arXiv in a new tab)
  • Lifted algorithms for symmetric weighted first-order model sampling
  • Hydra—A Framework for Elegantly Configuring Complex Applications
  • Exploring Large Language Models for Knowledge Graph Completion
  • As mentioned in the main text, we split the guidance weight $\lambda$ into node and edge components $\lambda_x$ and $\lambda_e$
  • All experiments are run with the model obtained from seed 0
  • \tag {34} $$
  • The three nodes are pairwise distinct:
  • \tag {36} $$
  • For support shift, we retain the five-triple schema but replace the original temporal-order rule with its strict reverse:
  • The color-bar scale is set independently in each panel to emphasize differences within each dataset, so colors should not be compared across datasets
  • KGs represent information with nodes being entities of interest and edges being relations between them
  • The domain is partitioned into subsets $\mathcal{D}_1, \ldots, \mathcal{D}_N$, each identifying an entity type
  • Mathematically, the node labels set is $\mathcal{L}_v = \mathcal{D}$ and the edge labels set is $\mathcal{L}_e = \mathcal{R}$
  • Type your response here