SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2103.01537 · CVPR · 2021

Few-shot Open-set Recognition by Transformation Consistency

Changick Kim, Seokeon Choi, Minki Jeong

arXiv · PDF · Open in the Atlas

Code that ran

2 of 4 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 2 have no contract verdict; 0 failures 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/2103.01537.json · badge: /api/ran/2103.01537.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
MinkiJ/SnaTCHer community
Papers with Code archive
2 ran · 2 no recorded run
FunctionStatusWhere it lives
MultiHeadAttention Ran
ran on a synthesized input
MinkiJ/SnaTCHer/model/models/SnaTCHerF.py
code served (permissive licence) · get_code("85ecf5763f8f6ec3")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) 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
import numpy as np

class Args:
    def __init__(self):
        self.slf_flag_norm = True

INIT_ARGS = {
    'args': Args(),
    'n_head': 2,
    'd_model': 4,
    'd_k': 3,
    'd_v': 3,
    'dropout': 0.1,
}

ARGS = {
    'q': torch.randn(2, 5, 4),
    'k': torch.randn(2, 5, 4),
    'v': torch.randn(2, 5, 4),
}

if __name__ == '__main__':
    from torch import nn
    import sys
    sys.path.insert(0, '/tmp')
    
    class ScaledDotProductAttention(nn.Module):
        """ Scaled Dot-Product Attention """

        def __init__(self, temperature, attn_dropout=0.1):
            super().__init__()
            self.temperature = temperature
            self.dropout = nn.Dropout(attn_dropout)
            self.softmax = nn.Softmax(dim=2)

        def forward(self, q, k, v):
            attn = torch.bmm(q, k.transpose(1, 2))
            attn = attn / self.temperature
            raw_attn = attn
            log_attn = torch.nn.functional.log_softmax(attn, 2)
            attn = self.softmax(attn)
            attn = self.dropout(attn)
            output = torch.bmm(attn, v)
            return (output, attn, log_attn, raw_attn)

    class MultiHeadAttention(nn.Module):
        """ Multi-Head Attention module """

        def __init__(self, args, n_head, d_model, d_k, d_v, dropout=0.1):
            super().__init__()
            self.n_head = n_head
            self.d_k = d_k
            self.d_v = d_v
            self.w_qs = nn.Linear(d_model, n_head * d_k, bias=False)
            self.w_ks = nn.Linear(d_model, n_head * d_k, bias=False)
            self.w_vs = nn.Linear(d_model, n_head * d_v, bias=False)
            nn.init.normal_(self.w_qs.weight, mean=0, std=np.sqrt(2.0 / (d_model + d_k)))
            nn.init.normal_(self.w_ks.weight, mean=0, std=np.sqrt(2.0 / (d_model + d_k)))
            nn.init.normal_(self.w_vs.weight, mean=0, std=np.sqrt(2.0 / (d_model + d_v)))
            self.attention = ScaledDotProductAttention(temperature=np.power(d_k, 0.5))
            self.layer_norm = nn.LayerNorm(d_model)
            self.fc = nn.Linear(n_head * d_v, d_model)
            nn.init.xavier_normal_(self.fc.weight)
            self.dropout = nn.Dropout(dropout)
            self.probe_attn = None
            self.probe_q = None
            self.probe_k = None
            self.probe_v = None
            self.temperature = np.power(d_k, 0.5)
            self.flag_norm = args.slf_flag_norm if hasattr(args, 'slf_flag_norm') else True

        def forward(self, q, k, v):
            d_k, d_v, n_head = (self.d_k, self.d_v, self.n_head)
            sz_q, len_q, _ = q.size()
            sz_b, len_k, _ = k.size()
            sz_b, len_v, _ = v.size()
            residual = q
            q = self.w_qs(q).view(sz_q, len_q, n_head, d_k)
            k = self.w_ks(k).view(sz_b, len_k, n_head, d_k)
            v = self.w_vs(v).view(sz_b, len_v, n_head, d_v)
            q = q.permute(2, 0, 1, 3).contiguous().view(-1, len_q, d_k)
            k = k.permute(2, 0, 1, 3).contiguous().view(-1, len_k, d_k)
            v = v.permute(2, 0, 1, 3).contiguous().view(-1, len_v, d_v)
            self.probe_q = q
            self.probe_k = k
            self.probe_v = v
            output, attn, log_attn, raw_attn = self.attention(q, k, v)
            self.probe_attn = attn
            self.probe_raw_attn = raw_attn
            output = output.view(n_head, sz_q, len_q, d_v)
            output = output.permute(1, 2, 0, 3).contiguous().view(sz_q, len_q, -1)
            resout = self.fc(output)
            output = self.dropout(resout)
            if self.flag_norm:
                output = self.layer_norm(output + residual)
            else:
                output = output
            return (output, resout)

    model = MultiHeadAttention(**INIT_ARGS)
    result = model(**ARGS)
    print("Output shape:", result[0].shape)
    print("Resout shape:", result[1].shape)
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
Imports
numpy, 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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
ScaledDotProductAttention Ran
ran on a synthesized input · constructed an object; no result was computed
MinkiJ/SnaTCHer/model/models/SnaTCHerF.py
code served (permissive licence) · get_code("4db87d995642db1f")
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, ScaledDotProductAttention: 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
import torch.nn.functional as F

torch.manual_seed(0)

class ScaledDotProductAttention(nn.Module):
    """ Scaled Dot-Product Attention """

    def __init__(self, temperature, attn_dropout=0.1):
        super().__init__()
        self.temperature = temperature
        self.dropout = nn.Dropout(attn_dropout)
        self.softmax = nn.Softmax(dim=2)

    def forward(self, q, k, v):
        attn = torch.bmm(q, k.transpose(1, 2))
        attn = attn / self.temperature
        raw_attn = attn
        log_attn = F.log_softmax(attn, 2)
        attn = self.softmax(attn)
        attn = self.dropout(attn)
        output = torch.bmm(attn, v)
        return (output, attn, log_attn, raw_attn)

# Construct valid arguments
batch_size = 2
seq_len = 3
d_model = 4

# Create query, key, value tensors
# q: (batch, seq_len, d_model)
# k: (batch, seq_len, d_model)
# v: (batch, seq_len, d_model)
q = torch.randn(batch_size, seq_len, d_model)
k = torch.randn(batch_size, seq_len, d_model)
v = torch.randn(batch_size, seq_len, d_model)

# Temperature parameter
temperature = 2.0

ARGS = {
    'temperature': temperature,
    'attn_dropout': 0.1
}
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 ScaledDotProductAttention — 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 ScaledDotProductAttention 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
FewShotModel Not yet run
unverified (harvested, no recorded run)
MinkiJ/SnaTCHer/model/models/SnaTCHerF.py
code served (permissive licence) · get_code("64ad17ab7c2b66c3")
How it ran

no invocation recorded.

SnaTCHerF Not yet run
unverified (harvested, no recorded run)
MinkiJ/SnaTCHer/model/models/SnaTCHerF.py
code served (permissive licence) · get_code("e94d87f4c8c1a82c")
How it ran

no invocation recorded.

Also present in other papers' code

Of 4 samples lifted from this paper's linked repositories, 4 carry a function identity and 0 do not. Of the 4 distinct functions with an identity, 0 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 0 later) and 4 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.

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

In this paper, we attack a few-shot open-set recognition (FSOSR) problem, which is a combination of few-shot learning (FSL) and open-set recognition (OSR). It aims to quickly adapt a model to a given small set of labeled samples while rejecting unseen class samples. Since OSR requires rich data and FSL considers closed-set classification, existing OSR and FSL methods show poor performances in solving FSOSR problems. The previous FSOSR method follows the pseudo-unseen class sample-based methods, which collect pseudo-unseen samples from the other dataset or synthesize samples to model unseen class representations. However, this approach is heavily dependent on the composition of the pseudo samples. In this paper, we propose a novel unknown class sample detector, named SnaTCHer, that does not require pseudo-unseen samples. Based on the transformation consistency, our method measures the difference between the transformed prototypes and a modified prototype set. The modified set is composed by replacing a query feature and its predicted class prototype. SnaTCHer rejects samples with large differences to the transformed prototypes. Our method alters the unseen class distribution estimation problem to a relative feature transformation problem, independent of pseudo-unseen class samples. We investigate our SnaTCHer with various prototype transformation methods and observe that our method consistently improves unseen class sample detection performance without closed-set classification reduction.

For agents

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

get_harvested_code_for_paper("2103.01537")
get_code_for_paper("2103.01537")
have("2103.01537")

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

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

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

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

Connect an agent — have() is free.