Abstract
Knowledge Graphs (KGs) are essential for representing structured facts but are often incomplete. Rule mining addresses this by discovering logical patterns to infer missing links. However, traditional methods apply rules statically across all queries. We present Ruleformer, a transformer-based approach that introduces context-awareness to rule mining. By encoding the local subgraph of a query's head entity, Ruleformer dynamically selects the most appropriate rules, significantly improving reasoning accuracy and rule quality over state-of-the-art baselines.
Introduction
Knowledge Graphs represent facts as triplets, such as (New York, isCityOf, USA). Despite their utility, they are notoriously incomplete. Rule mining addresses this by discovering logical patterns like:
nationality(X, Y) ← livesIn(X, Z) ∧ isCityOf(Z, Y)
Existing differentiable rule mining methods (e.g., Neural-LP, DRUM) suffer from a major limitation: they apply rules uniformly for every query of a given relation. This ignores the fact that the "best" logical path often depends on the specific entity's context. For example, as illustrated in Figure 1, determining an ambassador's nationality might require looking at their workplace, whereas for a local employee, their place of residence is more relevant. Ruleformer addresses this by incorporating neighborhood information into the reasoning process.
Methodology
Ruleformer treats rule mining as a sequence-to-sequence (seq2seq) task, comprising two main modules:
1. Context-Aware Encoder
The encoder extracts structural information from the subgraph surrounding the head entity. To adapt the Transformer architecture for graph data, the authors developed a Relational Attention Mechanism. Unlike standard attention, this mechanism explicitly incorporates the relation types (edges) between entities during weight calculation, preserving the graph's structural integrity while feeding it into the Transformer.
2. Rule-Generating Decoder
The decoder takes the encoded context and the target relation to generate a sequence of relations that form the rule's body. The model is trained end-to-end using the TensorLog framework, which converts rule probabilities into entity predictions, allowing it to learn directly from KG facts without requiring ground-truth rules.
Experimental Results
Ruleformer was evaluated on three standard benchmarks: UMLS (medical), FB15K-237 (general knowledge), and WN18RR (lexical).
- Link Prediction: Ruleformer consistently outperformed state-of-the-art rule-based baselines. On the UMLS dataset, it achieved a Hit@1 of 75.2%, a 10.9% absolute improvement over previous methods. It also showed steady gains on the larger FB15K-237 and WN18RR datasets.
- Rule Quality: The "Standard Confidence" of mined rules improved by 43.7% on UMLS and 25.5% on FB15K-237, confirming that context-aware rules are more reliable than static ones.
- Interpretability: Case studies on relations like
_hypernymdemonstrated that the model generates distinct, logically sound rules tailored to different entities, confirming that context-awareness works in practice.
Discussion
The key insight of Ruleformer is that an entity's identity is defined by its neighbors. By modifying the attention mechanism to account for connection types, Ruleformer adapts Transformers for graph data effectively. This allows for dynamic rule confidence—a rule may be highly weighted for one entity but ignored for another based on their respective subgraphs.
While highly effective, the model currently focuses on chain-like rules of fixed lengths (T=2 or 3). Future work will explore more complex, branching rule structures and address the computational overhead associated with subgraph extraction for large-scale KGs.
Conclusion
Ruleformer advances Knowledge Graph reasoning by making rule mining context-aware. Its ability to disambiguate rules based on local neighborhoods sets a new benchmark for accuracy and interpretability in the field of automated reasoning.
Summary updated