DocVCE: Diffusion-based Visual Counterfactual Explanations for Document Image Classification

Saifullah Saifullah, Stefan Agne, Andreas Dengel, Sheraz AhmedarXiv 2025 · DOI

Abstract

Deep learning models for document image classification often operate as "black boxes," making it difficult to understand the reasoning behind their predictions. We present DocVCE, a framework that generates visual counterfactual explanations (VCEs) to clarify these decisions. By combining a Guided Reverse Diffusion Process (S-LDCE) with a Hierarchical Patch-wise Refinement (HPR) strategy, DocVCE produces realistic and minimal document modifications that flip a classifier's output. Our evaluation across three benchmark datasets (RVL-CDIP, Tobacco3482, and DocLayNet) demonstrates that DocVCE provides more interpretable and actionable insights than traditional attribution maps, revealing both structural dependencies and spurious correlations in state-of-the-art classifiers.

Introduction

While deep learning models excel at categorizing documents—such as distinguishing invoices from resumes—their decision-making processes remain opaque. Traditional explainability (XAI) tools typically rely on attribution maps, which highlight influential pixels. However, for document images, these heatmaps are often noisy and fail to capture critical global features like layout, font styles, or specific formatting.

DocVCE addresses this by generating counterfactual explanations. Instead of merely highlighting important regions, it answers the question: "What is the smallest change required to this image to flip the model's classification?" This approach provides actionable insights into model behavior, helping users identify why a document might have been misclassified.

Methodology

The DocVCE framework consists of two primary stages designed to ensure that generated counterfactuals are both realistic and minimal.

Stochastic Latent Diffusion Counterfactual Explanations (S-LDCE)

The first stage utilizes a Latent Diffusion Model (LDM) to generate a modified version of the input document. The denoising process is guided by two distinct signals:

  1. Classifier Gradient: Pushes the latent representation toward a target class.
  2. Distance Gradient: Ensures the generated image remains visually similar to the original.

To prevent the generation of "adversarial" artifacts—digital noise that fools a classifier but lacks human-interpretable meaning—DocVCE employs stochastic sampling. This adds controlled randomness to the process, favoring the generation of realistic document features over high-frequency noise.

Hierarchical Patch-wise Refinement (HPR)

To ensure the explanation is as concise as possible, the HPR module iteratively "polishes" the counterfactual. The system recursively divides the image into patches and attempts to swap them back with the original pixels. If the classifier still predicts the target class after a swap, the change in that patch is deemed unnecessary and discarded. This results in a "difference map" that highlights only the essential regions—such as a specific logo, header, or signature—that drive the classification.

Overview of the DocVCE framework, illustrating the diffusion-based generation (A, B, C) and hierarchical refinement (D) processes.

Experimental Setup

We evaluated DocVCE on three diverse document benchmarks:

  • RVL-CDIP: 400,000 business documents across 16 categories.
  • Tobacco3482: A smaller, imbalanced dataset of industry documents.
  • DocLayNet: A dataset focused on complex layouts like scientific reports.

The framework was tested against three distinct model architectures: ResNet-50, ConvNeXt, and the Document Image Transformer (DiT).

Results and Key Insights

DocVCE significantly outperformed previous state-of-the-art methods (like LDCE) in terms of realism, as measured by Fréchet Inception Distance (FID) scores on the Tobacco3482 and DocLayNet datasets.

Uncovering Spurious Correlations

A key finding was the identification of "junk" features. Counterfactuals revealed that models often rely on spurious correlations, such as specific barcodes or ID numbers in document corners, rather than the actual semantic content.

Structural vs. Object Changes

Unlike natural image counterfactuals that might change an object (e.g., cat to dog), DocVCE often induces structural shifts. For example, it might transform equations into paragraph headers to change a "scientific article" classification into a "government tender."

Minimality and Actionability

The HPR module proved critical for generating actionable explanations. In "Letter vs. Memo" tests, DocVCE showed that simply altering the header format was sufficient to flip a prediction, whereas baseline methods often modified the entire body text unnecessarily.

Conclusion and Future Work

DocVCE provides a robust method for visualizing document classifier logic through realistic counterfactuals. While currently limited by a $256 \times 256$ resolution and the iterative computational cost of HPR, it represents a significant step toward transparent document AI. Future work will focus on scaling the system to handle high-resolution images and integrating it with Vision-Language Models (VLMs) for OCR-free explanations.

Summary updated

BibTeX
@misc{saifullah2025docvce,
  author = {Saifullah Saifullah and Stefan Agne and Andreas Dengel and Sheraz Ahmed},
  title = {{DocVCE: Diffusion-based Visual Counterfactual Explanations for Document Image Classification}},
  year = {2025},
  eprint = {2508.04233},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2508.04233},
}
Figure