| LSEPLoss |
Ran ran on a synthesized input |
junweiliang/multitrain/slowfast/models/losses.py code served (permissive licence) · get_code("ec4d0c57187accb7") How it ranRan 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 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
import torch.nn as nn
class LSEPLoss(nn.Module):
"""
# http://openaccess.thecvf.com/content_cvpr_2017/html/Li_Improving_Pairwise_Ranking_CVPR_2017_paper.html
"""
def __init__(self, reduction='mean'):
"""
Args:
reduction (str): specifies reduction to apply to the output. It can be
"mean" (default) or "none".
"""
super(LSEPLoss, self).__init__()
self.reduction = reduction
def forward(self, scores, labels):
mask = (labels.unsqueeze(1).expand(labels.size(0), labels.size(1), labels.size(1)) - labels.unsqueeze(2).expand(labels.size(0), labels.size(1), labels.size(1)) > 0).float()
loss = scores.unsqueeze(2).expand(labels.size(0), labels.size(1), labels.size(1)) - scores.unsqueeze(1).expand(labels.size(0), labels.size(1), labels.size(1))
loss = loss.exp().mul(mask).sum().add(1).log()
if self.reduction == 'mean':
return loss.mean()
elif self.reduction == 'none':
return loss
else:
raise NotImplementedError
INIT_ARGS = {
'reduction': 'mean'
}
ARGS = {
'scores': torch.randn(2, 4),
'labels': torch.randn(2, 4)
}
if __name__ == '__main__':
model = LSEPLoss(**INIT_ARGS)
output = model(**ARGS)
print(f"Output shape: {output.shape}")
print(f"Output: {output}")
- Setup block drafted by
- a language model, class construct-then-call prompt, model not recorded
- 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 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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
|
| MeanAbsoluteError |
Ran ran on a synthesized input |
junweiliang/multitrain/slowfast/models/losses.py code served (permissive licence) · get_code("0dac89749d6d9308") How it ranRan 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 0, 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
import torch.nn.functional as F
class MeanAbsoluteError(nn.Module):
"""
mean absolute error loss, it is said to be more robust to label noise compared
to CE loss
"""
def __init__(self, reduction='mean'):
"""
Args:
reduction (str): specifies reduction to apply to the output. It can be
"mean" (default) or "none".
"""
super(MeanAbsoluteError, self).__init__()
self.reduction = reduction
def forward(self, x, y):
pred = F.softmax(x, dim=-1)
loss = 1.0 - torch.sum(y * pred, dim=-1)
if self.reduction == 'mean':
return loss.mean()
elif self.reduction == 'none':
return loss
else:
raise NotImplementedError
INIT_ARGS = {
'reduction': 'mean'
}
ARGS = {
'x': torch.randn(2, 4),
'y': torch.softmax(torch.randn(2, 4), dim=-1)
}
if __name__ == '__main__':
model = MeanAbsoluteError(**INIT_ARGS)
output = model(**ARGS)
print(f"Output: {output}")
print(f"Output shape: {output.shape}")
- Setup block drafted by
- a language model, class construct-then-call prompt, model not recorded
- 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 0, 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)
|
| NCEandRCE |
Ran ran on a synthesized input |
junweiliang/multitrain/slowfast/models/losses.py code served (permissive licence) · get_code("038b53347cdfe89b") How it ranRan 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 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
import torch.nn as nn
import torch.nn.functional as F
class NormalizedSoftTargetCrossEntropy(nn.Module):
"""
Normalized Cross entropy loss with soft target. For MixUp train
"""
def __init__(self, reduction='mean'):
"""
Args:
reduction (str): specifies reduction to apply to the output. It can be
"mean" (default) or "none".
"""
super(NormalizedSoftTargetCrossEntropy, self).__init__()
self.reduction = reduction
def forward(self, x, y):
pred = F.log_softmax(x, dim=-1)
loss = -torch.sum(y * pred, dim=-1) / -pred.sum(dim=-1)
if self.reduction == 'mean':
return loss.mean()
elif self.reduction == 'none':
return loss
else:
raise NotImplementedError
class ReverseSoftTargetCrossEntropy(nn.Module):
"""
Reverse Cross entropy loss with soft target. For MixUp train
"""
def __init__(self, reduction='mean'):
"""
Args:
reduction (str): specifies reduction to apply to the output. It can be
"mean" (default) or "none".
"""
super(ReverseSoftTargetCrossEntropy, self).__init__()
self.reduction = reduction
def forward(self, x, y):
pred = F.softmax(x, dim=-1)
pred = torch.clamp(pred, min=1e-07, max=1.0)
y = torch.clamp(y, min=0.0001, max=1.0)
y = torch.log(y)
loss = -torch.sum(y * pred, dim=-1)
if self.reduction == 'mean':
return loss.mean()
elif self.reduction == 'none':
return loss
else:
raise NotImplementedError
class NCEandRCE(nn.Module):
def __init__(self, alpha=1.0, beta=1.0, reduction='mean'):
super(NCEandRCE, self).__init__()
self.alpha = alpha
self.beta = beta
self.nce = NormalizedSoftTargetCrossEntropy(reduction=reduction)
self.rce = ReverseSoftTargetCrossEntropy(reduction=reduction)
def forward(self, pred, labels):
return self.alpha * self.nce(pred, labels) + self.beta * self.rce(pred, labels)
INIT_ARGS = {
'alpha': 0.5,
'beta': 0.7,
'reduction': 'mean'
}
ARGS = {
'pred': torch.randn(2, 4),
'labels': torch.softmax(torch.randn(2, 4), dim=-1)
}
if __name__ == '__main__':
model = NCEandRCE(**INIT_ARGS)
output = model(**ARGS)
print(f"Output: {output}")
print(f"Output shape: {output.shape}")
- Setup block drafted by
- a language model, class construct-then-call prompt, model not recorded
- 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 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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
|
| NormalizedSoftTargetCrossEntropy |
Ran ran on a synthesized input |
junweiliang/multitrain/slowfast/models/losses.py code served (permissive licence) · get_code("5007808e58a0cf6a") How it ranRan 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 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
import torch.nn as nn
import torch.nn.functional as F
class NormalizedSoftTargetCrossEntropy(nn.Module):
"""
Normalized Cross entropy loss with soft target. For MixUp train
"""
def __init__(self, reduction='mean'):
"""
Args:
reduction (str): specifies reduction to apply to the output. It can be
"mean" (default) or "none".
"""
super(NormalizedSoftTargetCrossEntropy, self).__init__()
self.reduction = reduction
def forward(self, x, y):
pred = F.log_softmax(x, dim=-1)
loss = -torch.sum(y * pred, dim=-1) / -pred.sum(dim=-1)
if self.reduction == 'mean':
return loss.mean()
elif self.reduction == 'none':
return loss
else:
raise NotImplementedError
INIT_ARGS = {
'reduction': 'mean'
}
ARGS = {
'x': torch.randn(2, 4),
'y': torch.softmax(torch.randn(2, 4), dim=-1)
}
if __name__ == '__main__':
model = NormalizedSoftTargetCrossEntropy(**INIT_ARGS)
output = model(**ARGS)
print(f"Output shape: {output.shape}")
print(f"Output value: {output}")
model_none = NormalizedSoftTargetCrossEntropy(reduction='none')
output_none = model_none(**ARGS)
print(f"Output (reduction='none') shape: {output_none.shape}")
print(f"Output (reduction='none') value: {output_none}")
- Setup block drafted by
- a language model, class construct-then-call prompt, model not recorded
- 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 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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
|
| ReverseSoftTargetCrossEntropy |
Ran ran on a synthesized input |
junweiliang/multitrain/slowfast/models/losses.py code served (permissive licence) · get_code("95fb2d4c767dc202") How it ranRan 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 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
import torch.nn as nn
import torch.nn.functional as F
class ReverseSoftTargetCrossEntropy(nn.Module):
"""
Reverse Cross entropy loss with soft target. For MixUp train
"""
def __init__(self, reduction='mean'):
"""
Args:
reduction (str): specifies reduction to apply to the output. It can be
"mean" (default) or "none".
"""
super(ReverseSoftTargetCrossEntropy, self).__init__()
self.reduction = reduction
def forward(self, x, y):
pred = F.softmax(x, dim=-1)
pred = torch.clamp(pred, min=1e-07, max=1.0)
y = torch.clamp(y, min=0.0001, max=1.0)
y = torch.log(y)
loss = -torch.sum(y * pred, dim=-1)
if self.reduction == 'mean':
return loss.mean()
elif self.reduction == 'none':
return loss
else:
raise NotImplementedError
INIT_ARGS = {
'reduction': 'mean'
}
ARGS = {
'x': torch.randn(2, 4),
'y': torch.softmax(torch.randn(2, 4), dim=-1)
}
if __name__ == '__main__':
model = ReverseSoftTargetCrossEntropy(**INIT_ARGS)
output = model(**ARGS)
print("Output:", output)
print("Output shape:", output.shape)
- Setup block drafted by
- a language model, class construct-then-call prompt, model not recorded
- 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 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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
|
| SoftTargetCrossEntropy |
Ran ran on a synthesized input |
junweiliang/multitrain/slowfast/models/losses.py code served (permissive licence) · get_code("666787bd3939df7c") How it ranRan 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 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
import torch.nn as nn
import torch.nn.functional as F
class SoftTargetCrossEntropy(nn.Module):
"""
Cross entropy loss with soft target. For MixUp train
"""
def __init__(self, reduction='mean'):
"""
Args:
reduction (str): specifies reduction to apply to the output. It can be
"mean" (default) or "none".
"""
super(SoftTargetCrossEntropy, self).__init__()
self.reduction = reduction
def forward(self, x, y):
loss = torch.sum(-y * F.log_softmax(x, dim=-1), dim=-1)
if self.reduction == 'mean':
return loss.mean()
elif self.reduction == 'none':
return loss
else:
raise NotImplementedError
INIT_ARGS = {
'reduction': 'mean'
}
ARGS = {
'x': torch.randn(2, 4),
'y': torch.softmax(torch.randn(2, 4), dim=-1)
}
if __name__ == '__main__':
loss_fn = SoftTargetCrossEntropy(**INIT_ARGS)
output = loss_fn(**ARGS)
print(f"Output shape: {output.shape}")
print(f"Output value: {output}")
- Setup block drafted by
- a language model, class construct-then-call prompt, model not recorded
- 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 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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
|
| read_val_data |
Ran ran; our contract draft was wrong, not the code |
JunweiLiang/MultiTrain/tools/train_net.py code served (permissive licence) · get_code("39a9b846b179205b") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1) 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 os
import pickle
import tempfile
# Create a temporary directory for the test
temp_dir = tempfile.mkdtemp()
# Create a sample val_record dictionary
val_record = {
'loss': {0: 0.5, 1: 0.4, 2: 0.3},
'accuracy': {0: 0.7, 1: 0.8, 2: 0.85}
}
# Save the val_record to a pickle file
save_file = os.path.join(temp_dir, 'val_record.pkl')
with open(save_file, 'wb') as f:
pickle.dump(val_record, f)
# Create a config object with OUTPUT_DIR attribute
class Config:
def __init__(self, output_dir):
self.OUTPUT_DIR = output_dir
cfg = Config(temp_dir)
ARGS = {
'cfg': cfg
}
- Setup block drafted by
- a language model, Claude Haiku 4.5, prompt python_fixture_v1
- 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 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
|
| MultiHeadLoss |
Not yet run unverified (harvested, no recorded run) |
junweiliang/multitrain/slowfast/models/losses.py code served (permissive licence) · get_code("40418acd5604e86d") How it ran |