Elamur Research

Classical Out-of-Distribution Detection Methods Benchmark in Text Classification Tasks

Paper · 2023 · Mateusz Baran, Joanna Baran, Mateusz Wójcik et al.

Summary

A text classifier can give a confident answer to a document that falls outside the task it learned. A headline about a topic absent from training can still receive one of the familiar topic labels. A review from an unfamiliar source can fit the task’s labels and still differ substantially from the reviews used to train the classifier. Baran and colleagues examine whether an additional score can flag such inputs for review. They compare eight methods for detecting out-of-distribution text, using methods that can be attached to an already trained classifier without collecting examples of unfamiliar inputs for detector training.

The benchmark uses a RoBERTa base classifier and varies what makes a test input unfamiliar. One set of experiments starts with news headlines and tests the detectors on held-out headline topics, tweets, reviews, non-English text and randomized headlines. The other set separates changes in the topics a classifier is expected to recognize from changes in the source and characteristics of reviews whose sentiment labels stay familiar. The distinction matters because a detector can recognize an unfamiliar vocabulary or document format while missing a change in what a sentence says or how its words fit together.

K-nearest neighbors, which scores a text by how close its representation lies to training examples, achieved the highest area under the receiver operating characteristic curve, or AUROC, on every test comparison in the news-based scenario. Its AUROC was 80.1% on held-out headline topics and 99.6% on the non-English texts. It reached just 67.6% when the authors randomized headlines made from the familiar news categories. Virtual-logit Matching, which uses information from both the text representation and the classifier’s output, led every semantic-shift comparison in the newsgroup experiments. The two methods shared the lead across the review-source comparisons, where established confidence scores generally struggled to improve on the plain softmax baseline.

The authors release the TrustworthyAI experimental framework so the comparisons can be reproduced and extended. The benchmark’s main finding is that detector quality depends on the kind of departure being tested. The methods can rank inputs from a markedly different source with high accuracy, yet still have trouble separating familiar-looking disruptions or recognizing a shift while retaining most ordinary inputs. Those are different demands on a detector, and the benchmark shows why they deserve separate measurements.

Deep dive: Classical Out-of-Distribution Detection Methods Benchmark in Text Classification Tasks

A benchmark of out-of-distribution detection for text classifiers finds nearest neighbors and virtual-logit matching strongest under different shifts. · about 31 minutes to read

The problem and its context

A label and a decision to use it

In text classification, a system learns to assign passages to a fixed set of categories. A news classifier may learn topic labels, while a review classifier learns sentiment labels. Once trained, the classifier can apply those labels to any text it receives. The ability to return a label says little by itself about whether the input resembles what the classifier learned from or whether its categories make sense for the new document.

The paper calls the familiar population in-distribution, or ID. Inputs drawn from a different population are out-of-distribution, or OOD, relative to that reference. The qualification matters. A restaurant review can be part of the ordinary input for a review classifier and an unfamiliar input for a headline classifier. Even within news, the same headline could fall inside the scope of one classifier and outside the scope of another because the two were trained on different topics.

The authors motivate the benchmark with a document-processing workflow. A classifier proposes a label, and a detector estimates whether the input fits its training distribution. The workflow can send flagged documents for human verification. A detector that accepts shifted inputs too readily leaves mistakes for downstream stages to inherit. A detector that flags too many ordinary documents increases the work left to reviewers. Useful detection therefore requires both a meaningful score and a way to use that score at a suitable operating point.

The introduction describes several routes by which real inputs can change. A change in user behavior can alter the material a system receives. Markets, seasons and regulations can also change what people write or submit. Entirely new inputs may appear once a classifier begins operating outside the setting in which it was evaluated. Testing on familiar held-out data establishes how well the classifier handles that population. A separate detection experiment asks whether it recognizes departures from that population. The paper places this deployment concern in the broader discussion of bias, fairness and safety, citing Concrete Problems in AI Safety.

What can shift in a document

The paper uses two ways to organize departures from the training distribution. The first is a qualitative judgment about closeness. A headline on an unfamiliar topic can remain close to the training headlines because it comes from the same collection and has the same form. A movie review stands farther away in both purpose and style. Non-English texts offer a more distinct comparison with the English headlines. The resulting groups are called Near-OOD, Far-OOD and Distinct-OOD. They describe how the authors construct the benchmark and give a reader a way to interpret its test cases.

The second way asks which properties of the data have changed. In a semantic shift, inputs introduce categories outside the labels the classifier learned. The benchmark illustrates this by training on subtopics in one branch of a newsgroup collection and testing with material from other branches. In a background shift, the characteristics of the writing change while the decision still uses the same kinds of labels. A movie review and a restaurant review can both be positive, even though they describe different things and use different expressions to communicate approval. The paper draws this distinction from work including Types of Out-of-Distribution Texts and How to Detect Them.

These two schemes address different questions. Closeness describes how far the authors judge a test collection to be from the chosen reference. Semantic and background shift describe what kind of change the authors intend a comparison to represent. The held-out headline topics illustrate why both questions matter. They introduce unfamiliar labels while preserving many of the cues that mark an item as a HuffPost headline. A detector that reacts strongly to a change in source can have little evidence of that kind available in the headline comparison. The paper situates its two categories within a broader discussion of generalization in State-of-the-art generalisation research in NLP.

For the authors, textual structure adds another source of difficulty. A string assembled from ordinary headline words can retain cues about familiar topics even after it loses the organization that makes it a usable headline. The paper includes randomized headlines to test whether detectors notice this kind of input. The experiment extends the question beyond whether the classifier recognizes a source or label. It also asks how much the detector responds to the arrangement of familiar textual material.

Why compare existing detectors on text

The related-work section traces much of the detector literature to computer vision. It describes methods that examine the classifier’s output, inspect gradients, estimate the density of familiar data or measure distances to its representations. These families start from different evidence. The output may show how decisively a classifier favors a label. A gradient describes how an objective responds to changes in parameters. A density or distance method asks how the input sits relative to previously observed examples.

Maximum Softmax Probability, introduced by Hendrycks and Gimpel, supplies the benchmark’s reference point. It simply uses the probability the classifier assigns to its most favored label. It is attractive because the classifier already produces the information it needs and the procedure is independent of the subject matter. The paper describes subsequent approaches that work with raw output scores, intervene on activations or draw on evidence elsewhere in the classifier. A vision benchmark discussed in the related work had found that simple preprocessing could compete with more elaborate approaches, giving the authors a reason to take readily integrated methods seriously.

The paper also discusses the GLUE-X benchmark, which examined how pretrained systems generalize to unfamiliar data without attaching detectors of the kind studied here. That distinction gives the two evaluations different aims. A generalization test can ask whether a system still predicts the right label when the data change. The experiments here ask whether a detector can tell familiar and shifted inputs apart. In a shift that brings in entirely new labels, the original classifier may have no suitable label available in the first place.

The authors describe previous studies in natural language processing as including new detection techniques, adaptations of existing techniques and work dedicated to particular forms of shift. Their benchmark addresses the comparative question left by that literature. It attaches several readily usable detectors to a common text-classification setup and changes the kind of input they must separate. Using the same backbone and the same data splits within a comparison makes it possible to ask how much the choice of detector matters under those particular conditions.

The method, step by step

Begin with a classifier trained on familiar examples

The benchmark starts by defining the categories and texts that count as ordinary input for a task. A classifier learns to predict labels from those examples. For a news task, the familiar inputs belong to selected headline topics. For a review task, the familiar inputs come from a designated review collection and carry positive or negative sentiment labels. The choice of training population sets the reference that every subsequent detector must work with.

The common backbone is RoBERTa base, pretrained on English corpora and equipped for these experiments with a fully connected classification head. A head is the part of the system that takes the text representation from the backbone and turns it into a score for each task label. Those raw scores are called logits. Softmax converts them into probabilities that sum to a whole. The largest probability supplies the classifier’s predicted label and also serves as the simplest detector’s input. The backbone uses the Transformer and attention architecture, with RoBERTa as the specific choice for the benchmark.

In fine-tuning, the classifier adapts its pretrained representations to the labels of the chosen task. The training split supplies the examples used for learning, and the validation split supplies the F1 score used to select a checkpoint. The classifier’s held-out test split serves a different purpose. It measures how well the selected classifier labels familiar inputs and provides the familiar examples against which shifted inputs are compared. The benchmark repeats the training procedure across different initial seeds so the detector comparisons can be summarized across training runs.

The authors attach each detector after this training stage. Each detector supplies a real-valued score for an input, expressing evidence about how well the input fits the familiar data. Depending on the method, a scoring rule may first need reference information estimated from the training or validation split. The term post-hoc refers to this placement after classifier training. Some methods still require access to internal computations, and some alter activations or weights for the purpose of scoring at evaluation time.

Training the classifier and evaluating its detectors

The steps in order.

Training the classifier and evaluating its detectorsStep 1: Define the familiar task and label set1. Define the familiar task and label setStep 2: Fine-tune RoBERTa on familiar labeled texts2. Fine-tune RoBERTa on familiar labeled textsStep 3: Select a checkpoint using validation F13. Select a checkpoint using validation F1Step 4: Estimate detector statistics from familiar data4. Estimate detector statistics from familiar dataStep 5: Score familiar and shifted test inputs5. Score familiar and shifted test inputsStep 6: Compare detection scores across test pairs6. Compare detection scores across test pairs

The step for estimating statistics applies to methods that need a reference beyond the individual input. The detection experiments always require familiar and shifted test examples, because the evaluation needs to know which group each score belongs to. Preparing those shifted examples for testing is separate from supplying shifted examples to a detector so it can learn what to reject. The benchmark’s integration constraint concerns the latter.

Read the classifier’s output or examine how it was produced

Maximum Softmax Probability. MSP takes the largest probability in the classifier’s output. If the classifier gives a familiar label a commanding lead, MSP treats that as evidence of a familiar input. The method needs only the probabilities for the current text. Its simplicity also exposes the assumption under test. Probabilities distributed among familiar labels express how the classifier chooses within that label set. A confident choice can still occur for a document lying outside the set of inputs the classifier learned to handle.

Energy. The energy-based detector derives a confidence score from the classifier’s logits. MSP reduces an input to the leading probability after normalization. The energy approach uses a function of the raw scores, giving it access to information that can disappear when the probabilities are normalized. It still uses the classifier’s output as its evidence. A good result for Energy on a test pair therefore shows that a different treatment of that output separated the two populations more clearly in that comparison.

Rectified Activations. ReAct intervenes earlier in the computation by truncating high activations during evaluation. An activation is a value produced by a component of the network in response to the input. Capping high values restricts the influence of those values on the score that follows. The intention is to reduce the overconfidence that unusual activation patterns can produce. The benchmark estimates the required configuration from familiar data. The comparison asks whether this intervention improves the separation between familiar and shifted inputs while keeping the classifier’s training procedure common to the other detectors.

KL-Matching. KLM compares the entire vector of output probabilities with typical distributions estimated for familiar classes. It uses Kullback–Leibler divergence, a measure of discrepancy between probability distributions, and takes the smallest divergence to a class reference. The closest class reference determines the match. Two inputs can have the same top probability while allocating the remaining probability differently. KLM can respond to that difference because it compares probability profiles, including the scores assigned to the alternatives. Its premise is that a familiar input is likely to produce a profile similar to an established one.

GradNorm. GradNorm inspects gradients in the classification head. A gradient records how a quantity used in the computation changes in response to small changes in the head’s parameters. The detector reduces the gradient vector to a norm, which measures its magnitude. The method assumes that larger norms characterize familiar inputs. This route uses a different signal from directly reading a probability or a logit, though it still depends on the trained head. It requires the computation needed to obtain its gradients at scoring time.

Use the representation of the input

Directed Sparsification. DICE selects a subset of weights used to produce the output. Sparsification makes a computation depend on fewer weights, here with the aim of filtering out contributions that the method deems irrelevant. The idea is that restricting which components of the representation contribute to the score can improve the signal that separates familiar and shifted inputs. Because the selection is established using familiar data, its success depends on whether useful detection information survives that restriction when the input distribution changes.

Virtual-logit Matching. ViM combines the representation from the pretrained backbone with the logits associated with the task labels. The representation supplies evidence that can be considered without first choosing a class. The logits capture the output tied to those classes. The virtual-logit idea brings the representation-based evidence into a comparison with the familiar classes’ output scores. This gives the detector two sources of information about the input, one tied to the shape of the learned feature space and one tied to the current classification task.

K-nearest neighbors. KNN uses distances from the new input’s representation to representations of familiar training examples. A representation, or embedding, is the numerical description that the classifier builds for a text. If a new input lies close to familiar examples in that space, the detector has evidence that it belongs to the training distribution. If its neighbors are farther away, it has evidence of a departure. KNN’s usefulness depends on the distances induced by the backbone. A change in the input can be visually obvious to a reader and still produce a representation close to those of ordinary texts.

ReAct, KLM, DICE, ViM and KNN require configuration or reference statistics based on familiar training or validation data. The authors take the detector hyper-parameters from the original publications. They describe the detectors through the information each one consumes and the operation it performs. Their benchmark does not set out a separate mathematical derivation of each scoring rule. The descriptions identify the relevant probabilities, distances or other computations without fixing additional details about norms, reference estimates or parameter choices beyond what the paper reports.

These methods can agree on which label the classifier favors while differing in their estimate of familiarity. Consider the held-out headline topics. A classifier restricted to familiar topics still assigns an output score to every available label. MSP can treat a decisive output as evidence of familiarity. KNN can judge the same headline by its distance from retained training examples, and ViM can use both the feature representation and the head’s scores. The paired evaluations measure whether those different kinds of evidence lead to different separations of the test sets.

Build changes of source, topic and structure into the test data

The first scenario uses the News Category Dataset, a collection of around 210k HuffPost headlines published between 2012 and 2022. The source has 42 classes, with a substantial imbalance in their frequencies. The authors combine similar classes to obtain 17 representative groups. They use the seven most frequent groups as the familiar set, NC/I, and reserve the remaining 10 as NC/O. NC/O offers an unfamiliar label set inside the same publication and the same basic format. The Twitter Topic Classification dataset supplies the other Near-OOD comparison. Its topics resemble those of the news collection, but its posts differ in how they are written.

The Far-OOD tests use reviews. SST-2 draws short text from movie reviews and uses positive and negative sentiment annotations. IMDB contains more extended movie reviews, and Yelp Polarity Review contains customer reviews. Together these give the headline classifier test cases with a different purpose from news and several distinct sources and text lengths. The paper identifies the sources in Recursive Deep Models for Semantic Compositionality, Learning Word Vectors for Sentiment Analysis and Character-level Convolutional Networks for Text Classification.

The review collections’ labels illustrate what is held constant when the authors later use them for background shift. For IMDB, the source’s 10-point scale is filtered to retain strongly positive or strongly negative reviews. The positive rule is:

r ≥ 7

Here r denotes a review’s original IMDB rating, ≥ means greater than or equal to, and 7 is the minimum retained rating for the positive class.

The negative rule for IMDB is:

r ≤ 4

Here r again denotes the original IMDB rating, ≤ means less than or equal to, and 4 is the maximum retained rating for the negative class. The selection leaves out ratings between the positive and negative ranges.

Yelp uses the star rating attached to each review. Its rule for the negative class is:

s ≤ 2

Here s is the number of stars assigned by the Yelp reviewer, ≤ means less than or equal to, and 2 is the highest star count assigned to the negative class.

The positive rule for Yelp is:

s ≥ 3

Here s is the Yelp star count, ≥ means greater than or equal to, and 3 is the lowest count assigned to the positive class. The benchmark draws a random subset of 75k reviews from a source containing nearly 600k. These source rules establish a common positive-versus-negative prediction task while allowing the collections to differ in how those labels were produced.

The Distinct-OOD test comes from the Language Detection Dataset. The source includes texts in 17 languages. The authors exclude languages that use a script other than the Latin alphabet and remove English texts. The resulting evaluation collection therefore offers a language change without relying on a change away from the Latin script. The detector receives the resulting texts as OOD examples relative to the English headline training set. The experiment uses language as a property of the test population. It does not separately establish what words or token fragments RoBERTa encountered during pretraining.

The authors add a pair of randomized collections called News Category Random. In the procedure they describe, words from the material available in each category are shuffled, with both the total number of examples and the word count of each example kept the same. NCR/I derives from the familiar categories. NCR/O derives from the held-out categories. The categorization of the source material is preserved, while the texts lose their original sentence context. NCR/I is central to the design because it lets the authors ask whether a detector treats a disrupted text as unfamiliar even when its words come from the kinds of news it was trained to accept.

Change the role each collection plays

The second scenario uses ordered pairs of data collections. The first member of a pair supplies the familiar task and produces a classifier and detector reference. The other member supplies shifted test texts. Reversing a pair changes the data used to train the classifier and changes which population the detector is meant to recognize as familiar. As a consequence, a result for IMDB as ID with SST-2 as OOD answers a different question from a result for SST-2 as ID with IMDB as OOD.

For semantic shift, the authors use the hierarchy in 20 Newsgroups, a collection of around 18k messages on 20 topics. They select Computer, Politics and Sports as the broad groups for the experiment. Each selected group contains its own finer labels, so a classifier trained on Computer learns to discriminate topics within that group. At evaluation, a message from Politics or Sports represents an input whose topic comes from a different branch. The authors leave out the miscellaneous group because of possible data leakage. They reserve a validation subset from the original training portion and use held-out data for evaluation.

For background shift, each of the three review collections takes a turn as the familiar source. The other review collections supply shifted inputs, with separate results for each pairing. The labels remain positive and negative, so the detector is asked to recognize a change in the input population even though the classification task still makes sense for both sources. The comparisons also cover changes in length and in the subject of the reviews. Those properties belong to the background-shift setting as implemented, and the pairwise design makes it possible to see which directions of transfer are especially difficult.

Experiments and results

Which data go into training and testing

For the news-based scenario, NC/I has 66,223 training headlines, 26,475 validation headlines and 39,688 test headlines. The OOD comparisons use those familiar test headlines against the corresponding shifted test collection. NC/O contributes 48,522 headlines and Twitter contributes 3184 posts, both used for OOD evaluation. The randomized versions have the same counts as their corresponding news test collections. NCR/I thus contains 39,688 test items drawn from the familiar category partition, while NCR/O has 48,522 drawn from the unfamiliar partition.

The review collections serve as OOD sets in the news-based experiment and can serve as familiar training sources in the background-shift experiment. The IMDB split has 25,000 training, 5000 validation and 20,000 test reviews. SST-2 has 43,221 training, 5000 validation and 20,000 test texts. Yelp has 50,000 training, 5000 validation and 20,000 test reviews. The non-English Language collection is reserved for detection evaluation and contributes 5864 test inputs. These are the benchmark’s split counts. The sizes the paper gives for the original sources describe a different stage of data preparation.

For the semantic-shift comparisons, the Computer group has 5 classes, with 2965 training, 456 validation and 1460 test items. Politics has 4 classes, with 1959 training, 315 validation and 979 test items. Sports has 4 classes, with 2363 training, 432 validation and 1182 test items. Each group’s classifier learns its own classes. A pair such as Computer ID and Politics OOD uses Computer test texts as the familiar examples and Politics test texts as the shifted examples.

Check the classifier before measuring the detector

Training runs for at most 100 epochs, with early stopping and a patience of 10 epochs. The paper reports a learning rate of 2e − 5, a weight decay of 0.01 and the Adam optimizer. Weight decay controls the penalty on parameter size during training. The authors select the checkpoint on validation F1 and report classification performance on the held-out familiar test split. They repeat training five times per task with different seeds, using the range [2021, 2025]. The detector tables give averages and standard deviations.

The classification results establish how the backbone performed on the task it learned. The news test split has F1 of 81.8 ±0.1, while the Sports test split has F1 of 97.5 ±0.2. On their own review test splits, SST-2 records F1 of 93.8 ±0.1 and Yelp records 96.9 ±0.0. These scores concern correct task labels on familiar test examples. The detection experiments use the same fitted classifiers to ask whether their outputs or representations can separate inputs by distribution membership.

The paper reports 35 training runs, consuming 222 GPU-hours. Evaluation alone took 124 GPU-hours. The results come from a workstation with an Nvidia RTX 3060 and 12GB of GPU memory. The resource totals describe the benchmark as a whole. The reported setup gives context for the authors’ choice to use recommended hyper-parameters and the amount of work involved in testing each detector across the full set of data pairs.

Read the three detection metrics

AUROC, the primary metric, is the area under the receiver operating characteristic curve. The curve traces the tradeoff between the true positive rate and the false positive rate as the decision threshold moves. A higher area indicates better separation across thresholds. This makes AUROC useful for comparing ranking quality before choosing an operating threshold, such as the score below which a document would go to human review.

AUPR-IN is the area under the precision–recall curve with familiar inputs as the positive class. Recall describes how much of the familiar population the detector accepts. Precision describes how much of what it accepts is actually familiar under the experiment’s definitions. AUPR-IN emphasizes the quality of the accepted set across operating points. The balance between familiar and shifted test examples varies between comparisons, which matters when reading precision values across different dataset pairs.

FPR@95 reports the false positive rate at a true positive rate of 95%. With familiar inputs treated as positive, it describes how much shifted text is accepted at a point that retains that share of familiar data. A lower number is better. This metric addresses a narrower question than AUROC. A detector can produce a good ranking across a broad range of thresholds and still leave substantial overlap where the workflow seeks to retain most familiar documents. The paper gives all three measures, so a reader can distinguish a ranking advantage from performance at this particular acceptance target.

Familiar sources and unfamiliar headlines

KNN has the highest mean AUROC in each comparison of the first scenario. The held-out headline topics offer a particularly demanding test because NC/O comes from the same HuffPost collection as the data used to train the classifier. It preserves much of the source’s format and vocabulary while changing which topics count as familiar. On that comparison the baseline MSP has AUROC of 74.2 ±0.3. KNN reaches 80.1 ±0.2 and ViM reaches 79.9 ±0.2. Energy, ReAct and GradNorm also exceed the MSP mean on this test, while KLM and DICE fall below it.

Detector AUROC on NC/O headlines with NC/I as the familiar set

Nearest neighbors leads on held-out headline topics, with Virtual-logit Matching close behind.

Detector AUROC on NC/O headlines with NC/I as the familiar setMSP: 74.2MSP74.2Energy: 77.6Energy77.6GradNorm: 77.2GradNorm77.2KLM: 62.9KLM62.9ReAct: 77.5ReAct77.5DICE: 58.2DICE58.2KNN (this paper): 80.1KNN (this paper)80.1ViM: 79.9ViM79.9
The numbers
System or settingAUROC %
MSP74.2
Energy77.6
GradNorm77.2
KLM62.9
ReAct77.5
DICE58.2
KNN (this paper)80.1
ViM79.9

On NC/O, the ordering of leading methods depends partly on what is measured. KNN has AUPR-IN of 78.5 ±0.1, ahead of ViM at 77.1 ±0.1 and MSP at 71.7 ±0.4. At the operating point measured by FPR@95, ViM records 71.5 ±0.5 and KNN records 73.9 ±0.6, compared with 82.3 ±0.8 for MSP. The detector with the strongest AUROC still has considerable overlap between the two score populations where it must keep most familiar headlines. Improving the ranking and solving the acceptance problem are distinct accomplishments in this test.

Twitter also belongs to Near-OOD, but it brings a more visible change in where and how the text is written. With NC/I as the familiar set, MSP has Twitter AUROC of 74.8 ±2.4 and KNN has 92.9 ±1.2. ViM reaches 89.2 ±1.5, while Energy reaches 84.8 ±1.9. KLM records 54.0 ±3.8. The Twitter test accordingly gives a very different picture of the gain from a representation-based detector than the held-out headline test. Both test sets share some subject matter with the familiar news, yet they differ in how much of the familiar source and form they preserve.

The Twitter results show why the paper evaluates precision–recall alongside the other measures. MSP’s AUPR-IN is 97.3 ±0.3 and KNN’s is 99.3 ±0.1, while their corresponding FPR@95 values are 77.3 ±4.8 and 34.4 ±5.4. The familiar test set is considerably larger than the Twitter test set. A high proportion of familiar inputs among accepted items can coexist with acceptance of a substantial share of the smaller shifted collection. Each metric describes a different property of the same decisions.

Reviews and the change of language

In the Far-OOD group, IMDB and Yelp are more readily separated from familiar news than SST-2. KNN attains AUROC of 99.8 ±0.1 on IMDB and 99.5 ±0.1 on Yelp. The corresponding MSP scores are 96.6 ±3.1 and 95.3 ±1.5. Energy and ReAct both record 99.6 ±0.5 on IMDB and 98.6 ±0.7 on Yelp. ViM falls below MSP on both of these comparisons, with 90.6 ±3.1 on IMDB and 92.9 ±1.6 on Yelp. The benchmark therefore contains conspicuous exceptions to ViM’s strong showing elsewhere.

SST-2 has a different profile. KNN records AUROC of 96.4 ±1.1, ViM gets 96.0 ±0.9 and MSP gets 84.2 ±3.3 against familiar news. The paper reports an average of 9.53 words for SST-2 texts, compared with 9.95 for NC/I headlines. IMDB averages 231.15 words and Yelp averages 133.11. The authors point to SST-2’s short inputs as a possible reason that it is the hardest of the Far-OOD collections in their setup. Similar average lengths give the detector less opportunity to distinguish the short review texts from headlines by length alone. Other properties of these sources vary together with length.

On the non-English Language test, KNN records AUROC of 99.6 ±0.1 and FPR@95 of 1.4 ±0.5. Energy and ReAct both reach AUROC of 98.7 ±0.6, and the MSP baseline reaches 95.1 ±1.9. The benchmark’s relatively easy characterization of this test reflects the performance of most methods. Some have considerable difficulty even here. DICE gives AUROC of 69.3 ±2.8 and FPR@95 of 100.0 ±0.0. The language comparison offers a strong signal to several detectors, and the results also show that the choice of score can determine whether that signal becomes actionable.

Randomized headlines

The randomized texts show how much familiar vocabulary can matter after sentence structure is disrupted. With intact NC/I headlines as the familiar reference, KNN reaches AUROC of 67.6 ±1.3 on NCR/I. MSP reaches 59.0 ±0.8, and KLM reaches 50.6 ±0.1. At the acceptance target used by FPR@95, even KNN has a false positive rate of 85.7 ±0.7 on NCR/I. The result gives a concrete scale to the authors’ concern that a detector may let visibly disrupted texts through when their lexical material comes from familiar news categories.

Randomization has a different effect when the material comes from the held-out categories. Against the same familiar reference, KNN has AUROC of 88.7 ±0.5 on NCR/O, compared with 80.1 ±0.2 on the intact NC/O headlines. GradNorm likewise records 85.0 ±0.8 on NCR/O and 77.2 ±0.5 on NC/O. NCR/O is easier to separate than its intact counterpart, while NCR/I remains harder to separate than either version of the held-out material for KNN. The origin of the words changes what this perturbation reveals about a detector.

Semantic shift within 20 Newsgroups

ViM has the highest mean AUROC in every semantic-shift pairing. With Computer as ID, it reaches 98.6 ±0.3 against Politics and 97.7 ±0.6 against Sports. MSP reaches 91.5 ±1.9 and 89.8 ±2.7 on the same pairs. With Politics as ID, ViM records 98.3 ±0.2 against Computer and 97.3 ±0.3 against Sports. With Sports as ID, its AUROC is 98.5 ±0.2 against Computer and 98.0 ±0.1 against Politics. The ordering holds across changes to which broad topic group supplies the training examples and task labels.

Detector AUROC on Politics posts with Computer posts as the familiar set

Virtual-logit Matching leads the semantic-shift comparison, and several detectors improve on plain softmax confidence.

Detector AUROC on Politics posts with Computer posts as the familiar setMSP: 91.5MSP91.5Energy: 96.3Energy96.3GradNorm: 95.5GradNorm95.5KLM: 78.0KLM78.0ReAct: 96.2ReAct96.2DICE: 34.6DICE34.6KNN: 97.0KNN97.0ViM (this paper): 98.6ViM (this paper)98.6
The numbers
System or settingAUROC %
MSP91.5
Energy96.3
GradNorm95.5
KLM78.0
ReAct96.2
DICE34.6
KNN97.0
ViM (this paper)98.6

The other metrics reinforce ViM’s advantage here. For Computer as ID and Politics as OOD, it records AUPR-IN of 99.1 ±0.2 and FPR@95 of 7.2 ±1.8. KNN has AUPR-IN of 98.2 ±0.3 and FPR@95 of 17.3 ±4.6. MSP has AUPR-IN of 95.2 ±1.1 and FPR@95 of 55.9 ±11.7. ViM leads both additional metrics across the other semantic-shift pairings as well. Its advantage in this setting is visible in the general ranking and at the reported acceptance target.

Energy, ReAct and GradNorm each attain higher mean AUROC than MSP in every semantic-shift pair. The chart also illustrates the weakness of DICE on these particular data. With Computer as ID and Politics as OOD, its mean AUROC is 34.6 ±13.2, and its FPR@95 is 99.9 ±0.1. An AUROC below 50% gives an unfavorable ordering overall in the reported score direction. The relatively large variation across training runs on this pair also matters when interpreting the mean. The results establish that the benchmarked configuration performs poorly here.

Background shift between review collections

On review-source changes, KNN and ViM each lead some pairings. With IMDB as ID and SST-2 as OOD, KNN attains AUROC of 97.8 ±1.2 and ViM attains 97.3 ±0.7, compared with MSP at 85.3 ±0.8. Keeping IMDB as ID and testing against Yelp gives ViM 98.4 ±0.8 and KNN 97.5 ±1.1, while MSP gives 76.0 ±3.3. Changing the shifted collection therefore changes both the performance of the baseline and the ordering at the top.

Using SST-2 as the familiar source gives a more difficult comparison for ViM. When IMDB is OOD, KNN gets AUROC of 87.2 ±1.7, ViM gets 83.9 ±3.3 and MSP gets 83.2 ±1.4. When Yelp is OOD, KNN gets 87.8 ±0.4 and ViM gets 80.1 ±2.8, while MSP gets 75.7 ±2.2. GradNorm and the two weakest detectors, KLM and DICE, perform especially poorly on these SST-2 training pairs relative to the leading methods. Energy and ReAct remain close to MSP.

Detector AUROC on Yelp reviews with SST-2 as the familiar set

Nearest neighbors leads when the familiar examples are short movie-review texts and the shifted examples are Yelp reviews.

Detector AUROC on Yelp reviews with SST-2 as the familiar setMSP: 75.7MSP75.7Energy: 75.0Energy75.0GradNorm: 61.3GradNorm61.3KLM: 51.3KLM51.3ReAct: 75.7ReAct75.7DICE: 35.4DICE35.4KNN (this paper): 87.8KNN (this paper)87.8ViM: 80.1ViM80.1
The numbers
System or settingAUROC %
MSP75.7
Energy75.0
GradNorm61.3
KLM51.3
ReAct75.7
DICE35.4
KNN (this paper)87.8
ViM80.1

With Yelp as ID, ViM leads both comparisons. It has AUROC of 88.6 ±0.7 against IMDB and 99.0 ±0.1 against SST-2. KNN returns 84.7 ±0.8 and 98.5 ±0.3 on those pairs. The reverse of the Yelp-to-SST-2 comparison appears in the chart. Its lower scores illustrate why the result depends on which source defines familiarity. Training on the short review texts and testing on the longer Yelp texts produces a different detection problem from training on Yelp and testing against SST-2.

The results at the stated acceptance target qualify some of the AUROC gains. For SST-2 as ID and IMDB as OOD, KNN has the leading AUROC but records FPR@95 of 88.3 ±10.9. MSP records 77.7 ±2.3 at that point, and ViM records 79.0 ±17.8. With IMDB as ID and Yelp as OOD, ViM gives FPR@95 of 8.2 ±6.5, KNN gives 15.1 ±9.1 and MSP gives 92.3 ±1.3. The same broad category of background shift thus contains cases where the leading detectors separate the input populations well at the reported operating point and cases where a large fraction of shifted texts still passes.

What the ablations show

The paper reports no component-level ablation and instead analyzes detector behavior through matched test comparisons, directional changes of training source and randomized-input tests.

Changing the text while preserving its source categories

The headline randomization is the closest experiment to a controlled input intervention. Its comparison fixes the trained news classifier and keeps the source-category partition and text lengths used to construct the randomized data. For the held-out topics, the authors can compare ordinary NC/O headlines with NCR/O. The stronger results on NCR/O show that disrupting the text can increase evidence of unfamiliarity when the underlying category is already unfamiliar. That result on its own would give an incomplete picture of sensitivity to sentence structure.

NCR/I supplies the complementary check. Its words come from familiar categories, and precisely that material can still give the trained classifier cues it recognizes. The detector is supposed to flag the resulting input as shifted because the original context has been disrupted. The low AUROC and high FPR@95 scores show how often this kind of disruption escapes detection in the benchmark. This matters especially for KNN. Its lead over the other detectors is visible in both the usual headline tests and NCR/I, yet its absolute NCR/I performance leaves much of the disruption undetected.

The authors interpret this pattern as resembling bag-of-words behavior. A bag-of-words representation keeps information about which words appear while discarding their order. The observed scores are compatible with strong reliance on recognizable lexical material in this task. The experiment measures the combined behavior of the trained classifier and the detector. It does not independently trace how an internal representation changes under randomization or measure how much information about word order remains available elsewhere in the network.

Changing which data define familiarity

The review comparisons provide a different kind of control. The positive and negative label scheme stays in place, and the experiment changes which collection supplies training data and which supplies OOD examples. SST-2 illustrates the value of testing both directions. Its texts are short relative to IMDB and Yelp. As an OOD collection against either of those familiar sources, it is well separated by KNN and ViM. As the familiar training source, it gives ViM markedly weaker results against the longer collections. KNN is the AUROC leader in both comparisons with SST-2 as ID.

That directional pattern supports the authors’ suspicion that ViM can be sensitive when trained on short texts and then exposed to long shifted inputs. The comparisons also change how the texts were collected, what they describe and which examples establish the reference statistics. Length is one explanation consistent with the results. The design does not isolate it by matching source collections for length or varying length while keeping the other factors fixed. The measured conclusion is narrower and more useful for interpreting the table. ViM’s results depend on which review source defines the familiar feature and output distributions.

The newsgroup pairs show what a consistent method advantage looks like in the same design. ViM leads whichever broad group supplies the classifier, and the additional metrics support the AUROC ordering. Energy, ReAct and GradNorm also improve on MSP in all the semantic-shift AUROC comparisons. Their results are weaker relative to MSP in the background-shift comparisons, although ReAct does slightly exceed it on some pairs. The pattern concerns the benchmarked families of tests. It does not establish that an output or gradient score can help only when new topic labels appear.

What can be attributed to the detector

Within a particular test comparison, the classifiers and data are held common across scoring methods. This supports a direct comparison between MSP and a detector that uses training representations, for instance. When KNN improves the separation of Twitter from familiar news, one can attribute the changed ranking to the switch in detection procedure within that setup. Comparing KNN on Twitter and NC/O asks a different question. The same detector now faces different inputs, so the change in performance reflects how its evidence interacts with the test population.

KNN and ViM each use a learned representation, and both generally outperform the simpler reference on the paper’s primary metric. That shared property offers a plausible way to understand part of their success. A representation can retain information about the input beyond the classifier’s confidence in the selected task label. The benchmark does not separately remove ViM’s representation term and its logit term, or substitute a common distance computation across detectors. The evidence is therefore strongest about how the complete methods compare. The experiments leave open how much each constituent operation contributes to the observed advantage.

KLM and DICE also illustrate the distinction between a method’s rationale and its measured behavior. A class probability profile could carry useful information about familiarity, and restricting weights could suppress distracting contributions. The poor outcomes for their benchmarked configurations establish that these signals did not yield reliable separation across these test pairs. They give no direct diagnosis of which reference statistics, settings or characteristics of the representations caused the failures. For the benchmark’s purpose, those outcomes are informative because the methods were tested under the same integration conditions as the stronger alternatives.

Limitations

Limits the authors state

The authors restrict their experiments to text classification. They identify named entity recognition and question answering as other places to investigate detection. Those tasks organize predictions differently from assigning a document to a category. The paper also proposes a fuller treatment of task shift, in which inputs arise from an completely different prediction problem. The review texts used against the news classifier already differ in purpose and source, but the benchmark does not isolate task shift as a separate controlled factor.

The authors also use a single backbone, RoBERTa base. A common backbone makes the detector comparisons easier to interpret internally. It also binds the results to the feature space, logits and gradients that this backbone produces after fine-tuning. A nearest-neighbor score is particularly tied to the geometry of the representations it receives, while an output-based score depends on the head’s behavior. The relative ordering could change with a different architecture or training procedure. The authors identify broader architectural comparisons as work left open.

Computational constraints prevented a hyper-parameter search for the classifier and the detectors. The benchmark uses fixed settings and takes detector values from the original papers. That approach measures the performance of these methods under a straightforward integration procedure. It leaves their best attainable performance on each task unresolved. A different configuration could change weak results, and the benchmark offers no tuning experiment with which to estimate the size or direction of such a change.

Limits apparent from the experimental design

The intended shift categories help organize the experiments, but individual collections bring several changes at once. Moving from HuffPost headlines to Twitter posts changes provenance and writing style as well as the form and length of the input. Moving from news to reviews changes subject matter, communicative purpose and frequently length. The language comparison reduces one conspicuous cue by retaining only Latin-script languages, while leaving other source and textual differences in place. Each result therefore belongs to the concrete pair evaluated. The paper’s group names describe the design and give no calibrated measure of how much any one factor changed.

Semantic and background shift are likewise implemented through different datasets. The newsgroup tests use branches of a common corpus to create changes in relevant classes. The review tests draw on distinct collections while retaining the sentiment labels. This design can reveal that the detectors respond differently in the two settings. It offers less control over whether that difference arises from the kind of shift, the particular corpora, the training set sizes or their combined effect. The strong ViM results on semantic shift are best read in the context of the newsgroup comparisons the authors actually ran.

The randomization puts a specific kind of structural disturbance under test. The paper describes drawing words from the material available within a category while retaining item lengths. That procedure controls category provenance and the number of words in an item, but it can also change which words co-occur and which associations are available within an individual headline. The experiment consequently supports a claim about the detection of these category-based randomized inputs. A claim about order alone would require an intervention that kept the individual headline’s words fixed. Naturally occurring mistakes and disruptions could also produce different results from the benchmark’s randomized samples.

The reported standard deviations describe variation across training seeds for the datasets and splits in the experiment. They do not measure uncertainty over possible future data sources. On NC/O, for instance, the leading mean AUROC values for KNN and ViM are close. The table establishes their observed ordering, while the paper supplies no significance test for that comparison. Repeated training runs help readers judge sensitivity to training variation, with the scope of that evidence determined by the test collections themselves.

Finally, the benchmark captures separate pieces of a human-review workflow. It measures familiar classification quality and how well detectors distinguish familiar from shifted inputs. Its FPR@95 figures illustrate the tradeoff at a specified acceptance target. Deployment would also depend on how frequently each kind of shift occurs, how a threshold is selected for future inputs and what happens when flagged documents go to reviewers. The paper’s document-processing example motivates those questions. The reported experiments measure detector scores and benchmark operating points rather than outcomes from an actual review process.

What came after

Subsequent work that builds on this benchmark is undocumented here. The paper itself leaves an extensible comparison for testing new detectors against familiar-looking topic changes, shifts between review sources and disruptions that preserve the lexical material of familiar text.

Cite

Cite as Mateusz Baran, Joanna Baran, Mateusz Wójcik, Maciej Zięba and Adam Gonczarek. 2023. Classical Out-of-Distribution Detection Methods Benchmark in Text Classification Tasks. Proceedings of the 61st Annual Meeting of the Association for Computational Linguistics (Volume 4: Student Research Workshop).

The paper itself, not this page. BibTeX from the library's record of the work. DOI 10.18653/v1/2023.acl-srw.20

@inproceedings{baran2023classical,
  title = {{Classical Out-of-Distribution Detection Methods Benchmark in Text Classification Tasks}},
  author = {Mateusz Baran, Joanna Baran, Mateusz Wójcik, Maciej Zięba and Adam Gonczarek},
  booktitle = {Proceedings of the 61st Annual Meeting of the Association for Computational Linguistics (Volume 4: Student Research Workshop)},
  year = {2023},
  doi = {10.18653/v1/2023.acl-srw.20},
  url = {https://doi.org/10.18653/v1/2023.acl-srw.20}
}

↑ back to top

This page in Markdown https://md.research.elamur.ai/free/en/papers/baran-2023-classical-out-distribution-detection-methods/