SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2204.09222 · NeurIPS · 2022

K-LITE: Learning Transferable Visual Models with External Knowledge

Sheng Shen, Kurt Keutzer, Chunyuan Li, Jianfeng Gao, Zhe Gan, Trevor Darrell, Anna Rohrbach, Lu Yuan, Lijuan Wang, Jianwei Yang, Pengchuan Zhang, Ce Liu, and 2 more

arXiv · PDF · Open in the Atlas

Code that ran

5 of 10 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (3 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 1 violated it and 4 have no contract verdict; 0 failures of our instrument; 5 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/2204.09222.json · badge: /api/ran/2204.09222.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
microsoft/klite community
Papers with Code archive
5 ran · 5 no recorded run
FunctionStatusWhere it lives
PatchEmbed Ran
ran on a synthesized input · constructed an object; no result was computed
microsoft/klite/model/model.py
code served (permissive licence) · get_code("5913171a402effd1")
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, PatchEmbed: 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
from timm.models.layers import to_2tuple

torch.manual_seed(0)

# Define ARGS dict mapping all PatchEmbed.__init__ parameters to values
ARGS = {
    "img_size": 224,
    "patch_size": 4,
    "in_chans": 3,
    "embed_dim": 96,
    "norm_layer": nn.LayerNorm,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
timm, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type PatchEmbed — 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 PatchEmbed 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
PatchMerging Ran
ran on a synthesized input · constructed an object; no result was computed
microsoft/klite/model/model.py
code served (permissive licence) · get_code("89e08495ccdd55f4")
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, PatchMerging: 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
from torch import nn

torch.manual_seed(0)

# PatchMerging expects:
# - input_resolution: tuple of (H, W) where both are even
# - dim: int, number of input channels
# - norm_layer: nn.Module class (default nn.LayerNorm)
# - forward receives x of shape (B, H*W, C)

ARGS = {
    'input_resolution': (4, 6),  # H=4, W=6 (both even, distinct sizes)
    'dim': 8,                     # input channels
    'norm_layer': nn.LayerNorm,   # normalization layer class
}
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 PatchMerging — 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 PatchMerging 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
SwinTransformerBlock Ran
ran on a synthesized input
microsoft/klite/model/model.py
code served (permissive licence) · get_code("5a5551bec22c5f90")
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 Tensor, ndim 3, 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 numpy as np
from torch import nn
from timm.models.layers import DropPath, to_2tuple, trunc_normal_

class SwinTransformerBlock(nn.Module):
    def __init__(self, dim, input_resolution, num_heads, window_size=7, shift_size=0,
                 mlp_ratio=4., qkv_bias=True, qk_scale=None, drop=0., attn_drop=0.,
                 drop_path=0., act_layer=nn.GELU, norm_layer=nn.LayerNorm):
        super().__init__()
        self.dim = dim
        self.input_resolution = input_resolution
        self.num_heads = num_heads
        self.window_size = window_size
        self.shift_size = shift_size
        self.mlp_ratio = mlp_ratio
        if min(self.input_resolution) <= self.window_size:
            self.shift_size = 0
            self.window_size = min(self.input_resolution)
        assert 0 <= self.shift_size < self.window_size, "shift_size must in 0-window_size"

        self.norm1 = norm_layer(dim)
        self.attn = WindowAttention(
            dim, window_size=to_2tuple(self.window_size), num_heads=num_heads,
            qkv_bias=qkv_bias, qk_scale=qk_scale, attn_drop=attn_drop, proj_drop=drop)

        self.drop_path = DropPath(drop_path) if drop_path > 0. else nn.Identity()
        self.norm2 = norm_layer(dim)
        mlp_hidden_dim = int(dim * mlp_ratio)
        self.mlp = Mlp(in_features=dim, hidden_features=mlp_hidden_dim, act_layer=act_layer, drop=drop)

        if self.shift_size > 0:
            H, W = self.input_resolution
            img_mask = torch.zeros((1, H, W, 1))
            h_slices = (slice(0, -self.window_size),
                        slice(-self.window_size, -self.shift_size),
                        slice(-self.shift_size, None))
            w_slices = (slice(0, -self.window_size),
                        slice(-self.window_size, -self.shift_size),
                        slice(-self.shift_size, None))
            cnt = 0
            for h in h_slices:
                for w in w_slices:
                    img_mask[:, h, w, :] = cnt
                    cnt += 1

            mask_windows = window_partition(img_mask, self.window_size)
            mask_windows = mask_windows.view(-1, self.window_size * self.window_size)
            attn_mask = mask_windows.unsqueeze(1) - mask_windows.unsqueeze(2)
            attn_mask = attn_mask.masked_fill(attn_mask != 0, float(-100.0)).masked_fill(attn_mask == 0, float(0.0))
        else:
            attn_mask = None

        self.register_buffer("attn_mask", attn_mask)

    def forward(self, x):
        H, W = self.input_resolution
        B, L, C = x.shape
        assert L == H * W, "input feature has wrong size"

        shortcut = x
        x = self.norm1(x)
        x = x.view(B, H, W, C)

        if self.shift_size > 0:
            shifted_x = torch.roll(x, shifts=(-self.shift_size, -self.shift_size), dims=(1, 2))
        else:
            shifted_x = x

        x_windows = window_partition(shifted_x, self.window_size)
        x_windows = x_windows.view(-1, self.window_size * self.window_size, C)

        attn_windows = self.attn(x_windows, mask=self.attn_mask)

        attn_windows = attn_windows.view(-1, self.window_size, self.window_size, C)
        shifted_x = window_reverse(attn_windows, self.window_size, H, W)

        if self.shift_size > 0:
            x = torch.roll(shifted_x, shifts=(self.shift_size, self.shift_size), dims=(1, 2))
        else:
            x = shifted_x
        x = x.view(B, H * W, C)

        x = shortcut + self.drop_path(x)
        x = x + self.drop_path(self.mlp(self.norm2(x)))

        return x

def window_reverse(windows, window_size, H, W):
    B = int(windows.shape[0] / (H * W / window_size / window_size))
    x = windows.view(B, H // window_size, W // window_size, window_size, window_size, -1)
    x = x.permute(0, 1, 3, 2, 4, 5).contiguous().view(B, H, W, -1)
    return x

INIT_ARGS = {
    'dim': 4,
    'input_resolution': (6, 8),
    'num_heads': 2,
    'window_size': 2,
    'shift_size': 1,
    'mlp_ratio': 2.0,
    'qkv_bias': True,
    'qk_scale': None,
    'drop': 0.0,
    'attn_drop': 0.0,
    'drop_path': 0.0,
    'act_layer': nn.GELU,
    'norm_layer': nn.LayerNorm
}

ARGS = {
    'x': torch.randn(2, 6 * 8, 4)
}
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
Imports
numpy, timm, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 3, dtype family float — no output shape is stated: observe_signature.py observed this class with its constructor sizes canonicalised where it could, which the node does not record, so its shape is not stated as this setup block's
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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
WindowAttention Ran
ran on a synthesized input · constructed an object; no result was computed
microsoft/klite/model/model.py
code served (permissive licence) · get_code("44721c30a2563ec1")
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, WindowAttention: 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
from torch import nn

torch.manual_seed(0)

ARGS = {
    "dim": 64,
    "window_size": (4, 4),
    "num_heads": 4,
    "qkv_bias": True,
    "qk_scale": None,
    "attn_drop": 0.0,
    "proj_drop": 0.0,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
timm, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type WindowAttention — 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 WindowAttention 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
is_lang_encoder Ran
ran, violated the contract we drafted
microsoft/klite/model/model.py
code served (permissive licence) · get_code("253f375438a3b31d")
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 bool, ndim 0, dtype family float, shape () 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)

_lang_encoders = {}

ARGS = {
    "model_name": "bert"
}
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 bool, ndim 0, dtype family float, shape () — shape () 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
BasicLayer Not yet run
unverified (harvested, no recorded run)
microsoft/klite/model/model.py
code served (permissive licence) · get_code("30fb736aaa42b89d")
How it ran

no invocation recorded.

KLITEModel Not yet run
unverified (harvested, no recorded run)
microsoft/klite/model/model.py
code served (permissive licence) · get_code("96a6b788f6e04b42")
How it ran

no invocation recorded.

SwinTransformer Not yet run
unverified (harvested, no recorded run)
microsoft/klite/model/model.py
code served (permissive licence) · get_code("5817ae83cc9df84f")
How it ran

no invocation recorded.

build_tokenizer Not yet run
unverified (harvested, no recorded run)
microsoft/klite/model/model.py
code served (permissive licence) · get_code("d7ee228866431711")
How it ran

no invocation recorded.

lang_encoders Not yet run
unverified (harvested, no recorded run)
microsoft/klite/model/model.py
code served (permissive licence) · get_code("25812f971a96b8f8")
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, 9 are also present in other papers whose code we hold (5 with at least one paper dated earlier, 9 the same month, 5 later) and 1 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
WindowAttention
brick of this paper's assembly: helper
15 other papers
4 dated earlier, 1 the same month, 10 later · 5 only as an assembly brick
2103.14030 (2021-03)
Swin Transformer: Hierarchical Vision Transformer using Shifted Windows
2108.10257 (2021-08)
SwinIR: Image Restoration Using Swin Transformer
2203.13963 (2022-03)
Transformer-empowered Multi-scale Contextual Matching and Aggregation for Multi-contrast MRI Super-resolution
and 12 more not named here
PatchEmbed
brick of this paper's assembly: helper
9 other papers
2 dated earlier, 2 the same month, 5 later · 5 only as an assembly brick
2103.14030 (2021-03)
Swin Transformer: Hierarchical Vision Transformer using Shifted Windows
2203.15350 (2022-03)
End-to-End Transformer Based Model for Image Captioning
2204.03610 (2022-04)
Unified Contrastive Learning in Image-Text-Label Space
and 6 more not named here
BasicLayer
brick of this paper's assembly: helper
7 other papers
2 dated earlier, 1 the same month, 4 later · 2 only as an assembly brick
2103.14030 (2021-03)
Swin Transformer: Hierarchical Vision Transformer using Shifted Windows
2203.15350 (2022-03)
End-to-End Transformer Based Model for Image Captioning
2204.03610 (2022-04)
Unified Contrastive Learning in Image-Text-Label Space
and 4 more not named here
PatchMerging
brick of this paper's assembly: helper
7 other papers
2 dated earlier, 2 the same month, 3 later · 5 only as an assembly brick
2103.14030 (2021-03)
Swin Transformer: Hierarchical Vision Transformer using Shifted Windows
2203.15350 (2022-03)
End-to-End Transformer Based Model for Image Captioning
2204.03610 (2022-04)
Unified Contrastive Learning in Image-Text-Label Space
and 4 more not named here
SwinTransformerBlock
brick of this paper's assembly: helper
7 other papers
2 dated earlier, 1 the same month, 4 later · 2 only as an assembly brick
2103.14030 (2021-03)
Swin Transformer: Hierarchical Vision Transformer using Shifted Windows
2203.15350 (2022-03)
End-to-End Transformer Based Model for Image Captioning
2204.03610 (2022-04)
Unified Contrastive Learning in Image-Text-Label Space
and 4 more not named here
SwinTransformer
brick of this paper's assembly: helper
1 other paper
1 the same month · 1 only as an assembly brick
2204.03610 (2022-04)
Unified Contrastive Learning in Image-Text-Label Space
build_tokenizer
brick of this paper's assembly: helper
1 other paper
1 the same month · 1 only as an assembly brick
2204.03610 (2022-04)
Unified Contrastive Learning in Image-Text-Label Space
is_lang_encoder
brick of this paper's assembly: helper
1 other paper
1 the same month · 1 only as an assembly brick
2204.03610 (2022-04)
Unified Contrastive Learning in Image-Text-Label Space
lang_encoders
brick of this paper's assembly: helper
1 other paper
1 the same month · 1 only as an assembly brick
2204.03610 (2022-04)
Unified Contrastive Learning in Image-Text-Label Space

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

The new generation of state-of-the-art computer vision systems are trained from natural language supervision, ranging from simple object category names to descriptive captions. This form of supervision ensures high generality and usability of the learned visual models, due to the broad concept coverage achieved via largescale data collection process. Alternatively, we argue that learning with external knowledge is a promising way which leverages a much more structured source of supervision and offers sample efficiency. We propose K-LITE 1 , a simple strategy to leverage external knowledge for building transferable visual systems: In training, it enriches entities in text with WordNet and Wiktionary knowledge, leading to an efficient and scalable approach to learning image representations that uses knowledge about the visual concepts. In evaluation, the text is also augmented with external knowledge and then used to reference learned visual concepts (or describe new ones) to enable zero-shot and few-shot transfer of the pre-trained models. We study the performance of K-LITE on two important computer vision problems, image classification and object detection, benchmarking on 20 and 13 different existing datasets, respectively. The proposed knowledge-augmented models show significant improvement in transfer learning performance over existing methods. 2 * Equal Technical Contribution ♠ Project Lead 1 Knowledge-augmented Language Image Training and Evaluation 2 Our code is available at https://github.com/microsoft/klite.

For agents

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

get_harvested_code_for_paper("2204.09222")
get_code_for_paper("2204.09222")
have("2204.09222")

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

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

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

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

Connect an agent — have() is free.