Improving Out-of-Distribution Detection with Markov Logic Networks

Konstantin Kirchheim, Frank Ortmeier · DOI

Abstract

Out-of-distribution (OOD) detection is essential for ensuring the reliability of deep learning models operating in open-world scenarios. Current OOD detectors mainly rely on statistical models to identify unusual patterns in the latent representations of a deep neural network. This work proposes to augment existing OOD detectors with probabilistic reasoning, utilizing Markov logic networks (MLNs). MLNs connect first-order logic with probabilistic reasoning to assign probabilities to inputs based on weighted logical constraints defined over human-understandable concepts, which offers improved explainability. Through extensive experiments on multiple datasets, we demonstrate that MLNs can significantly enhance the performance of a wide range of existing OOD detectors while maintaining computational efficiency. Furthermore, we introduce a simple algorithm for learning logical constraints for OOD detection from a dataset and showcase its effectiveness.

Introduction

Deep Neural Networks (DNNs) are notoriously overconfident when encountering Out-of-Distribution (OOD) data—inputs that differ significantly from the training distribution. Standard OOD detection methods typically rely on statistical metrics derived from model outputs, such as feature vector distances or logit energy. However, these methods often lack semantic understanding, provide opaque scalar scores without explanation, and can be rigid in their application. This paper, presented at ICML 2025, introduces a neuro-symbolic framework that integrates Markov Logic Networks (MLNs) with traditional OOD detectors to address these limitations.

Methodology: Neuro-Symbolic OOD Detection

The proposed framework operates in three primary stages: concept extraction, probabilistic logical reasoning, and score fusion.

Concept Extraction and Soft Logic

High-dimensional inputs (pixels) are first mapped into a semantic space of human-understandable concepts (e.g., is_red, is_octagon) using auxiliary neural classifiers. Unlike previous logic-based OOD methods that used "hard" first-order logic rules, this work employs MLNs to perform "soft" reasoning. In an MLN, logical formulas are assigned weights rather than being strictly true or false. This allows the system to handle noise and rare exceptions gracefully without failing immediately upon a single rule violation.

Figure 5: Example of a logical constraint tree used for OOD detection. The system evaluates whether an input labeled as a 'stop sign' satisfies expected semantic properties like color and shape.

Score Fusion and Rule Learning

To maintain the strengths of existing detectors, the framework fuses the MLN's semantic plausibility score with standard statistical scores (e.g., Mahalanobis or Energy-based). These scores are normalized using a Generalized Extreme Value (GEV) distribution before being combined. Furthermore, the authors propose a Greedy Constraint Set Search algorithm to automatically discover effective logical rules from data by searching through a tree of possible formulas and keeping those that best improve detection on a validation set.

Experimental Results

The method was evaluated using the GTSRB (traffic signs) and CelebA (faces) datasets as In-Distribution (ID) tasks, against eight diverse OOD datasets including LSUN, TinyImageNet, and synthetic noise.

Performance and Robustness

The MLN-augmented detectors showed significant improvements in the False Positive Rate (FPR95) across various model architectures, including ResNet, ConvNext, and Vision Transformers. The logical constraints were particularly effective at catching "near" OOD samples—inputs that are statistically similar to the training data but semantically incorrect (e.g., a blue stop sign).

Computational Efficiency

A critical concern for neuro-symbolic methods is the added latency. As shown in Figure 6, the inference time overhead for the MLN+Ensemble approach remains minimal across various batch sizes, adding only a few milliseconds to inference time, which is negligible for most real-world applications.

Figure 6: Inference time comparison across different batch sizes. The MLN-augmented methods maintain competitive performance with standard ensembles, demonstrating minimal computational overhead.

Conclusion and Future Work

By bridging the gap between neural representations and symbolic logic, this work provides a robust and explainable path for OOD detection. While the system currently depends on the accuracy of concept classifiers and predefined predicate pools, it demonstrates that "soft" logic is a powerful tool for making AI systems more self-aware. Future research will focus on scaling to larger knowledge bases and automating the discovery of semantic concepts.

Summary updated

Abstract

Out-of-distribution (OOD) detection is essential for ensuring the reliability of deep learning models operating in open-world scenarios. Current OOD detectors mainly rely on statistical models to identify unusual patterns in the latent representations of a deep neural network. This work proposes to augment existing OOD detectors with probabilistic reasoning, utilizing Markov logic networks (MLNs). MLNs connect first-order logic with probabilistic reasoning to assign probabilities to inputs based on weighted logical constraints defined over human-understandable concepts, which offers improved explainability. Through extensive experiments on multiple datasets, we demonstrate that MLNs can significantly enhance the performance of a wide range of existing OOD detectors while maintaining computational efficiency. Furthermore, we introduce a simple algorithm for learning logical constraints for OOD detection from a dataset and showcase its effectiveness.
BibTeX
@inproceedings{kirchheim2025improving,
  author = {Konstantin Kirchheim and Frank Ortmeier},
  title = {{Improving Out-of-Distribution Detection with Markov Logic Networks}},
  booktitle = {International Conference on Machine Learning},
  year = {2025},
  url = {https://openreview.net/forum?id=8m2zWI6OJv},
}
Figure