SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2305.13282 · ACL · 2023

Is Fine-tuning Needed? Pre-trained Language Models Are Near Perfect for Out-of-Domain Detection

Junjie Hu, Yixuan Li, Rheeya Uppaal

arXiv · PDF · Open in the Atlas

Code that ran

8 of 10 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 7 have no contract verdict; 1 failure of our instrument; 2 no recorded run), measured 2026-11-22; repository links from the Papers with Code archive attributed under CC BY-SA, no affiliation; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2305.13282.json · badge: /api/ran/2305.13282.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
Uppaal/lm-ood canonical (classifier label)
classifier basis: census
8 ran · 2 no recorded run
FunctionStatusWhere it lives
collate_fn Ran
ran on a synthesized input
Uppaal/lm-ood/utils/startup.py
code served (permissive licence) · get_code("e27e3e8767d93f9e")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned dict. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

torch.manual_seed(0)

# Create sample batch data
# Each item needs 'input_ids' (a tensor), and 'labels' (a scalar)
batch = [
    {
        'input_ids': torch.tensor([101, 2054, 2003], dtype=torch.long),
        'labels': torch.tensor(1, dtype=torch.long)
    },
    {
        'input_ids': torch.tensor([101, 2054], dtype=torch.long),
        'labels': torch.tensor(0, dtype=torch.long)
    },
    {
        'input_ids': torch.tensor([101, 2054, 2003, 2545, 1012], dtype=torch.long),
        'labels': torch.tensor(1, dtype=torch.long)
    }
]

ARGS = {
    'batch': batch
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
compute_loss Ran
ran on a synthesized input
Uppaal/lm-ood/model.py
code served (permissive licence) · get_code("d4befec42a19db00")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned tuple, ndim 1, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

torch.manual_seed(0)

# Create a minimal config class
class Config:
    def __init__(self):
        self.contrastive_loss = 'cosine'  # or 'margin'
        self.tau = 0.07
        self.cross_entropy_weight = 1.0
        self.contrastive_weight = 0.5

# Create a minimal model class
class MinimalModel(nn.Module):
    def __init__(self, num_labels=1):
        super().__init__()
        self.config = Config()
        self.num_labels = num_labels

model = MinimalModel(num_labels=3)

# Create tensors with distinct sizes
batch_size = 2
hidden_dim = 4
num_labels = 3

# labels: batch of class indices
labels = torch.tensor([0, 1])

# logits: (batch_size, num_labels)
logits = torch.randn(batch_size, num_labels)

# pooled: (batch_size, hidden_dim)
pooled = torch.randn(batch_size, hidden_dim)

ARGS = {
    'model': model,
    'labels': labels,
    'logits': logits,
    'pooled': pooled
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple, ndim 1, dtype family float — a tuple output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
describe_training_method Ran
ran on a synthesized input
Uppaal/lm-ood/run_ood_detection.py
code served (permissive licence) · get_code("92188b9962a95088")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned str. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

torch.manual_seed(0)

class Args:
    def __init__(self):
        self.cross_entropy_weight = 0.5
        self.contrastive_weight = 0.3
        self.contrastive_loss = 'triplet'
        self.linear_probe = True

ARGS = {
    'args': Args()
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
get_auroc Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
Uppaal/lm-ood/evaluation.py
pointer only (licence: MIT); the stored copy get_code serves, from awenbocc/llm-ood, is pointer only (licence: NONE) · get_code("ace38fb975eb5cfa")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from awenbocc/llm-ood, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

get_sent_embeddings Ran
ran on a synthesized input
Uppaal/lm-ood/model.py
code served (permissive licence) · get_code("08fed2404d724a96")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned tuple. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

torch.manual_seed(0)

# Create a minimal config class for RoBERTa model
class RoBERTaConfig:
    def __init__(self):
        self._name_or_path = "roberta-base"
        self.sentence_embedding = 'average'
        self.layer_representation_for_ood = 'penultimate_layer'
        self.hidden_size = 4
        self.vocab_size = 100
        self.pad_token_id = 0

# Create a minimal RoBERTa-like model
class MinimalRoBERTaModel(nn.Module):
    def __init__(self, config):
        super().__init__()
        self.config = config
        # Minimal transformer-like layer
        self.roberta = nn.Module()
        self.roberta.forward = self._roberta_forward
        self.classifier = nn.Linear(config.hidden_size, 2)
    
    def _roberta_forward(self, input_ids, attention_mask):
        batch_size, seq_len = input_ids.shape
        hidden_states = torch.randn(batch_size, seq_len, self.config.hidden_size)
        return (hidden_states,)
    
    def forward(self, input_ids, attention_mask):
        return self.roberta(input_ids, attention_mask=attention_mask)

# Create config and model
config = RoBERTaConfig()
model = MinimalRoBERTaModel(config)

# Create minimal input tensors
batch_size = 2
seq_length = 5
input_ids = torch.randint(1, 100, (batch_size, seq_length))
attention_mask = torch.ones(batch_size, seq_length)

ARGS = {
    'model': model,
    'input_ids': input_ids,
    'attention_mask': attention_mask
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple — a tuple output has no array shape of its own; none is stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
load_tokenizer Ran
ran on a synthesized input
Uppaal/lm-ood/utils/model_utils.py
code served (permissive licence) · get_code("bb9cc88f0bea27c4")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned MockTokenizer. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn
from transformers import AutoTokenizer

# Create a minimal stand-in for a pretrained tokenizer
class MockTokenizer:
    def __init__(self):
        self.eos_token = "<|endoftext|>"
        self.pad_token = None
        self.padding_side = "left"
    
    def __call__(self, text, **kwargs):
        return {"input_ids": [1, 2, 3], "attention_mask": [1, 1, 1]}

# Mock AutoTokenizer.from_pretrained to return our mock tokenizer
original_from_pretrained = AutoTokenizer.from_pretrained
def mock_from_pretrained(model_path, **kwargs):
    return MockTokenizer()

AutoTokenizer.from_pretrained = staticmethod(mock_from_pretrained)

ARGS = {
    "model_path": "gpt2",
    "model_str": "gpt2"
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch, transformers — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type MockTokenizer — a MockTokenizer output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a MockTokenizer output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
merge_keys Ran
ran on a synthesized input
Uppaal/lm-ood/evaluation.py
code served (permissive licence) · get_code("0ae01890dc1a0be1")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned dict. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

torch.manual_seed(0)

# The function merge_keys takes:
# - l: a list of dictionaries (batch_scores)
# - keys: a list of keys to merge
#
# It iterates over keys, and for each key, concatenates values from each batch_scores dict
# The values are concatenated with +=, suggesting they are lists

# Create sample batch_scores dictionaries
batch_scores_1 = {
    'accuracy': [0.8, 0.9],
    'loss': [0.1, 0.2],
    'f1': [0.75, 0.85]
}

batch_scores_2 = {
    'accuracy': [0.92, 0.88],
    'loss': [0.15, 0.12],
    'f1': [0.80, 0.82]
}

batch_scores_3 = {
    'accuracy': [0.85],
    'loss': [0.18],
    'f1': [0.78]
}

l = [batch_scores_1, batch_scores_2, batch_scores_3]
keys = ['accuracy', 'loss', 'f1']

ARGS = {
    'l': l,
    'keys': keys
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
resolve_path Ran
ran on a synthesized input
Uppaal/lm-ood/download_models.py
code served (permissive licence) · get_code("5aa8c0ddf6cf12c2")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned PosixPath. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import sys
from pathlib import Path

# Mock __file__ by simulating a module file path
class MockModule:
    __file__ = "/home/user/repo/module.py"

sys.modules['__main__'].__file__ = "/home/user/repo/module.py"

# Now define resolve_path function with proper repo_root
repo_root = Path("/home/user/repo")

def resolve_path(path):
    path = Path(path).expanduser()
    if path.is_absolute():
        return path
    return repo_root / path

# Test with various path inputs
test_path_relative = "data/file.txt"
test_path_absolute = "/absolute/path/to/file.txt"
test_path_with_home = "~/documents/file.txt"

ARGS = {
    "path": test_path_relative
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type PosixPath — a PosixPath output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a PosixPath output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
compute_metrics Not yet run
unverified (harvested, no recorded run)
Uppaal/lm-ood/utils/trainer_utils.py
code served (permissive licence) · get_code("b43faec17e425ded")
How it ran

no invocation recorded.

load_model Not yet run
unverified (harvested, no recorded run)
Uppaal/lm-ood/utils/model_utils.py
code served (permissive licence) · get_code("48775127b9ab8dbe")
How it ran

no invocation recorded.

Also present in other papers' code

Of 10 samples lifted from this paper's linked repositories, 10 carry a function identity and 0 do not. Of the 10 distinct functions with an identity, 1 are also present in other papers whose code we hold (1 with at least one paper dated earlier, 0 the same month, 1 later) and 9 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

FunctionAlso present inEarliest-datedOthers named
get_auroc 2 other papers
1 dated earlier, 1 later
2104.08812 (2021-04)
Contrastive Out-of-Distribution Detection for Pretrained Transformers
2308.10261 (2023-08)
How Good Are LLMs at Out-of-Distribution Detection?

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-22.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

Out-of-distribution (OOD) detection is a critical task for reliable predictions over text. Finetuning with pre-trained language models has been a de facto procedure to derive OOD detectors with respect to in-distribution (ID) data. Despite its common use, the understanding of the role of fine-tuning and its necessity for OOD detection is largely unexplored. In this paper, we raise the question: is fine-tuning necessary for OOD detection? We present a study investigating the efficacy of directly leveraging pre-trained language models for OOD detection, without any model fine-tuning on the ID data. We compare the approach with several competitive fine-tuning objectives, and offer new insights under various types of distributional shifts. Extensive evaluations on 8 diverse ID-OOD dataset pairs demonstrate nearperfect OOD detection performance (with 0% FPR95 in many cases), strongly outperforming its fine-tuned counterparts. We show that using distance-based detection methods, pretrained language models are near-perfect OOD detectors when the distribution shift involves a domain change. Furthermore, we study the effect of fine-tuning on OOD detection and identify how to balance ID accuracy with OOD detection performance. Our code is publically available 1 .

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2305.13282")
get_code_for_paper("2305.13282")
have("2305.13282")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2305.13282.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2305.13282.svg)](https://syntology.ai/paper/2305.13282)

Connect an agent — have() is free.