Enhancing Out-of-Distribution Detection in Natural Language Understanding via Implicit Layer Ensemble

Hyunsoo Cho, Choonghyun Park, Jaewook Kang, Kang Min Yoo, Taeuk Kim, Sang-goo Lee

Introduction

In Natural Language Understanding (NLU), models are typically trained to classify user intents into a fixed set of categories. However, real-world deployment often exposes these models to "out-of-distribution" (OOD) inputs—queries that do not belong to any of the predefined classes. Standard NLU models suffer from a "closed-world" bias, frequently assigning high-confidence scores to these outliers instead of identifying them as unknown. This failure mode poses significant risks for reliability and user trust.

Traditional OOD detection methods primarily focus on the representations generated by the final layer of a neural network. This approach overlooks a wealth of information; research into Transformer-based architectures like BERT suggests that intermediate layers capture diverse syntactic and semantic features that the final layer may compress or discard. While explicit ensembles of multiple layers could theoretically address this, they are often computationally expensive and can suffer from high feature correlation, leading to redundant or even degraded performance.

The Layer-agnostic Contrastive Learning (LaCL) Framework

To address these limitations, we present Layer-agnostic Contrastive Learning (LaCL), a novel framework that treats the intermediate layers of a model as an "implicit ensemble." LaCL optimizes the model to utilize features across the entire architecture without the overhead of traditional ensemble methods.

Core Components

  1. Supervised Contrastive Learning (SCL): Unlike standard training that only applies a loss signal to the final output, LaCL applies SCL to every layer. This forces the model to learn discriminative representations—pulling similar intents together and pushing different ones apart—at every stage of the processing pipeline.
  2. Global Compression Layer (GCL): To manage the high dimensionality of multi-layer outputs, a shared two-layer Multi-Layer Perceptron (MLP) compresses the features from each layer into a lower-dimensional space. This ensures the final representation remains computationally efficient.
  3. Correlation Regularization (CR) Loss: A critical innovation in LaCL is the CR loss. To prevent adjacent layers from learning redundant information, this loss function penalizes high similarity between the features of neighboring layers. This forces each layer to specialize, capturing unique "views" of the input data.
  4. Implicit Ensemble via Concatenation: The specialized, compressed features from all layers are concatenated into a single vector ($z$). During inference, OOD detection is performed by calculating the cosine similarity between the input's vector and its nearest neighbor in the training set.

Experimental Setup

The framework was evaluated across three benchmark NLU datasets: CLINC150 (150 intents across 10 domains), Banking77 (77 fine-grained banking intents), and Snips (voice assistant queries). The researchers tested performance in two distinct settings:

  • Close-OOD: Outliers that are semantically similar to the training data (e.g., different intents within the same domain).
  • Far-OOD: Outliers from entirely different datasets, representing a more distinct shift in distribution.

Results and Key Insights

LaCL demonstrates superior performance across all tested scenarios, establishing a new state-of-the-art for intent-based OOD detection.

Quantitative Performance

On the CLINC150 dataset, LaCL significantly improved detection metrics compared to standard baselines. Specifically, it reduced the False Positive Rate (FPR@95)—the frequency with which OOD samples are incorrectly accepted as in-distribution—from 38.97% to 26.59%. In Far-OOD tasks, such as training on CLINC and testing on Banking77, the framework achieved an AUROC of 98.57%, indicating near-perfect separation between known and unknown inputs.

The Value of Layer Diversity

Ablation studies confirmed that the "last layer is best" heuristic is often incorrect for OOD tasks. Intermediate layers frequently outperformed the final layer in identifying outliers. Furthermore, the inclusion of the first few layers of BERT—often dismissed as too primitive—was found to contribute meaningful features that enhanced the model's ability to distinguish subtle differences in input distribution.

Efficiency and Robustness

Because the ensemble is "implicit" (integrated into the feature representation itself), LaCL avoids the computational slowdown associated with running multiple scoring functions or separate models. It also proved more robust than competing contrastive methods, which often excelled in Far-OOD scenarios but struggled with Close-OOD detection.

Conclusion and Future Work

LaCL provides a powerful, efficient method for OOD detection by leveraging the latent information within intermediate neural layers. By enforcing layer diversity through Correlation Regularization, the framework transforms a standard backbone into a highly effective ensemble.

While currently optimized for NLU intent classification, future research will explore automating hyperparameter tuning for the compression layers to make the framework more adaptable to larger architectures. Additionally, testing the LaCL approach in other domains, such as computer vision and long-form document analysis, remains a promising avenue for future study.

Summary updated

BibTeX
@inproceedings{cho2022enhancing,
  author = {Hyunsoo Cho and Choonghyun Park and Jaewook Kang and Kang Min Yoo and Taeuk Kim and Sang-goo Lee},
  title = {{Enhancing Out-of-Distribution Detection in Natural Language Understanding via Implicit Layer Ensemble}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2022},
  doi = {10.18653/v1/2022.findings-emnlp.55},
}
Figure