Out-of-Distribution Detection with Negative Prompts

Jun Nie, Yonggang Zhang, Zhen Fang, Tongliang Liu, Bo Han, Xinmei Tian

TL;DR

Researchers have developed a novel method called Learn to Say No (LSN) that significantly improves Out-of-Distribution (OOD) detection by teaching models what an object is not. By learning class-specific "negative prompts" to complement standard positive ones, the approach helps vision-language models like CLIP distinguish between similar-looking objects (like a cat and a tiger) that often confuse traditional detectors.

What Problem Does This Paper Address?

In the "open-world" of machine learning, models often encounter objects they weren't trained on—this is known as Out-of-Distribution (OOD) data. A reliable model needs to not only classify known objects (In-Distribution or ID) but also accurately flag unknown ones.

Current state-of-the-art methods leverage large vision-language models like CLIP by matching images to "positive prompts" (e.g., "a photo of a cat"). However, these models struggle when an OOD sample shares features with an ID class. For example, if a model is trained to recognize cats and horses, it might mistakenly classify a tiger as a "cat" because both have pointed ears.

OOD samples sharing features with known classes

The authors identify two major hurdles in solving this:

  1. CLIP's "Bag-of-Words" Nature: CLIP doesn't truly understand linguistic negation. If you give it the prompt "not a photo of an elephant," it often focuses heavily on the word "elephant" and assigns a high similarity score to an actual elephant image.
  2. The Diversity of "Not": There are infinite ways for an object not to be a cat. A single hand-crafted negative prompt isn't enough to capture all the features that distinguish a cat from every other possible object in the world.

Methods

To overcome these limitations, the authors introduce Learn to Say No (LSN), a framework designed to automatically learn both positive and negative prompts.

Logic of negative features
  • Negative Prompt Learning: Instead of using a generic "not a [class]" string, LSN learns a set of $K$ learnable vectors (prompts) for every single class. These prompts are optimized to have low similarity with images of that class and high similarity with everything else, effectively capturing the absence of class-specific features.
  • Semantic Orthogonality Loss: To ensure the $K$ negative prompts for a class aren't just redundant copies of each other, the authors introduce a loss function that forces these prompts to be "orthogonal" (different) from one another. This allows the model to capture diverse negative features (e.g., one prompt might focus on the absence of a long snout, another on the absence of hooves).
  • Dual Scoring: During testing, the model calculates a "Positive Score" (how much it looks like a known class) and a "Negative Score" (how much it looks like "not" that class). The final OOD score is the difference between the two. If an image has high positive similarity but also high negative similarity, it is likely an OOD sample mimicking an ID class.

Datasets

The researchers evaluated LSN across a wide range of benchmarks:

  • Large-scale: ImageNet-100 and ImageNet-1k (as ID), tested against OOD sets like iNaturalist, SUN, Places, and Textures.
  • Small-scale: CIFAR-10, CIFAR-100, CIFAR+10, CIFAR+50, and TinyImageNet.
  • Models: They tested the approach using various backbones including CLIP (ViT-B/16, ViT-B/32, RN50x4) and BLIP.

Key Insights and Ideas

  • The "Not" Gap: The paper confirms that pre-trained models like CLIP are sensitive to the word "not" but fail to understand its logical function. Adding "not" to a low-scoring prompt can actually increase its score, proving that manual negative prompting is fundamentally unreliable for OOD detection.
  • Negative Features are Essential: Classification only requires finding the minimum features to distinguish Class A from Class B. OOD detection, however, requires a more complete description. Learning what is absent provides the "stricter rules" needed for open-world safety.
  • Class-Specific Negation: While a single positive prompt can often be shared across classes (e.g., "a photo of a..."), negative information is highly specific. The "not-ness" of a cat is vastly different from the "not-ness" of a truck.

Key Results

LSN achieved state-of-the-art performance across nearly all benchmarks:

  • ImageNet-100: LSN reduced the FPR95 (False Positive Rate at a 95% True Positive Rate—a key metric for OOD safety) from 32.58% (MCM baseline) to just 8.56%. This is a massive 24-point improvement.
  • ImageNet-1k: On the full-scale dataset, LSN improved FPR95 from 43.55% to 30.22%.
  • Robustness: The method proved robust across different model architectures (ViT vs. ResNet) and different vision-language models (CLIP vs. BLIP).

Limitations and Future Work

  • Computational Overhead: Because LSN learns and processes both positive and negative prompts, it roughly doubles the training and inference time compared to simpler prompt-learning methods like CoOp.
  • Feature Dependency: LSN is still "frozen" to the features learned by the base CLIP model. If CLIP itself cannot see a specific feature, LSN cannot learn to negate it.
  • Data Efficiency: While LSN works well with few samples (e.g., 16-shot), the authors noted that its performance doesn't continue to scale significantly as more training data is added, likely due to the limited number of learnable parameters in the prompt vectors.

Future work could involve making the negative prompt generation more efficient or exploring how to dynamically generate negative prompts based on the specific OOD samples encountered at test time.

Summary updated

BibTeX
@inproceedings{nie2024out,
  author = {Jun Nie and Yonggang Zhang and Zhen Fang and Tongliang Liu and Bo Han and Xinmei Tian},
  title = {{Out-of-Distribution Detection with Negative Prompts}},
  booktitle = {International Conference on Learning Representations},
  year = {2024},
  url = {https://openreview.net/forum?id=nanyAujl6e},
}
Figure