Contextual Graph Attention for Answering Logical Queries over Incomplete Knowledge Graphs

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

TL;DR

Knowledge graphs are often incomplete, causing complex logical queries to fail. This paper introduces Contextual Graph Attention (CGA), an end-to-end model that predicts missing answers by intelligently weighting different information paths. By solving the "chicken-and-egg" problem of applying attention to unknown variables, CGA outperforms existing methods while remaining more parameter-efficient.

What Problem Does This Paper Address?

Knowledge Graphs (KGs) like DBpedia or Wikidata are massive but notoriously incomplete. If you ask a standard database a 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.

To solve this, researchers use KG Embeddings, which map entities and relations into a continuous vector space to "guess" missing links. However, existing models like Graph Query Embedding (GQE) have a major flaw: they treat all paths to an answer as equally important. In reality, some facts are more "discriminative" than others. Knowing someone was a guest on a specific obscure TV show is a much stronger hint about their identity than knowing they went to a massive university like UCLA.

Standard Graph Attention Networks (GATs) could solve this weighting problem, but they require you to know the "center node" (the answer) to calculate attention scores. Since the answer is exactly what we are trying to predict, standard attention doesn't work.

Methods

The authors propose the Contextual Graph Attention (CGA) model, which uses a two-step process to handle unknown variables:

  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. This allows the model to prioritize the most informative paths.
  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. It learns from both the original KG structure (local neighborhoods) and sampled "query-answer" pairs. This ensures the model understands both the global geometry of the graph and the specific logic of complex queries.

Datasets

The authors evaluated CGA on three datasets:

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

The two new datasets are significantly larger and more complex (having 4x more relation types) than the benchmarks typically used in this sub-field.

Key Insights and Ideas

  • Solving the Prerequisite Trap: The "aha moment" is the use of an initial neighborhood aggregation to create a proxy for the center node. This unblocks the use of attention mechanisms for predictive tasks where the target is unknown.
  • Information Density: The model confirms that not all triples are equal. By using attention, the model can "ignore" high-frequency, low-information relations (like a general "type" relation) in favor of rare, specific relations that point directly to the answer.
  • The Power of Joint Training: The paper shows that training on the raw KG structure is just as important as training on the queries themselves. It provides a structural "prior" that helps the model generalize to complex, multi-step logic.
  • Efficiency: Despite being more "intelligent," the CGA model actually uses fewer learnable parameters than the baseline GQE model because it uses a more efficient bilinear projection and shares weights across attention heads.

Key Results

  • Superior Accuracy: CGA consistently outperformed baselines (GQE, TransE, DistMult) across all datasets.
  • Handling "Hard Negatives": The model showed its greatest 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 than a single-head approach, proving that the model benefits from looking at the data through different "logical lenses."

Limitations and Future Work

  • Transductive Setting: The current model is "transductive," meaning it can only answer queries about entities it saw during training. The authors aim to move toward an inductive setup that can handle entirely new entities.
  • Logical Scope: The model currently handles Conjunctive Graph Queries (AND logic). It does not yet support disjunction (OR), negation (NOT), or complex filters (e.g., "population > 1 million").
  • Predicate Knowledge: The model assumes the relations (predicates) in the query are known and correctly labeled; it does not yet handle noise or ambiguity in the query strings themselves.

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},
}

Loading related content...

Figure