[Paper Review] Transformers over Directed Acyclic Graphs
This paper proposes DAGFormer, a transformer architecture adapted for directed acyclic graphs (DAGs) via a novel attention mechanism that restricts receptive fields to reachable predecessors and successors, reducing computational complexity while preserving structural fidelity. It further integrates depth-based positional encoding to capture DAG topology. The method outperforms both standard graph transformers and DAG-specific GNNs in accuracy and efficiency across diverse DAG tasks, including source code and citation networks.
Transformer models have recently gained popularity in graph representation learning as they have the potential to learn complex relationships beyond the ones captured by regular graph neural networks. The main research question is how to inject the structural bias of graphs into the transformer architecture, and several proposals have been made for undirected molecular graphs and, recently, also for larger network graphs. In this paper, we study transformers over directed acyclic graphs (DAGs) and propose architecture adaptations tailored to DAGs: (1) An attention mechanism that is considerably more efficient than the regular quadratic complexity of transformers and at the same time faithfully captures the DAG structure, and (2) a positional encoding of the DAG's partial order, complementing the former. We rigorously evaluate our approach over various types of tasks, ranging from classifying source code graphs to nodes in citation networks, and show that it is effective in two important aspects: in making graph transformers generally outperform graph neural networks tailored to DAGs and in improving SOTA graph transformer performance in terms of both quality and efficiency.
Motivation & Objective
- To address the lack of structural inductive bias in standard transformers when applied to DAGs, which encode partial order and reachability.
- To design an attention mechanism that maintains expressivity while reducing the quadratic complexity typical of transformers.
- To integrate positional encoding that reflects node depth in the DAG's partial order to enhance structural awareness.
- To evaluate the framework across diverse DAG types, demonstrating superiority over both GNNs and existing graph transformers.
- To provide a general, efficient, and extensible framework compatible with existing transformer and GNN architectures.
Proposed method
- Introduce a DAG-aware attention mechanism that restricts each token’s attention to only those nodes reachable via directed paths, effectively limiting the receptive field to predecessors and successors.
- Use a learnable mask matrix to enforce this restriction, ensuring attention is computed only over nodes that are topologically ordered and reachable.
- Introduce a depth-based positional encoding that explicitly encodes each node’s position in the DAG’s partial order, complementing the attention mechanism.
- Formulate the attention computation as a differentiable, sparse operation that maintains parallelism and reduces FLOPs compared to standard self-attention.
- Enable integration into both standalone transformers and message-passing GNNs by designing the framework as a plug-in module.
- Implement the method in a modular way, allowing deployment on top of existing models such as vanilla transformers or SOTA graph transformers.
Experimental results
Research questions
- RQ1Can a transformer-based architecture be effectively adapted to exploit the partial order and reachability structure of DAGs?
- RQ2Does restricting attention to only reachable nodes improve both model efficiency and performance on DAG tasks?
- RQ3To what extent does depth-based positional encoding enhance the representation of DAG structure in transformers?
- RQ4Can the proposed framework outperform both standard graph transformers and DAG-specific GNNs in accuracy and inference speed?
- RQ5How does the size of the receptive field (k) affect performance and training time across different DAG datasets?
Key findings
- The proposed DAG attention mechanism reduces computational complexity significantly, achieving up to 4x faster training than baseline GNNs like DAGNN, with 10 minutes per epoch on ogbg-code2 compared to 100 minutes.
- On the ogbg-code2 dataset, the method achieved a test F1 score of 0.2018 with DAG+SAT, outperforming the baseline SAT model (0.2000) and DAGNN (0.1975).
- Increasing the receptive field size (k) from 1 to ∞ led to a consistent performance gain, with F1 rising from 0.1724 to 0.1879 for DAG+TF and from 0.1533 to 0.2018 for DAG+SAT.
- The average number of reachable nodes (n_k) for k=∞ was 9.78 on ogbg-code2, far below the total node count, indicating that the method remains efficient even with full reachability.
- The framework improves SOTA graph transformers in both quality and efficiency, demonstrating that structural bias via attention and positional encoding is critical for DAG representation learning.
- The method generalizes well, improving performance across diverse DAG types, including source code graphs, citation networks, and logical formulas.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.