Introduction
Deep neural networks (DNNs) frequently exhibit "overconfidence," assigning high-probability scores to incorrect categories when encountering out-of-distribution (OOD) data. This behavior poses significant safety risks in high-stakes domains like medical diagnosis or autonomous systems. While OOD detection has seen substantial progress in computer vision, textual OOD detection remains a challenge.
Most current textual OOD methods are "post-hoc," applying scoring functions to pre-trained classifiers. The authors of "VI-OOD" argue that this approach is fundamentally limited. Standard training focuses on maximizing the conditional likelihood $p(y|x)$, which incentivizes the model to discard any information not strictly necessary for the classification task. Unfortunately, this "discarded" information is often critical for identifying outliers.
The VI-OOD Framework
To address these limitations, the authors propose VI-OOD, a Variational Inference framework designed to learn the joint distribution of inputs and labels ($p(x, y)$). By modeling the joint distribution, the framework preserves more descriptive features of the input data, enhancing its ability to distinguish between in-distribution (ID) and OOD samples.
Joint Distribution via ELBO
Since calculating the true joint distribution is mathematically intractable, VI-OOD optimizes the Evidence Lower Bound (ELBO). This objective splits training into two primary targets:
- Supervised Target: A standard classification task where the model predicts the label $y$ from a latent representation $z$.
- Unsupervised Target: A variational autoencoder (VAE) task that ensures the latent representation $z$ can reconstruct a target representation of the input.
Exploiting Intermediate Layers
A key finding of the research is that intermediate layers of Transformers (e.g., BERT, RoBERTa) often contain richer information for OOD detection than the final layer. VI-OOD introduces a learnable weight vector that dynamically combines hidden states from all layers to create the reconstruction target. This allows the model to capture multi-level semantic nuances that are typically filtered out by the final classification head.
Experimental Results
The authors evaluated VI-OOD across four ID datasets: 20 Newsgroups (20NG), IMDB, SST-2, and TREC-10. OOD performance was tested using unrelated datasets such as WMT16 and Multi30K.
As shown in the results table, VI-OOD consistently outperforms standard post-hoc methods like Maximum Softmax Probability (MSP), Mahalanobis distance, and Energy-based scores. Notably, on the SST-2 dataset, the False Alarm Rate at 95% Recall (FAR@95) for the Mahalanobis method dropped from 11.50% to 3.62% when integrated into the VI-OOD framework.
Scaling to Large Language Models
The framework's utility extends beyond encoder-only models. The authors successfully applied VI-OOD to LLaMA-2-7B, demonstrating that massive decoder-only models also benefit from joint-distribution training. On the TREC-10 task, LLaMA-2 equipped with VI-OOD achieved a near-perfect AUROC using cosine-based detection.
Discussion and Conclusion
The "Discarded Info" hypothesis was confirmed: as models become more specialized for a specific classification task, their OOD detection capabilities often degrade. VI-OOD mitigates this by forcing the latent space to remain descriptive of the input through its generative component.
While the framework introduces a slight computational overhead during training due to the decoder head and ELBO objective, only the encoder is required during inference, maintaining efficiency. There is also a minor trade-off in ID classification accuracy (typically <1%), which the authors view as a small price for significantly improved model safety and robustness.
Summary updated