CLEAR: Contextual Logic-based Explanations for Anomaly Reasoning

Vikash Sharma, Vipul Joshi, Anurag Tripathi, Mayank Jauhari, Amir RazaFMSD @ ICML 2025

TL;DR

This paper introduces CLEAR, a novel framework that uses contrastive learning and large language models (LLMs) to generate human-readable explanations for anomalies detected in financial invoices. By providing context-rich justifications, CLEAR significantly improves the efficiency and accuracy of human investigators, bridging the gap between powerful but opaque ML models and the need for trust and auditability in finance.

What Problem Does This Paper Address?

Financial institutions process millions of invoices annually, and even a small percentage of errors or fraud can lead to substantial financial losses. While machine learning (ML) models are effective at detecting these anomalies, their "black-box" nature poses a significant challenge. In finance, regulations often require manual review and justification for any action taken based on ML predictions. Current explainability methods like SHAP and LIME, while useful, often produce explanations that are mathematically plausible but semantically invalid or lack the necessary context for human investigators. This leads to a bottleneck, with investigators only correctly identifying about 40% of true anomalies, missing crucial insights due to opaque feature scores and a lack of narrative grounding.

Methods

CLEAR is a model-agnostic, post-hoc framework designed to be layered on top of existing anomaly detection systems. It comprises four key stages:

  1. Embedding and Anomaly Model Training: An anomaly detector ($M_c$) is trained on historical data. Crucially, a separate embedding model ($M_e$), trained using contrastive learning (specifically SCARF), is used to capture semantic and contextual patterns in non-anomalous data, creating a dense embedding space.
  2. Neighbor Retrieval via Approximate KNN: For any invoice flagged as anomalous, its embedding is generated, and the system retrieves the top-K (K=200) most similar normal invoices from the embedding space. These serve as a "peer group" for contrastive reasoning.
  3. Local Surrogate Modeling and Feature Attribution: A local surrogate model (e.g., a Random Forest) is trained using the flagged anomaly and its K neighbors to approximate the anomaly detector's decision boundary. The top-N (N=5) most discriminative features are then extracted.
  4. Controlled Natural Language Explanation via LLM: A domain-adapted LLM (Gemma-7b, fine-tuned on 50K labeled invoices with investigator notes) takes the extracted features and contextual neighbors to generate structured, human-readable justifications. This stage leverages domain knowledge to ensure explanations are grounded and aligned with how investigators reason.

Datasets

The paper uses a proprietary dataset of six million structured business invoices. This dataset includes raw attributes and 210 derived features that capture current invoice properties (e.g., PO presence) and historical vendor behavior (e.g., transaction volume). The LLM was fine-tuned on 50K labeled invoices with investigator notes.

Key Insights and Ideas

  • Contrastive Learning for Semantic Embeddings: Instead of relying solely on raw feature importance, CLEAR uses contrastive learning to create embeddings that capture the semantic relationships between invoices. This allows for the retrieval of truly similar normal cases, which is crucial for contextual reasoning.
  • Real-Data Counterfactuals: By retrieving actual historical normal invoices as counterfactuals, CLEAR avoids the pitfalls of synthetic perturbations used by methods like LIME, ensuring explanations are grounded in real-world data and are more auditable.
  • LLMs for Narrative Grounding: Integrating LLMs allows for the translation of complex feature interactions into concise, human-readable narratives, making the explanations actionable and understandable for investigators.
  • Bridging the Gap: The core idea is to move beyond isolated feature scores to provide explanations that mimic how human investigators reason – by comparing an anomaly to similar, known-good examples and highlighting key differentiating factors.

Key Results

  • Improved Investigator Efficiency: An A/B test showed a statistically significant 25% relative improvement in investigator efficiency, increasing the proportion of correctly identified cancelled invoices (Investigator Efficiency) from 40.2% (baseline) to 50.1%.
  • Enhanced Responsiveness to Counterfactuals: CLEAR demonstrated a 22.4% and 10.5% relative improvement in responsiveness to targeted counterfactual edits compared to SHAP+LLM and LIME+LLM, respectively, indicating better capture of nuanced feature interactions.
  • Higher Alignment Score: The CLEAR framework achieved a 22.4% and 15.5% relative improvement in alignment score over SHAP+LLM and LIME+LLM, meaning its suggested features better matched the critical features identified by human investigators.
  • Estimated Annual Savings: The improved efficiency is estimated to enable substantial annual savings for financial operations.

Limitations and Future Work

  • Scalability to Heterogeneous Datasets: The authors suggest future work will focus on scaling CLEAR to handle more diverse and heterogeneous datasets beyond structured tabular data.
  • LLM Hallucination: While the paper mentions prompt control helps mitigate hallucination, it's an inherent challenge with LLMs that might require further attention.
  • Domain Adaptation: The current LLM is fine-tuned on financial invoice data. Adapting it to other domains would require retraining or further fine-tuning.

Summary updated

BibTeX
@inproceedings{sharma2025clear,
  author = {Vikash Sharma and Vipul Joshi and Anurag Tripathi and Mayank Jauhari and Amir Raza},
  title = {{CLEAR: Contextual Logic-based Explanations for Anomaly Reasoning}},
  booktitle = {FMSD @ ICML},
  year = {2025},
  url = {https://openreview.net/forum?id=zd6my13pVm},
}
Figure