NLProlog: Reasoning with Weak Unification for Question Answering in Natural Language

Leon Weber, Pasquale Minervini, Jannes Münchmeyer, Ulf Leser, Tim Rocktäschel

Abstract

Rule-based models are attractive for various tasks because they inherently lead to interpretable and explainable decisions and can easily incorporate prior knowledge. However, such systems are difficult to apply to problems involving natural language, due to its large linguistic variability. In contrast, neural models can cope very well with ambiguity by learning distributed representations of words and their composition from data, but lead to models that are difficult to interpret. In this paper, we describe a model combining neural networks with logic programming in a novel manner for solving multi-hop reasoning tasks over natural language. Specifically, we propose to use an Prolog prover which we extend to utilize a similarity function over pretrained sentence encoders. We fine-tune the representations for the similarity function via backpropagation. This leads to a system that can apply rule-based reasoning to natural language, and induce domain-specific natural language rules from training data. We evaluate the proposed system on two different question answering tasks, showing that it outperforms two baselines – BiDAF (Seo et al., 2016a) and FastQA( Weissenborn et al., 2017) on a subset of the WikiHop corpus and achieves competitive results on the MedHop data set (Welbl et al., 2017).

Introduction

The AI community has long faced a trade-off between the flexibility of neural models and the interpretability of symbolic systems. Neural models, such as BiDAF, excel at handling the inherent variability and ambiguity of human language but operate as "black boxes." Conversely, rule-based systems like Prolog offer perfect transparency and strong generalization from small datasets but are notoriously brittle, failing when linguistic expressions do not match exactly (e.g., "was born in" vs. "birthplace").

NLProlog addresses this gap, specifically targeting multi-hop reasoning—tasks that require connecting disparate pieces of information across multiple documents. By combining the strengths of both paradigms, the system aims to understand semantically similar phrases while following a rigorous logical chain of evidence.

Methodology: Weak Unification

The core innovation of NLProlog is Weak Unification. In traditional logic programming, two terms unify only if they are identical. NLProlog replaces this strict matching with a differentiable similarity function.

The NLProlog architecture combining triple extraction, sentence encoding, and a logic prover.

The system operates through several key stages:

  1. Triple Extraction: Using spaCy, the system identifies entities and converts sentences into $(subject, predicate, object)$ triples. The predicate is represented by the sentence text with entities masked.
  2. Weak Unification Mechanism: When the Prolog prover attempts to match a goal to a fact, it calculates the cosine similarity between their vector embeddings. If this similarity exceeds a threshold $\lambda$, the unification succeeds, contributing to a "proof score."
  3. End-to-End Learning: The similarity function is differentiable, allowing the system to fine-tune sentence encoders (Sent2Vec + MLP) via backpropagation.
  4. Rule Learning: Utilizing Inductive Logic Programming (ILP) templates, the system can learn logical rules from data, such as transitivity in geographic locations.
  5. Pruning Strategy: To manage the computational complexity of symbolic reasoning, the authors implemented a pruning strategy that discards proof paths falling below a dynamic similarity threshold.

Experimental Evaluation

The authors evaluated NLProlog on two multi-hop Question Answering (QA) benchmarks: MEDHOP, which focuses on drug-protein interactions in medical abstracts, and a subset of WIKIHOP, targeting specific predicates like publisher, developer, and country.

Performance comparison of NLProlog against neural baselines on MedHop and WikiHop predicates.

As shown in the results table, NLProlog demonstrated significant improvements over strong neural baselines. On the WikiHop publisher predicate, NLProlog achieved 83.33% accuracy, outperforming BiDAF (66.67%) and FastQA (62.96%). On the MedHop dataset, it reached 65.78% accuracy, surpassing the best neural baseline by over 13 percentage points.

Ablation studies highlighted the importance of the symbolic component; removing logical rules led to a significant drop in performance, confirming that the model utilizes logical reasoning rather than simple pattern matching. Additionally, fine-tuning entity representations via a Multi-Layer Perceptron (MLP) proved vital for recognizing different mentions of the same concept.

Discussion and Conclusion

NLProlog represents a significant step toward neuro-symbolic AI for natural language. By using similarity as a proxy for truth within a logic engine, the model can reason over raw text without manual conversion into formal symbols. This "soft logic" approach provides inherent interpretability, as the system generates literal proof trees showing the rules and sentences used to reach an answer.

However, challenges remain. The system's performance is currently bounded by the accuracy of the initial triple extraction. Furthermore, while pruning helps, the computational cost of reasoning over millions of triples is higher than that of pure neural retrievers. Future work may involve integrating more advanced encoders like BERT and extending the framework to handle more complex logical structures, such as temporal reasoning.

Summary updated

BibTeX
@inproceedings{weber2019nlprolog,
  author = {Leon Weber and Pasquale Minervini and Jannes Münchmeyer and Ulf Leser and Tim Rocktäschel},
  title = {{NLProlog: Reasoning with Weak Unification for Question Answering in Natural Language}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2019},
  url = {https://openreview.net/forum?id=3Zrrlw8rELd},
}
Figure