DomiKnowS: A Library for Integration of Symbolic Domain Knowledge in Deep Learning

Hossein Rajaby Faghihi, Quan Guo, Andrzej Uszok, Aliakbar Nafar, Elaheh Raisi, Parisa Kordjamshidi

Abstract

We demonstrate a library for the integration of domain knowledge in deep learning architectures. Using this library, the structure of the data is expressed symbolically via graph declarations and the logical constraints over outputs or latent variables can be seamlessly added to the deep models. The domain knowledge can be defined explicitly, which improves the models' explainability in addition to the performance and generalizability in the low-data regime. Several approaches for such an integration of symbolic and sub-symbolic models have been introduced; however, there is no library to facilitate the programming for such an integration in a generic way while various underlying algorithms can be used. Our library aims to simplify programming for such an integration in both training and inference phases while separating the knowledge representation from learning algorithms. We showcase various NLP benchmark tasks and beyond. The framework is publicly available at Github(https://github.com/HLR/DomiKnowS).

Introduction

While deep learning has revolutionized AI, it remains notoriously "data-hungry" and often acts as a "black box" that struggles to generalize outside its training set. In many fields, we already possess significant domain knowledge (e.g., medical rules, linguistic structures, or physical laws) that could guide these models. However, integrating this "symbolic" knowledge into "sub-symbolic" deep learning architectures is technically grueling. Developers usually have to hard-code constraints into loss functions or post-processing scripts, making the code brittle and difficult to reuse. There is a distinct lack of a generic library that separates what the knowledge is from how the model learns it.

DomiKnowS is a new Python library designed to bridge this gap. It allows researchers to inject structured domain knowledge directly into PyTorch models using a declarative, graph-based framework, significantly improving performance in data-scarce scenarios and enhancing model explainability.

Methodology: Declarative Learning-based Programming

DomiKnowS introduces a Declarative Learning-based Programming approach. It breaks the modeling process into three distinct layers:

  1. Problem Specification: Users define a conceptual graph where nodes are "concepts" (e.g., a word, a person, a relation) and edges are "relationships" (e.g., a sentence contains a phrase).
  2. Knowledge Representation: Constraints are written in a logical language (e.g., ifL(work_for('x'), andL(people(arg1), organization(arg2)))). This says: "If X is a 'work_for' relation, its first argument must be a person and its second must be an organization."
  3. Integration Algorithms: The library provides three main ways to enforce these rules: Learning + Inference (L+I), Inference-Masked Loss (IML), and Primal-Dual (Soft Constraints).
Example of defining programs with specific points of interest (POI) in DomiKnowS, demonstrating the separation of task definition from the underlying graph.

The library is built on top of PyTorch and utilizes the Gurobi optimizer for solving complex logical constraints. By decoupling the domain knowledge (the "what") from the neural network architecture (the "how"), DomiKnowS allows researchers to swap out learning algorithms or update rules without rewriting the entire model.

Evaluation and Key Results

The authors evaluated DomiKnowS across several distinct domains, demonstrating significant performance gains through the integration of symbolic logic:

  • Question Answering (WIQA): This was the most dramatic result. A baseline model achieved 74.22% accuracy. By adding logical constraints via DomiKnowS (combining Primal-Dual and ILP), the accuracy jumped to 80.35%.
  • Entity-Relation Extraction (EMR): On the full CoNLL dataset, adding ILP inference improved the F1 score from 0.901 to 0.914. More importantly, in a low-data setting (using only 25% of the training data), the model maintained high performance where the baseline faltered.
  • Image Classification: While CIFAR-10 is a standard task, adding "disjoint" constraints (ensuring a bird isn't also a plane) provided a modest 0.5% boost, proving the framework's versatility across modalities.

Discussion: Insights and Explainability

DomiKnowS shines in low-data regimes. By providing the model with "rules of the road," it doesn't have to waste thousands of examples trying to learn basic logical consistencies. Furthermore, because the library uses a conceptual graph, every layer and computation is tied to a named concept (like "Person" or "Location"), making it much easier to debug why a model made a specific decision. It demonstrates that you don't have to choose between "deep learning" and "symbolic AI"; you can use neural networks for perception and symbolic logic for structure.

Conclusion and Future Work

The authors acknowledge that while the interface is generic, the current implementation is tied to PyTorch and the Gurobi solver. Future versions aim to support other deep learning libraries and a wider variety of solvers. Additionally, while the library makes it easy to use knowledge, the user still has to provide it. A promising future direction is the automatic extraction of these constraints from existing ontologies or even learning the constraints themselves from data. Finally, the authors plan to expand the library to handle more complex tasks like spatial role labeling and procedural reasoning.

Summary updated

BibTeX
@inproceedings{faghihi2021domiknows,
  author = {Hossein Rajaby Faghihi and Quan Guo and Andrzej Uszok and Aliakbar Nafar and Elaheh Raisi and Parisa Kordjamshidi},
  title = {{DomiKnowS: A Library for Integration of Symbolic Domain Knowledge in Deep Learning}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2021},
  doi = {10.18653/v1/2021.emnlp-demo.27},
}
Figure