Contextual Graph Attention for Answering Logical Queries over Incomplete Knowledge Graphs

Gengchen Mai, Krzysztof Janowicz, Bo Yan, Rui Zhu, Ling Cai, Ni Lao · DOI

Abstract: Recently, several studies have explored methods for using KG embedding to answer logical queries. These approaches either treat embedding learning and query answering as two separated learning tasks, or fail to deal with the variability of contributions from different query paths. We proposed to leverage a graph attention mechanism to handle the unequal contribution of different query paths. However, commonly used graph attention assumes that the center node embedding is provided, which is unavailable in this task since the center node is to be predicted. To solve this problem we propose a multi-head attention-based end-to-end logical query answering model, called Contextual Graph Attention model(CGA), which uses an initial neighborhood aggregation layer to generate the center embedding, and the whole model is trained jointly on the original KG structure as well as the sampled query-answer pairs. We also introduce two new datasets, DB18 and WikiGeo19, which are rather large in size compared to the existing datasets and contain many more relation types, and use them to evaluate the performance of the proposed model. Our result shows that the proposed CGA with fewer learnable parameters consistently outperforms the baseline models on both datasets as well as Bio dataset.

Introduction

Knowledge Graphs (KGs) like DBpedia or Wikidata are massive but notoriously incomplete. If a standard database is asked a complex logical query—for example, "Find a person who graduated from UCLA and died of cardiovascular disease"—the query will return nothing if even a single "triple" (fact) is missing from the graph.

Figure 1: A logical query graph representing the search for a person based on multiple constraints.

To solve this, researchers use KG Embeddings to map entities and relations into a continuous vector space to predict missing links. However, existing models like Graph Query Embedding (GQE) treat all paths to an answer as equally important. In reality, some facts are more "discriminative" than others. While standard Graph Attention Networks (GATs) could solve this weighting problem, they require knowledge of the "center node" (the answer) to calculate attention scores. Since the answer is exactly what the model is trying to predict, standard attention mechanisms face a "chicken-and-egg" prerequisite trap.

The Contextual Graph Attention (CGA) Model

The authors propose the Contextual Graph Attention (CGA) model, which utilizes a multi-stage process to handle unknown target variables. The architecture unblocks the use of attention for predictive tasks by generating a proxy for the center node.

Figure 4: The architecture of the CGA model, featuring initial neighborhood aggregation followed by multi-head attention.
  1. Initial Intersection: The model first generates a "rough guess" of the target variable's embedding ($e''_{init}$) using a simple, permutation-invariant function (like an element-wise minimum or mean) across all incoming query paths.
  2. Multi-Head Attention: This "rough guess" acts as the context. The model compares each individual path to this context to calculate attention weights, allowing it to prioritize the most informative paths (e.g., rare, specific relations over high-frequency, low-information ones).
  3. Refinement: The weighted information is passed through a residual connection, layer normalization, and a feed-forward network to produce the final prediction.

Crucially, the model is jointly trained on both the original KG structure and sampled query-answer pairs. This ensures the model understands both the global geometry of the graph and the specific logic of complex queries.

Experimental Evaluation

The authors evaluated CGA on three datasets, including two new benchmarks that are significantly larger and more complex than those typically used in the field:

  • Bio: A standard biological interaction dataset with regenerated queries to test realistic "unanswerable" cases.
  • DB18 (New): Derived from DBpedia, focusing on geographic entities in California with 175 relation types.
  • WikiGeo19 (New): Derived from Wikidata, focusing on major US cities with 192 relation types.

Key Results and Insights

  • Superior Accuracy: CGA consistently outperformed baselines (GQE, TransE, DistMult) across all datasets. It showed particular strength on "hard negative" queries—cases where an entity satisfies some but not all parts of a complex query. On the Bio dataset, CGA achieved a 7.3% relative improvement in Area Under the Curve (AUC) over GQE.
  • Multi-Head Advantage: Using multiple attention heads (e.g., 4 or 8) consistently yielded better results, proving that the model benefits from looking at data through different "logical lenses."
  • Efficiency: Despite its increased complexity, CGA uses fewer learnable parameters than the baseline GQE model due to efficient bilinear projections and weight sharing across attention heads.

Conclusion and Future Work

CGA demonstrates that intelligent path weighting can significantly improve logical query answering in incomplete KGs. Future research will focus on moving from a transductive setting to an inductive one that can handle entirely new entities, as well as expanding the logical scope to include disjunction (OR) and negation (NOT).

Summary updated

Abstract

Recently, several studies have explored methods for using KG embedding to answer logical queries. These approaches either treat embedding learning and query answering as two separated learning tasks, or fail to deal with the variability of contributions from different query paths. We proposed to leverage a graph attention mechanism to handle the unequal contribution of different query paths. However, commonly used graph attention assumes that the center node embedding is provided, which is unavailable in this task since the center node is to be predicted. To solve this problem we propose a multi-head attention-based end-to-end logical query answering model, called Contextual Graph Attention model(CGA), which uses an initial neighborhood aggregation layer to generate the center embedding, and the whole model is trained jointly on the original KG structure as well as the sampled query-answer pairs. We also introduce two new datasets, DB18 and WikiGeo19, which are rather large in size compared to the existing datasets and contain many more relation types, and use them to evaluate the performance of the proposed model. Our result shows that the proposed CGA with fewer learnable parameters consistently outperforms the baseline models on both datasets as well as Bio dataset.

Empirical ResultsBrowse all benchmarks →

BenchmarkMethodMetricScoreProtocol / Evidence
BioCGA+4AUC76.12+3.89 vs baselinesplit: test · aggregation=macro-averaged · negative-sampling=hard-negative
Source quote
L350: \cga{+4} │ 85.13 │ 76.12 │ 85.46 │ 77.8 │ 84.46 │ 67.88 │ 87.05 │ 74.66 │ 83.96 │ 64.96 │ 85.36 │ 69.64
Reported baseline / comparator measurements (3)
BenchmarkMethodMetricScoreProtocol / Evidence
BioGQE+KG[min] baselineAUC72.23split: test · aggregation=macro-averaged · negative-sampling=hard-negative
Source quote
L348: GQE+KG{[}min{]} │ 83.69 │ 72.23 │ 84.07 │ 74.3 │ 84.23 │ 68.06 │ 86.32 │ 73.49 │ 83.66 │ 64.48 │ 84.73 │ 68.51
DB18GQE+KG[min] baselineAUC68.06split: test · aggregation=macro-averaged · negative-sampling=hard-negative
Source quote
L348: GQE+KG{[}min{]} │ 83.69 │ 72.23 │ 84.07 │ 74.3 │ 84.23 │ 68.06 │ 86.32 │ 73.49 │ 83.66 │ 64.48 │ 84.73 │ 68.51
WikiGeo19GQE+KG[min] baselineAUC64.48split: test · aggregation=macro-averaged · negative-sampling=hard-negative
Source quote
L348: GQE+KG{[}min{]} │ 83.69 │ 72.23 │ 84.07 │ 74.3 │ 84.23 │ 68.06 │ 86.32 │ 73.49 │ 83.66 │ 64.48 │ 84.73 │ 68.51
BibTeX
@inproceedings{mai2019contextual,
  author = {Gengchen Mai and Krzysztof Janowicz and Bo Yan and Rui Zhu and Ling Cai and Ni Lao},
  title = {{Contextual Graph Attention for Answering Logical Queries over Incomplete Knowledge Graphs}},
  booktitle = {K-CAP},
  year = {2019},
  url = {https://openreview.net/forum?id=aOORG8NbK65},
}
Figure