SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2205.01917 · 2022

CoCa: Contrastive Captioners are Image-Text Foundation Models

Jiahui Yu, Yonghui Wu, Vijay Vasudevan, Zirui Wang, Mojtaba Seyedhosseini, Legg Yeung

arXiv · PDF · Open in the Atlas

Code that ran

10 of 17 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (5 of them constructed an object rather than computing a result; 2 honoured the contract we drafted, 0 violated it and 6 have no contract verdict; 2 failures of our instrument; 7 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/2205.01917.json · badge: /api/ran/2205.01917.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
facebookresearch/multimodal community
Papers with Code archive
7 ran · 6 no recorded run
Chaolei98/FreeZAD community (classifier label)
classifier basis not recorded on the link
3 ran · 1 no recorded run
FunctionStatusWhere it lives
CoCaTextEmbeddings Ran
ran on a synthesized input · constructed an object; no result was computed
facebookresearch/multimodal/torchmultimodal/models/coca/coca_model.py
code served (permissive licence) · get_code("38c836510c2b097d")
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, CoCaTextEmbeddings: 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)

# Define ARGS dict with all parameters for CoCaTextEmbeddings
ARGS = {
    "vocab_size": 100,
    "num_positions": 17,
    "embedding_dim": 4,
    "pad_idx": 0,
    "embed_cls": True,
}
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 CoCaTextEmbeddings — 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 CoCaTextEmbeddings 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
Fp32LayerNorm Ran
ran on a synthesized input
facebookresearch/multimodal/torchmultimodal/models/coca/coca_model.py
code served (permissive licence) · get_code("1851c02d87765a1f")
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

# Fp32LayerNorm.__init__ takes *args and **kwargs which are passed to nn.LayerNorm
# nn.LayerNorm.__init__ signature: normalized_shape, eps=1e-05, elementwise_affine=True
# We need to provide normalized_shape (required) and optionally eps and elementwise_affine

INIT_ARGS = {
    'normalized_shape': (6,),  # Can be int or tuple/list of ints
    'eps': 1e-5,
    'elementwise_affine': True
}

# The forward method takes x: Tensor
# x should have shape (..., *normalized_shape)
# Since normalized_shape is (6,), x should end with dimension 6

ARGS = {
    'x': torch.randn(2, 4, 6)  # batch=2, seq_len=4, features=6
}
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 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)
MHAWithCacheOutput Ran
ran on a synthesized input · constructed an object; no result was computed
facebookresearch/multimodal/torchmultimodal/models/coca/coca_model.py
code served (permissive licence) · get_code("c3bf9823eb334b94")
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, MHAWithCacheOutput: 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, Tensor
from typing import Tuple

torch.manual_seed(0)

# MHAWithCacheOutput is a NamedTuple with two fields:
# 1. attn_output: Tensor
# 2. past_key_value: Tuple[Tensor, Tensor]

# Create small tensors with distinct dimensions
attn_output = torch.randn(2, 4, 8)  # batch=2, seq_len=4, hidden=8

# past_key_value is a tuple of two tensors (key and value caches)
past_key = torch.randn(2, 3, 4)     # batch=2, num_heads=3, head_dim=4
past_value = torch.randn(2, 3, 4)   # batch=2, num_heads=3, head_dim=4
past_key_value = (past_key, past_value)

ARGS = {
    "attn_output": attn_output,
    "past_key_value": past_key_value,
}
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 MHAWithCacheOutput — the run constructed an instance of its own class and did not call it; no shape 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
MLP Ran
ran on a synthesized input · constructed an object; no result was computed
facebookresearch/multimodal/torchmultimodal/models/coca/coca_model.py
code served (permissive licence) · get_code("69bbd7902f886836")
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, MLP: 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
from functools import partial

torch.manual_seed(0)

ARGS = {
    "in_dim": 4,
    "out_dim": 3,
    "hidden_dims": [8, 6],
    "dropout": 0.5,
    "activation": nn.ReLU,
    "normalization": nn.BatchNorm1d,
}
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 MLP — 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 MLP 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
MultimodalOutput Ran
ran on a synthesized input · constructed an object; no result was computed
facebookresearch/multimodal/torchmultimodal/models/coca/coca_model.py
code served (permissive licence) · get_code("c48e25a9b1ad8b20")
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, MultimodalOutput: 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, Tensor
from typing import Optional

torch.manual_seed(0)

# Create small tensors for the MultimodalOutput
image_pooled_output = torch.randn(2, 4)
text_pooled_output = torch.randn(2, 3)
multimodal_embeddings = torch.randn(2, 5, 4)
multimodal_pooled_embeddings = torch.randn(2, 6)

ARGS = {
    "image_pooled_output": image_pooled_output,
    "text_pooled_output": text_pooled_output,
    "multimodal_embeddings": multimodal_embeddings,
    "multimodal_pooled_embeddings": multimodal_pooled_embeddings,
}
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 MultimodalOutput — the run constructed an instance of its own class and did not call it; no shape 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
TransformerOutput Ran
ran on a synthesized input · constructed an object; no result was computed
facebookresearch/multimodal/torchmultimodal/models/coca/coca_model.py
code served (permissive licence) · get_code("16907aa066126740")
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, TransformerOutput: 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 typing import NamedTuple, Optional, Tuple, List

torch.manual_seed(0)

# Create tiny tensors with distinct dimensions
last_hidden_state = torch.randn(2, 4, 8)  # batch=2, seq_len=4, hidden_dim=8
pooler_output = torch.randn(2, 8)  # batch=2, pooled_dim=8
hidden_states = [torch.randn(2, 4, 8), torch.randn(2, 4, 8)]  # list of 2 hidden state tensors
attentions = [torch.randn(2, 3, 4, 4), torch.randn(2, 3, 4, 4)]  # list of attention tensors with num_heads=3
image_labels = torch.randint(0, 10, (2,))  # batch=2, label values
current_key_values = [
    (torch.randn(2, 3, 4, 5), torch.randn(2, 3, 4, 5)),  # (key, value) tuples for first layer
    (torch.randn(2, 3, 4, 5), torch.randn(2, 3, 4, 5)),  # (key, value) tuples for second layer
]

ARGS = {
    "last_hidden_state": last_hidden_state,
    "pooler_output": pooler_output,
    "hidden_states": hidden_states,
    "attentions": attentions,
    "image_labels": image_labels,
    "current_key_values": current_key_values,
}
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 TransformerOutput — the run constructed an instance of its own class and did not call it; no shape 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
compute_average_precision_detection Ran
ran; our contract draft was wrong, not the code
Chaolei98/FreeZAD/evaluate.py
code served (permissive licence) · get_code("320499e20591d89f")
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 numpy as np
import pandas as pd

# Create ground truth dataframe with required fields
ground_truth = pd.DataFrame({
    'video-id': ['vid1', 'vid1', 'vid2', 'vid2'],
    't-start': [0.5, 5.0, 1.0, 10.0],
    't-end': [2.5, 7.0, 3.5, 12.0]
})

# Create prediction dataframe with required fields
prediction = pd.DataFrame({
    'video-id': ['vid1', 'vid1', 'vid2', 'vid2'],
    't-start': [0.6, 5.1, 1.1, 10.1],
    't-end': [2.4, 6.9, 3.4, 11.9],
    'score': [0.95, 0.87, 0.92, 0.85]
})

# Create tiou thresholds
tiou_thresholds = np.array([0.5, 0.75, 0.95])

ARGS = {
    'ground_truth': ground_truth,
    'prediction': prediction,
    'tiou_thresholds': tiou_thresholds
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, pandas — 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
get_causal_attention_mask Ran
ran, honoured the contract we drafted
facebookresearch/multimodal/torchmultimodal/models/coca/coca_model.py
code served (permissive licence) · get_code("e35be5f71f1604be")
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 Tensor, ndim 2, dtype family float, shape (5, 3) 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
from torch import nn, Tensor

torch.manual_seed(0)

ARGS = {
    "tgt_seq_len": 5,
    "src_seq_len": 3,
}
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 Tensor, ndim 2, dtype family float, shape (5, 3) — shape (5, 3) 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
interpolated_prec_rec Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
Chaolei98/FreeZAD/evaluate.py
pointer only (licence: MIT); the stored copy get_code serves, from benedettaliberatori/t3al, is pointer only (licence: NONE) · get_code("1fc3d3455e5edcbb")
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 benedettaliberatori/t3al, 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.

segment_iou Ran
ran, honoured the contract we drafted
Chaolei98/FreeZAD/evaluate.py
pointer only (licence: MIT); the stored copy get_code serves, from Ontheway361/BSN_pytorch, is pointer only (licence: NONE) · get_code("d0744a2fe3151508")
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 Ontheway361/BSN_pytorch, 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.

CoCaModel Not yet run
unverified (harvested, no recorded run)
facebookresearch/multimodal/torchmultimodal/models/coca/coca_model.py
code served (permissive licence) · get_code("c3f20e8434033e06")
How it ran

no invocation recorded.

CoCaMultimodalDecoder Not yet run
unverified (harvested, no recorded run)
facebookresearch/multimodal/torchmultimodal/models/coca/coca_model.py
code served (permissive licence) · get_code("d39521c69dad724c")
How it ran

no invocation recorded.

CoCaTextDecoder Not yet run
unverified (harvested, no recorded run)
facebookresearch/multimodal/torchmultimodal/models/coca/coca_model.py
code served (permissive licence) · get_code("378d7fee25d36766")
How it ran

no invocation recorded.

MultiHeadAttentionWithCache Not yet run
unverified (harvested, no recorded run)
facebookresearch/multimodal/torchmultimodal/models/coca/coca_model.py
code served (permissive licence) · get_code("a73d62315a5ca5ca")
How it ran

no invocation recorded.

TransformerDecoder Not yet run
unverified (harvested, no recorded run)
facebookresearch/multimodal/torchmultimodal/models/coca/coca_model.py
code served (permissive licence) · get_code("a241668983092d20")
How it ran

no invocation recorded.

TransformerDecoderLayer Not yet run
unverified (harvested, no recorded run)
facebookresearch/multimodal/torchmultimodal/models/coca/coca_model.py
code served (permissive licence) · get_code("3624eeb428e322e8")
How it ran

no invocation recorded.

get_video_info Not yet run
unverified (harvested, no recorded run)
Chaolei98/FreeZAD/extract_features.py
code served (permissive licence) · get_code("f6224c8305205872")
How it ran

no invocation recorded.

Also present in other papers' code

Of 17 samples lifted from this paper's linked repositories, 17 carry a function identity and 0 do not. Of the 17 distinct functions with an identity, 6 are also present in other papers whose code we hold (3 with at least one paper dated earlier, 0 the same month, 6 later) and 11 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
interpolated_prec_rec 13 other papers
7 dated earlier, 5 later, 1 same year, order not determinable
1804.05113 (2018-04)
Multilevel Language and Vision Integration for Text-to-Clip Retrieval
1806.02964 (2018-06)
BSN: Boundary Sensitive Network for Temporal Action Proposal Generation
1907.09702 (2019-07)
BMN: Boundary-Matching Network for Temporal Action Proposal Generation
and 10 more not named here
segment_iou 13 other papers
7 dated earlier, 5 later, 1 same year, order not determinable
1804.05113 (2018-04)
Multilevel Language and Vision Integration for Text-to-Clip Retrieval
1806.02964 (2018-06)
BSN: Boundary Sensitive Network for Temporal Action Proposal Generation
1907.09702 (2019-07)
BMN: Boundary-Matching Network for Temporal Action Proposal Generation
and 10 more not named here
TransformerOutput
brick of this paper's assembly: helper
3 other papers
1 dated earlier, 2 later
2111.06377 (2021-11)
Masked Autoencoders Are Scalable Vision Learners
2207.06405 (2022-07)
Masked Autoencoders that Listen
2301.12597 (2023-01)
BLIP-2: Bootstrapping Language-Image Pre-training with Frozen Image Encoders and Large Language Models
Fp32LayerNorm
brick of this paper's assembly: helper
1 other paper
1 later · 1 only as an assembly brick
2207.06405 (2022-07)
Masked Autoencoders that Listen
MLP
brick of this paper's assembly: helper
1 other paper
1 later
2207.06405 (2022-07)
Masked Autoencoders that Listen
compute_average_precision_detection 1 other paper
1 later
2404.05426 (2024-04)
Test-Time Zero-Shot Temporal Action Localization

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

Exploring large-scale pretrained foundation models is of significant interest in computer vision because these models can be quickly transferred to many downstream tasks. This paper presents Contrastive Captioner (CoCa), a minimalist design to pretrain an image-text encoder-decoder foundation model jointly with contrastive loss and captioning loss, thereby subsuming model capabilities from contrastive approaches like CLIP and generative methods like SimVLM. In contrast to standard encoder-decoder transformers where all decoder layers attend to encoder outputs, CoCa omits cross-attention in the first half of decoder layers to encode unimodal text representations, and cascades the remaining decoder layers which cross-attend to the image encoder for multimodal image-text representations. We apply a contrastive loss between unimodal image and text embeddings, in addition to a captioning loss on the multimodal decoder outputs which predicts text tokens autoregressively. By sharing the same computational graph, the two training objectives are computed efficiently with minimal overhead. CoCa is pretrained end-to-end and from scratch on both web-scale alt-text data and annotated images by treating all labels simply as text, seamlessly unifying natural language supervision for representation learning. Empirically, CoCa achieves state-of-theart performance with zero-shot transfer or minimal task-specific adaptation on a broad range of downstream tasks, spanning visual recognition (ImageNet, Kinetics-400/600/700, Moments-in-Time), crossmodal retrieval (MSCOCO, Flickr30K, MSR-VTT), multimodal understanding (VQA, SNLI-VE, NLVR2), and image captioning (MSCOCO, NoCaps). Notably on ImageNet classification, CoCa obtains 86.3% zero-shot top-1 accuracy, 90.6% with a frozen encoder and learned classification head, and new state-of-the-art 91.0% top-1 accuracy on ImageNet with a finetuned encoder.

For agents

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

get_harvested_code_for_paper("2205.01917")
get_code_for_paper("2205.01917")
have("2205.01917")

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

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

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

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

Connect an agent — have() is free.