Improving Out-of-Distribution Detection with Markov Logic Networks

Konstantin Kirchheim, Frank Ortmeier

TL;DR

This paper introduces a neuro-symbolic framework that augments traditional out-of-distribution (OOD) detectors with Markov Logic Networks (MLNs) to reason over human-understandable concepts. By evaluating soft, weighted logical constraints rather than rigid rules, the approach significantly boosts OOD detection performance and explainability with minimal computational overhead.

What Problem Does This Paper Address?

Deep Neural Networks (DNNs) are notorious for making confidently incorrect predictions when encountering out-of-distribution (OOD) data. While many OOD detectors exist, they primarily look for statistical anomalies in high-dimensional latent spaces. This leaves three major gaps:

  1. Lack of Semantics: They ignore high-level task logic (e.g., failing to realize a blue stop sign is anomalous because stop signs should be red).
  2. Opaqueness: They output a single scalar outlier score without explaining why an image is considered OOD.
  3. Rigidity of Prior Logic: Previous neuro-symbolic attempts use strict first-order logic, which breaks down in real-world applications where data is noisy or contains natural exceptions.

The authors bridge this gap by introducing a probabilistic, rule-based layer that can handle real-world uncertainty.

Methods

The authors propose a framework that combines traditional pattern-based OOD detectors with a Markov Logic Network (MLN).

First, standard DNNs act as "concept extractors," mapping high-dimensional inputs (like pixels) into a low-dimensional semantic space (e.g., identifying an object's color, shape, or attributes).

Next, an MLN applies first-order logic constraints over these concepts. Instead of treating rules as absolute, the MLN assigns a learned weight to each constraint based on how consistently it holds true for in-distribution (ID) data.

Figure 2. Representation of a constraint as a tree of depth 3.

To make this system practical for deployment, the authors introduce two key innovations:

  • Bypassing the Partition Function: Computing the exact probability in an MLN requires calculating a normalizing constant (the partition function), which is computationally expensive. The authors drop this step, creating a fast, unnormalized outlier score based on a weighted sum of violated constraints.
  • Score Fusion via Extreme Value Theory: Traditional OOD scores vary wildly in scale. The authors fit a Generalized Extreme Value Distribution (GED) to the baseline detector's ID scores, converting them into a normalized survival function between 0 and 1 before multiplying them by the MLN score.

When human experts cannot provide explicit rules, the paper introduces a Greedy Constraint Set Search algorithm to automatically discover optimal logical constraints directly from a validation dataset.

Datasets

The framework was evaluated using two primary in-distribution (ID) datasets:

  • GTSRB (German Traffic Sign Recognition Benchmark): ~40,000 images across 43 traffic sign classes, utilizing prior knowledge of sign shapes and colors.
  • CelebA: ~200,000 celebrity facial images annotated with 40 binary attributes, serving as a highly challenging, noisy dataset with soft, non-absolute rules.

OOD Benchmarks: The models were tested against 8 distinct OOD datasets, including LSUN, TinyImageNet, Places356, iNaturalist, Textures, and synthetic noise (Gaussian/Uniform).

Key Insights and Ideas

  • Statistical and Semantic Signals are Complementary: Traditional detectors excel at spotting pixel-level or latent texture anomalies, while MLNs excel at spotting conceptual contradictions. Merging them creates a much more robust defense.
  • Soft Logic Beats Hard Logic: On noisy datasets like CelebA, strict logical verification fails due to labeling noise or natural exceptions (e.g., not all individuals with grey hair are old). The MLN's weighted approach gracefully handles these imperfections where rigid logic fails.
  • Extreme Value Theory Enables Seamless Fusion: Modeling the baseline detector's score distribution as a GED survival function provides a clean, mathematically sound way to normalize and fuse completely different scoring mechanisms.
Figure 1. Distribution of outlier scores on ID samples from the CelebA dataset and some OOD data. A fitted generalized extreme value distribution (GED) in grey. Survival function below.

Key Results

  • State-of-the-Art Performance: On the GTSRB dataset, combining an MLN with a standard Ensemble detector pushed the AUROC to 99.89%, dropping the False Positive Rate (FPR95) to just 0.54%.
  • Handling Noisy Data: On the challenging CelebA dataset, the MLN+Mahalanobis combination reduced the FPR95 by roughly 20% compared to using the Mahalanobis detector alone.
  • Rule Scaling: Performance scales monotonically as more logical constraints are added to the system, proving that the network effectively stacks semantic knowledge.
Figure 3. OOD detection performance on GTSRB for different numbers of constraints.
  • Low Overhead: The logic-checking step is highly parallelizable in PyTorch. For batch sizes greater than 128, the computational overhead of checking dozens of rules becomes negligible compared to the time spent running the neural network backbones.

Limitations and Future Work

  • Bottlenecked by Concept Extractors: The framework relies entirely on the accuracy of the initial DNNs that extract the concepts. If these concept extractors share parameters to save memory, their prediction errors become correlated, causing a significant drop in OOD detection performance.
  • Algorithmic Bias: Automatically learning logical constraints from human attribute datasets can inadvertently capture and formalize societal biases or stereotypes present in the training data (e.g., learning a rule like ¬MALE(x) -> NO_BEARD(x)). However, the authors note that because MLN rules are explicit and human-readable, these biases are much easier to audit and manually correct than those buried deep within black-box neural networks.

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