Concept Matching with Agent for Out-of-Distribution Detection

Yuxiao Lee, Xiaofeng Cao, Jingcai Guo, Wei Ye, Qing Guo, Yi Chang

TL;DR

Concept Matching with Agent (CMA) introduces neutral text prompts as "agents" to establish a triangular relationship between images, in-distribution labels, and the agents themselves. This training-free, zero-shot method effectively suppresses the confidence scores of out-of-distribution (OOD) data, outperforming many existing techniques that require extensive fine-tuning.

What Problem Does This Paper Address?

Machine learning models deployed in real-world scenarios often fail silently when encountering Out-of-Distribution (OOD) data—inputs that differ significantly from the training data. While vision-language models like CLIP enable zero-shot OOD detection by matching images to text labels, existing methods rely on a simple binary classification paradigm (determining whether an input is strictly In-Distribution [ID] or OOD).

This binary approach lacks the flexibility to handle complex, real-world data distributions. "Hard" OOD samples (which are semantically close to ID data) or spurious correlations often trigger high-confidence false positives. The authors tackle this challenge by reshaping how we conceptualize the boundary between ID and OOD data space.

Methods

The authors propose Concept Matching with Agent (CMA). Instead of just comparing an image embedding to a set of ID labels, CMA introduces a set of neutral, generic text prompts (e.g., "a photo of a thing in the world") called Agents.

These agents act as a third vertex in the feature space, transforming the traditional binary relationship into a Vector Triangle Relationship.

Binary vs. Vector Triangle Relationship

During the scoring process, the image embedding is compared against both the ID labels and the Agent prompts. The core innovation lies in how the final score is calculated: the agent similarities are included in the denominator of a softmax-like scaling function but excluded from the numerator.

Figure 2: Overview of Concept Matching with Agent (CMA) framework. The input image x undergoes Image Encoder I to produce an image embedding. The concatenation of the ID labels Yin and Agents Yntc is then subjected to Text Encoder T to generate a text embedding. The similarity between the image and text embeddings is computed, with a higher result indicating a greater degree of similarity (darker shading denotes higher similarity). This is followed by the CMA operation, which computes the SCMA for each image as the ultimate discriminative metric. Further details are provided in Section 3.

This setup creates a "collision effect." Because OOD images lack a true semantic match among the ID labels, they are highly susceptible to aligning with these neutral prompts. This forces their ID confidence scores to plummet. True ID images, conversely, remain strongly anchored to their specific labels and are largely unaffected.

Datasets

The authors evaluated CMA across a comprehensive suite of benchmarks:

  • Large-scale benchmark: ImageNet-1k served as the ID dataset, evaluated against four distinct OOD datasets: iNaturalist, SUN, Places, and Textures.
  • Small-scale datasets: Evaluation across 12 diverse datasets including FashionMNIST, STL10, OxfordIIIPet, Food101, CUB-200, PlantVillage, LFW, Stanford-dogs, FGVC-Aircraft, Grocery Store, CIFAR-10, and CIFAR-100.
  • Hard & Spurious OOD benchmarks: Subsets of ImageNet (ImageNet-10 vs. ImageNet-20) to test semantically similar classes (e.g., dog vs. wolf), and the Waterbirds dataset to evaluate robustness against spurious correlations.

Key Insights and Ideas

  • Exploiting CLIP's Length Bias: The authors observed that CLIP naturally assigns higher similarity scores to longer text prompts within a certain range. CMA turns this potential quirk into a feature by using well-structured, longer neutral prompts to draw OOD images away from short ID labels.
  • The Power of Neutrality: ID images are robust against neutral prompts because their specific semantic features strongly match the ID labels. OOD images, lacking a true match, easily "collide" with neutral prompts, which drastically reduces their maximum ID similarity score during softmax normalization.
Figure 3: Heatmaps depicting the cosine similarity between image inputs and ID concept vectors. In Figure (A), the ID concept vectors consist of sentences containing the word ”cat” of varying lengths. It is observed that images tend to align with longer sentences regardless of whether there is a matching ID concept. Concurrently, keywords such as ”white” significantly influence image matching. In Figure (B), aside from ”cat”, no ID concept can be precisely matched with the given images. However, other than cat images, all images exhibit a preference for aligning with a long sentence devoid of tangible objects. Notably, cat image remains unaffected, aligning solely with the ID concept ”cat”. All the data in the figure is obtained from the practical use of CLIP (https://github.com/openai/CLIP).

Key Results

  • Outperforming Zero-Shot Baselines: On the ImageNet-1k benchmark, CMA outperforms standard zero-shot methods like MCM, improving the Area Under the Receiver Operating Characteristic (AUROC) by 2.22% and reducing the False Positive Rate at 95% recall (FPR95) by 2.68% on average.
  • Beating Training-Required Methods: Remarkably, CMA surpasses several methods that require training or fine-tuning (such as KNN and Energy-based methods), showing an average improvement of 0.79% in AUROC and 3.13% in FPR95.
  • Hard OOD & Spurious Robustness: On the challenging Waterbirds dataset, CMA achieved an exceptional FPR95 of 3.22%, a massive drop from the baseline Maximum Softmax Probability (MSP) method's 39.57%.

Limitations and Future Work

Despite its strong performance, CMA has a few notable limitations:

  • Semantic Overlap: If the generated neutral prompts accidentally share semantic meaning with the ID labels, the model's ability to correctly classify true ID data can degrade.
  • Extreme Semantic Similarity: External neutral agents struggle to mitigate the impact of OOD images that are almost identical to ID labels, as they do not alter the model's intrinsic visual representations.
  • Prompt Optimization: Currently, the neutral prompts are selected manually after being generated by an LLM. Automatically generating optimal, context-aware neutral prompts without requiring training remains an open challenge for future research.

Summary updated

BibTeX
@inproceedings{lee2025concept,
  author = {Yuxiao Lee and Xiaofeng Cao and Jingcai Guo and Wei Ye and Qing Guo and Yi Chang},
  title = {{Concept Matching with Agent for Out-of-Distribution Detection}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2025},
  doi = {10.1609/aaai.v39i5.32481},
}
Figure