SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2308.12213 · ICCV · 2023

CLIPN for Zero-Shot OOD Detection: Teaching CLIP to Say No

Yi Li, Hualiang Wang, Xiaomeng Li, Huifeng Yao

arXiv · PDF · Open in the Atlas

Code that ran

10 of 16 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (1 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 1 has no contract verdict; 9 failures of our instrument; 6 no recorded run), measured 2026-11-23; 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/2308.12213.json · badge: /api/ran/2308.12213.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
xmed-lab/clipn canonical (classifier label)
classifier basis: census
9 ran · 5 no recorded run
xmed-lab/CLIPN community
Papers with Code archive
1 ran · 1 no recorded run
FunctionStatusWhere it lives
ClipLoss Ran
ran on a synthesized input · constructed an object; no result was computed
xmed-lab/CLIPN/hand-crafted/src/open_clip/loss.py
code served (permissive licence) · get_code("398dd84d8c1a0c99")
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 an instance of its own class, ClipLoss: the run constructed the object and did not call it, so no result was computed. 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)

# Mock distributed module since we won't actually use it
class MockDistributed:
    pass

# Setup: Create minimal valid arguments for ClipLoss
batch_size = 2
feature_dim = 4

image_features = torch.randn(batch_size, feature_dim)
text_features = torch.randn(batch_size, feature_dim)
text_features_no = torch.randn(batch_size, feature_dim)
logit_scale = torch.tensor(1.0)

ARGS = {
    'local_loss': False,
    'gather_with_grad': False,
    'cache_labels': False,
    'rank': 0,
    'world_size': 1,
    'use_horovod': False,
}
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 ClipLoss — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a ClipLoss 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
cosine_lr Ran
ran; our contract draft was wrong, not the code
xmed-lab/clipn/src/tuning_util.py
pointer only (licence: MIT); the stored copy get_code serves, from BAIKLAB/SiM, is pointer only (licence: NONE) · get_code("2d5d7a12d8de02b7")
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 BAIKLAB/SiM, 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.

energy_score Ran
ran; our contract draft was wrong, not the code
xmed-lab/clipn/src/zero_shot_infer.py
code served (permissive licence) · get_code("77aa71bc99c32b88")
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 ndarray, ndim 1, dtype family float, shape (2,) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape 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 a small logits tensor
# Shape: (batch_size=2, num_classes=4)
logits = torch.randn(2, 4)

ARGS = {
    "logits": logits
}
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 ndarray, ndim 1, dtype family float, shape (2,) — shape (2,) as a later run recorded it
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
energy_score Ran
ran; our contract draft was wrong, not the code
xmed-lab/clipn/hand-crafted/src/zero_shot_infer.py
code served (permissive licence) · get_code("570302e9d15c6b9b")
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 ndarray, ndim 1, dtype family float, shape (2,) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape 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 numpy as np

torch.manual_seed(0)

# The function takes logits (a tensor) and temperature (a float)
# It performs: torch.logsumexp(logits * temperature - temperature, -1)
# So logits needs to be a tensor with at least one dimension (the -1 dimension)

logits = torch.randn(2, 4)  # batch_size=2, num_classes=4
temperature = 100

ARGS = {
    "logits": logits,
    "temperature": temperature,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type ndarray, ndim 1, dtype family float, shape (2,) — shape (2,) as a later run recorded it
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
load_state_dict Ran
ran; our contract draft was wrong, not the code
xmed-lab/clipn/src/open_clip/factory.py
code served (permissive licence) · get_code("5e42380894ae9205")
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 tempfile
import os

torch.manual_seed(0)

# Create a temporary checkpoint file to simulate a saved model
temp_dir = tempfile.mkdtemp()
checkpoint_path = os.path.join(temp_dir, "model.pt")

# Create a sample state dict with keys that match the patterns the function checks
state_dict = {
    'transformer.layer1.weight': torch.randn(4, 3),
    'transformer.layer1.bias': torch.randn(4),
    'token_embedding.weight': torch.randn(5, 4),
    'positional_embedding': torch.randn(10, 4),
    'ln_final.weight': torch.randn(4),
    'ln_final.bias': torch.randn(4),
    'text_projection': torch.randn(4, 3),
    'other_layer.weight': torch.randn(3, 2),
}

# Save as a checkpoint dict
checkpoint = {'state_dict': state_dict}
torch.save(checkpoint, checkpoint_path)

ARGS = {
    'checkpoint_path': checkpoint_path,
    'map_location': 'cpu',
}
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
load_state_dict_local Ran
ran; our contract draft was wrong, not the code
xmed-lab/clipn/src/open_clip/factory.py
code served (permissive licence) · get_code("72166ecea4b59f55")
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 tempfile
import os

torch.manual_seed(0)

# Create a temporary checkpoint file
temp_dir = tempfile.mkdtemp()
checkpoint_path = os.path.join(temp_dir, "checkpoint.pt")

# Create a sample state dict with model weights
sample_state_dict = {
    'layer1.weight': torch.randn(4, 3),
    'layer1.bias': torch.randn(4),
    'layer2.weight': torch.randn(5, 4),
    'layer2.bias': torch.randn(5),
}

# Save the checkpoint
torch.save(sample_state_dict, checkpoint_path)

ARGS = {
    'checkpoint_path': checkpoint_path,
    'map_location': 'cpu',
}
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
max_logit_score Ran
ran; our contract draft was wrong, not the code
xmed-lab/clipn/src/zero_shot_infer.py
code served (permissive licence) · get_code("6ae44ac0f19069aa")
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 ndarray, ndim 1, dtype family float, shape (2,) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape 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)

logits = torch.randn(2, 4)

ARGS = {
    "logits": logits
}
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 ndarray, ndim 1, dtype family float, shape (2,) — shape (2,) as a later run recorded it
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
maybe_dictionarize Ran
ran; our contract draft was wrong, not the code
xmed-lab/clipn/src/tuning_util.py
code served (permissive licence) · get_code("b1e9e0d3d7d7e615")
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 numpy as np

torch.manual_seed(0)

# Test case 1: batch as a dict (should return as-is)
batch_dict = {
    'images': torch.randn(2, 4),
    'labels': torch.randint(0, 10, (2,))
}

# Test case 2: batch as tuple with 2 elements
batch_tuple_2 = (
    torch.randn(2, 4),
    torch.randint(0, 10, (2,))
)

# Test case 3: batch as tuple with 3 elements
batch_tuple_3 = (
    torch.randn(2, 4),
    torch.randint(0, 10, (2,)),
    {'sample_id': [0, 1]}
)

# Use the dict case for ARGS
ARGS = {
    'batch': batch_dict
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, 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
msp_score Ran
ran; our contract draft was wrong, not the code
xmed-lab/clipn/src/zero_shot_infer.py
code served (permissive licence) · get_code("be2496a325c68b28")
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 ndarray, ndim 1, dtype family float, shape (2,) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape 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)

# The function takes logits as input and computes softmax probabilities,
# then returns the maximum probability for each sample.
# logits should be a 2D tensor of shape (batch_size, num_classes)

logits = torch.randn(2, 4)  # batch_size=2, num_classes=4

ARGS = {
    "logits": logits,
}
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 ndarray, ndim 1, dtype family float, shape (2,) — shape (2,) as a later run recorded it
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
trace_model Ran
ran; our contract draft was wrong, not the code
xmed-lab/clipn/src/open_clip/model.py
pointer only (licence: MIT); the stored copy get_code serves, from NYU-DICE-Lab/open_clip, is pointer only (licence: NOASSERTION) · get_code("8e95157106d1df8c")
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 NYU-DICE-Lab/open_clip, and GitHub could not classify the licence of that repository (NOASSERTION). 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.

accuracy Not yet run
unverified (harvested, no recorded run)
xmed-lab/clipn/src/tuning_util.py
code served (permissive licence) · get_code("aafcff3ad1ccef6e")
How it ran

no invocation recorded.

build_model_from_openai_state_dict Not yet run
unverified (harvested, no recorded run)
xmed-lab/clipn/src/open_clip/model.py
code served (permissive licence) · get_code("630cd10269e63c8c")
How it ran

no invocation recorded.

gather_features Not yet run
unverified (harvested, no recorded run)
xmed-lab/CLIPN/hand-crafted/src/open_clip/loss.py
code served (permissive licence) · get_code("61c4ca21dc698a56")
How it ran

no invocation recorded.

load_checkpoint Not yet run
unverified (harvested, no recorded run)
xmed-lab/clipn/src/open_clip/factory.py
code served (permissive licence) · get_code("69e67ef52fe6fde8")
How it ran

no invocation recorded.

load_openai_model Not yet run
unverified (harvested, no recorded run)
xmed-lab/clipn/src/open_clip/openai.py
code served (permissive licence) · get_code("ce3d74d26643c4c1")
How it ran

no invocation recorded.

torch_load Not yet run
unverified (harvested, no recorded run)
xmed-lab/clipn/src/classification.py
code served (permissive licence) · get_code("2235e9caabb77a27")
How it ran

no invocation recorded.

Also present in other papers' code

Of 16 samples lifted from this paper's linked repositories, 16 carry a function identity and 0 do not. Of the 16 distinct functions with an identity, 6 are also present in other papers whose code we hold (5 with at least one paper dated earlier, 2 the same month, 6 later) and 10 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
accuracy 22 other papers
4 dated earlier, 2 the same month, 16 later
2207.05333 (2022-07)
IDEA: Increasing Text Diversity via Online Multi-Label Recognition for Vision-Language Pre-training
2208.05592 (2022-08)
Patching open-vocabulary models by interpolating weights
2211.12914 (2022-11)
Open-vocabulary Attribute Detection
and 19 more not named here
maybe_dictionarize 13 other papers
1 the same month, 12 later · 1 only as an assembly brick
2308.01313 (2023-08)
PerceptionCLIP: Visual Classification by Inferring and Conditioning on Contexts
2311.01723 (2023-11)
Towards Calibrated Robust Fine-Tuning of Vision-Language Models
2312.02546 (2023-12)
Machine Vision Therapy: Multimodal Large Language Models Can Enhance Visual Robustness via Denoising In-Context Learning
and 10 more not named here
cosine_lr 11 other papers
2 dated earlier, 9 later
2208.05592 (2022-08)
Patching open-vocabulary models by interpolating weights
2305.12827 (2023-05)
Task Arithmetic in the Tangent Space: Improved Editing of Pre-Trained Models
aaai_27950 (2024 (year only))
LAMM: Label Alignment for Multi-Modal Prompt Learning
and 8 more not named here
trace_model 8 other papers
4 dated earlier, 4 later
2103.00020 (2021-03)
Learning Transferable Visual Models From Natural Language Supervision
2210.04150 (2022-10)
Open-Vocabulary Semantic Segmentation with Mask-adapted CLIP
2302.10281 (2023-02)
LiT Tuned Models for Efficient Species Detection
and 5 more not named here
build_model_from_openai_state_dict 3 other papers
1 dated earlier, 2 later
2210.04150 (2022-10)
Open-Vocabulary Semantic Segmentation with Mask-adapted CLIP
2405.00740 (2024-05)
Modeling Caption Diversity in Contrastive Vision-Language Pretraining
2412.10372 (2024-12)
UniMed-CLIP: Towards a Unified Image-Text Pretraining Paradigm for Diverse Medical Imaging Modalities
torch_load 2 other papers
1 dated earlier, 1 later
2208.05592 (2022-08)
Patching open-vocabulary models by interpolating weights
2410.03782 (2024-10)
DaWin: Training-free Dynamic Weight Interpolation for Robust Adaptation

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-23.

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 refers to training the model on an in-distribution (ID) dataset to classify whether the input images come from unknown classes. Considerable effort has been invested in designing various OOD detection methods based on either convolutional neural networks or transformers. However, zero-shot OOD detection methods driven by CLIP, which only require class names for ID, have received less attention. This paper presents a novel method, namely CLIP saying "no" (CLIPN), which empowers the logic of saying "no" within CLIP. Our key motivation is to equip CLIP with the capability of distinguishing OOD and ID samples using positivesemantic prompts and negation-semantic prompts. Specifically, we design a novel learnable "no" prompt and a "no" text encoder to capture negation semantics within images. Subsequently, we introduce two loss functions: the imagetext binary-opposite loss and the text semantic-opposite loss, which we use to teach CLIPN to associate images with "no" prompts, thereby enabling it to identify unknown samples. Furthermore, we propose two threshold-free inference algorithms to perform OOD detection by utilizing negation semantics from "no" prompts and the text encoder. Experimental results on 9 benchmark datasets (3 ID datasets and 6 OOD datasets) for the OOD detection task demonstrate that CLIPN, based on ViT-B-16, outperforms 7 well-used algorithms by at least 2.34% and 11.64% in terms of AUROC and FPR95 for zero-shot OOD detection on ImageNet-1K. Our CLIPN can serve as a solid foundation for effectively leveraging CLIP in downstream OOD tasks. The code is available on https://github.com/xmed-lab/CLIPN.

For agents

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

get_harvested_code_for_paper("2308.12213")
get_code_for_paper("2308.12213")
have("2308.12213")

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

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

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

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

Connect an agent — have() is free.