Introduction
Deep learning has revolutionized artificial intelligence, yet it remains notoriously data-intensive and often operates as a "black box." In many specialized fields—such as bioinformatics, linguistics, or physics—researchers already possess significant domain knowledge. Ideally, models should not have to re-learn these fundamental rules from scratch. However, most deep learning frameworks are not designed to handle symbolic logic, forcing researchers to create custom, one-off implementations that are difficult to maintain or generalize.
DomiKnowS is a Python library designed to bridge this gap. It provides a generic, high-level programming interface that separates the specification of domain knowledge from the learning process, allowing for the seamless injection of logical constraints into neural network architectures.
The DomiKnowS Framework
DomiKnowS introduces a declarative approach to neuro-symbolic integration. The workflow is structured into three primary stages:
- Problem Specification: Users define their domain using a conceptual graph. In this graph, nodes represent concepts (e.g., "Person," "Organization") and edges represent relationships (e.g., "Works_for").
- Model Declaration: These concepts are connected to computational units, categorized as "sensors" (which handle raw data input, like Word2Vec embeddings) and "learners" (which perform classification or regression).
- Constraint Integration: Users define logical rules using a Python-based Domain Specific Language (DSL). These rules represent the symbolic knowledge the model must respect, such as "a person cannot be a location."
Integration Paradigms
The library is designed to be flexible, supporting three distinct paradigms for incorporating symbolic knowledge:
- Learning plus Inference (L+I): This approach applies constraints during the inference phase. It uses Integer Linear Programming (ILP) solvers, such as Gurobi, to adjust the model's raw outputs so they satisfy all logical rules.
- Inference-Masked Loss (IML): This training-time strategy masks the loss function. If the global logical constraints can recover the correct labels despite a local misclassification, the model is not penalized, allowing the logic to guide the learning signal.
- Primal-Dual (Soft Constraints): This method integrates constraints directly into the loss function using Lagrangian multipliers. It "nudges" the model toward logically consistent outputs throughout the training process without requiring hard satisfaction at every step.
Experimental Evaluation
The authors evaluated DomiKnowS across several diverse benchmarks to demonstrate its versatility and the impact of symbolic logic on model performance.
Question Answering (WIQA)
The most significant performance gains were observed in the WIQA dataset, which focuses on "what if" reasoning over procedural text. By incorporating logical constraints like transitivity, the researchers boosted accuracy from a baseline of 74.22% to 80.35%—an absolute improvement of 6.1%—when combining Primal-Dual training with ILP inference.
Entity-Mention-Relation Extraction (EMR)
Using the CoNLL 2003 benchmark, the library demonstrated the power of logic in low-data regimes. While it provided a 1.3% improvement on the full dataset, its real strength appeared when training data was reduced to 25%. In these scenarios, the logical constraints helped maintain model performance that would otherwise degrade significantly without sufficient examples.
Image Classification (CIFAR-10)
On the CIFAR-10 dataset, DomiKnowS was used to enforce hierarchical and disjoint constraints (e.g., an object cannot be both a "dog" and a "truck"). While the accuracy gains were marginal (~0.5%), the experiment successfully demonstrated that the library could enforce complex hierarchies in computer vision tasks, ensuring the model's predictions remained logically sound.
Discussion and Future Work
A key insight from DomiKnowS is the "separation of concerns." By decoupling knowledge representation (the logic) from the learning algorithm (the neural network), researchers can experiment with different optimization strategies without rewriting the core model. Furthermore, the library is solver-agnostic; while it currently supports Gurobi and GEKKO, it is designed to be extensible to other optimization backends.
Current limitations include a heavy reliance on the PyTorch backend and the requirement of licenses for certain commercial solvers like Gurobi. Future work will focus on expanding the library of pre-defined sensors, supporting more complex model compositions, and improving the efficiency of mapping logical constraints to algebraic inequalities to handle larger, more complex rule sets.
Conclusion
DomiKnowS represents a significant step toward accessible neuro-symbolic AI. By allowing researchers to inject domain expertise directly into deep learning models, it improves performance in data-scarce environments and enhances the logical consistency and explainability of model outputs.
Summary updated