SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2203.10833 · CVPR · 2022

Hyperbolic Vision Transformers: Combining Improvements in Metric Learning

Nicu Sebe, Ivan Oseledets, Aleksandr Ermolov, Valentin Khrulkov, Leyla Skoltech

arXiv · PDF · Open in the Atlas

Code that ran

4 of 6 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 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; 3 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/2203.10833.json · badge: /api/ran/2203.10833.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
htdt/hyp_metric marked official in Papers with Code
Papers with Code archive
4 ran · 2 no recorded run
FunctionStatusWhere it lives
HypLinear Ran
ran on a synthesized input
htdt/hyp_metric/hyptorch/nn.py
code served (permissive licence) · get_code("ef850ea4ebf99283")
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 2, 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 math

# The class definition is incomplete in the provided code (ends with "s")
# Completing it based on the pattern:

class Artanh(torch.autograd.Function):

    @staticmethod
    def forward(ctx, x):
        x = x.clamp(-1 + 1e-05, 1 - 1e-05)
        ctx.save_for_backward(x)
        res = torch.log_(1 + x).sub_(torch.log_(1 - x)).mul_(0.5)
        return res

    @staticmethod
    def backward(ctx, grad_output):
        input, = ctx.saved_tensors
        return grad_output / (1 - input ** 2)

def artanh(x):
    return Artanh.apply(x)

def tanh(x, clamp=15):
    return x.clamp(-clamp, clamp).tanh()

def _project(x, c):
    norm = torch.clamp_min(x.norm(dim=-1, keepdim=True, p=2), 1e-05)
    maxnorm = (1 - 0.001) / c ** 0.5
    cond = norm > maxnorm
    projected = x / norm * maxnorm
    return torch.where(cond, projected, x)

def _mobius_matvec(m, x, c):
    x_norm = torch.clamp_min(x.norm(dim=-1, keepdim=True, p=2), 1e-05)
    sqrt_c = c ** 0.5
    mx = x @ m.transpose(-1, -2)
    mx_norm = mx.norm(dim=-1, keepdim=True, p=2)
    res_c = tanh(mx_norm / x_norm * artanh(sqrt_c * x_norm)) * mx / (mx_norm * sqrt_c)
    cond = (mx == 0).prod(-1, keepdim=True, dtype=torch.uint8)
    res_0 = torch.zeros(1, dtype=res_c.dtype, device=res_c.device)
    res = torch.where(cond, res_0, res_c)
    return _project(res, c)

class HypLinear(nn.Module):

    def __init__(self, in_features, out_features, c, bias=True):
        super(HypLinear, self).__init__()
        self.in_features = in_features
        self.out_features = out_features
        self.c = c
        self.weight = nn.Parameter(torch.Tensor(out_features, in_features))
        if bias:
            self.bias = nn.Parameter(torch.Tensor(out_features))
        else:
            self.bias = None
        self.reset_parameters()

    def reset_parameters(self):
        nn.init.xavier_uniform_(self.weight)
        if self.bias is not None:
            nn.init.constant_(self.bias, 0)

    def forward(self, x):
        mv = _mobius_matvec(self.weight, x, self.c)
        if self.bias is not None:
            bias = self.bias.view(1, -1)
            from torch import as_tensor
            c_tensor = as_tensor(self.c).type_as(mv)
            
            def _mobius_add(x, y, c):
                x2 = x.pow(2).sum(dim=-1, keepdim=True)
                y2 = y.pow(2).sum(dim=-1, keepdim=True)
                xy = (x * y).sum(dim=-1, keepdim=True)
                num = (1 + 2 * c * xy + c * y2) * x + (1 - c * x2) * y
                denom = 1 + 2 * c * xy + c ** 2 * x2 * y2
                return num / (denom + 1e-05)
            
            mv = _mobius_add(mv, bias, c_tensor)
        return mv


INIT_ARGS = {
    'in_features': 4,
    'out_features': 3,
    'c': 1.0,
    'bias': True
}

ARGS = {
    'x': torch.randn(2, 4)
}

if __name__ == '__main__':
    model = HypLinear(**INIT_ARGS)
    output = model(**ARGS)
    print("Output shape:", output.shape)
    print("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 2, 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)
artanh Ran
ran; our contract draft was wrong, not the code
htdt/hyp_metric/hyptorch/nn.py
code served (permissive licence) · get_code("daf212010121f13d")
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) and returned Tensor, ndim 2, dtype family float, shape (2, 4) 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 artanh function takes a single parameter x which should be a tensor
# The function clamps x to the range [-1 + 1e-05, 1 - 1e-05]
# and computes the inverse hyperbolic tangent

# Create a small tensor with values in the valid range for artanh
x = torch.randn(2, 4) * 0.5  # Scale down to keep values in reasonable range for artanh

ARGS = {
    "x": x
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
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 (2, 4) — shape (2, 4) 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
mobius_add Ran
ran; our contract draft was wrong, not the code
htdt/hyp_metric/hyptorch/nn.py
code served (permissive licence) · get_code("d0bcd7cd164a4987")
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) and returned Tensor, ndim 2, dtype family float, shape (2, 4) 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 small tensors for points on the Poincare ball
# x and y should have shape (batch_size, embedding_dim)
x = torch.randn(2, 4)
y = torch.randn(2, 4)

# Curvature parameter - can be float or tensor
c = 1.0

ARGS = {
    "x": x,
    "y": y,
    "c": c,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
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 (2, 4) — shape (2, 4) 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
mobius_matvec Ran
ran; our contract draft was wrong, not the code
htdt/hyp_metric/hyptorch/nn.py
code served (permissive licence) · get_code("ea6109a03ce10561")
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 (2, 4) 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

torch.manual_seed(0)

# Create a small matrix for the 'm' parameter
# The function uses m.transpose(-1, -2), so we need a 2D matrix
# Shape: (4, 3) - distinct dimensions to probe later
m = torch.randn(4, 3)

# Create a small point on the Poincare ball for the 'x' parameter
# The function uses x.norm(dim=-1, keepdim=True, p=2) and x @ m.transpose(-1, -2)
# So x should have shape (batch, feature_dim) where feature_dim matches m's second dimension
# Shape: (2, 3) - batch size 2, feature dimension 3
x = torch.randn(2, 3) * 0.1  # Scale down to keep it within valid Poincare ball region

# The 'c' parameter is optional with default 1.0
c = 1.0

ARGS = {
    "m": m,
    "x": x,
    "c": c
}
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 (2, 4) — shape (2, 4) 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
Artanh Not yet run
unverified (harvested, no recorded run)
htdt/hyp_metric/hyptorch/nn.py
code served (permissive licence) · get_code("7b7b467a36348c8b")
How it ran

no invocation recorded.

_mobius_matvec Not yet run
unverified (harvested, no recorded run)
htdt/hyp_metric/hyptorch/nn.py
code served (permissive licence) · get_code("93968601ef4b16be")
How it ran

no invocation recorded.

Also present in other papers' code

Of 6 samples lifted from this paper's linked repositories, 6 carry a function identity and 0 do not. Of the 6 distinct functions with an identity, 1 are also present in other papers whose code we hold (1 with at least one paper dated earlier, 0 the same month, 1 later) and 5 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
artanh
brick of this paper's assembly: helper
5 other papers
3 dated earlier, 2 later · 1 only as an assembly brick
1904.02239 (2019-04)
Hyperbolic Image Embeddings
2005.00545 (2020-05)
Low-Dimensional Hyperbolic Knowledge Graph Embeddings
2108.02390 (2021-08)
Fuzzy Logic Based Logical Query Answering on Knowledge Graphs
and 2 more not named here

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

Metric learning aims to learn a highly discriminative model encouraging the embeddings of similar classes to be close in the chosen metrics and pushed apart for dissimilar ones. The common recipe is to use an encoder to extract embeddings and a distance-based loss function to match the representations -usually, the Euclidean distance is utilized. An emerging interest in learning hyperbolic data embeddings suggests that hyperbolic geometry can be beneficial for natural data. Following this line of work, we propose a new hyperbolic-based model for metric learning. At the core of our method is a vision transformer with output embeddings mapped to hyperbolic space. These embeddings are directly optimized using modified pairwise cross-entropy loss. We evaluate the proposed model with six different formulations on four datasets achieving the new state-of-the-art performance. The source code is available at https://github.com/htdt/hyp_metric.

For agents

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

get_harvested_code_for_paper("2203.10833")
get_code_for_paper("2203.10833")
have("2203.10833")

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

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

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

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

Connect an agent — have() is free.