SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2207.04873 · ECCV · 2022

Hierarchical Average Precision Training for Pertinent Image Retrieval

Nicolas Thome, Elias Ramzi, Nicolas Audebert, Clément Rambour, Xavier Bitot

arXiv · PDF · Open in the Atlas

Code that ran

6 of 9 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; 4 honoured the contract we drafted, 0 violated it and 1 has no contract verdict; 1 failure of our instrument; 3 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/2207.04873.json · badge: /api/ran/2207.04873.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
elias-ramzi/HAPPIER community
Papers with Code archive
6 ran · 3 no recorded run
FunctionStatusWhere it lives
SmoothRankHAP Ran
ran on a synthesized input · constructed an object; no result was computed
elias-ramzi/HAPPIER/happier/losses/hap_loss.py
code served (permissive licence) · get_code("df2ae1b21d4b22e7")
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, SmoothRankHAP: the run constructed the object and did not call it, so no result was computed. The image it ran in was not recorded. The code mentions cuda, and the harness aliases cuda to the CPU for every sample; whether this run needed that is 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

torch.manual_seed(0)

# Create mock lib module with required functions
class MockLib:
    class LOGGER:
        @staticmethod
        def warning(msg):
            pass
    
    @staticmethod
    def create_label_matrix(labels, ref_labels, hierarchy_level='MULTI', dtype=torch.long):
        # Simple mock: return a binary matrix indicating label matches
        batch_size = labels.size(0)
        ref_size = ref_labels.size(0)
        matrix = torch.zeros(batch_size, ref_size, dtype=dtype)
        for i in range(batch_size):
            for j in range(ref_size):
                if torch.equal(labels[i], ref_labels[j]):
                    matrix[i, j] = 1
        return matrix

import sys
from types import ModuleType
lib = MockLib()
sys.modules['lib'] = ModuleType('lib')
sys.modules['lib'].create_label_matrix = MockLib.create_label_matrix
sys.modules['lib'].LOGGER = MockLib.LOGGER

# Create mock rank and hrank approximation functions
class RankApproximation(nn.Module):
    def __init__(self):
        super().__init__()
    
    def forward(self, sim_diff, target=None, general=False):
        # Return a tensor of same shape as sim_diff with values between 0 and 1
        return torch.sigmoid(sim_diff)

class HRankApproximation(nn.Module):
    def __init__(self):
        super().__init__()
    
    def forward(self, sim_diff, target=None, general=False):
        # Return a tensor of same shape as sim_diff with values between 0 and 1
        return torch.sigmoid(sim_diff) * 0.5

# Create mock relevance function
def relevance_fn(target):
    # Input: target matrix of shape (batch, ref_size)
    # Output: relevance scores
    return torch.ones_like(target, dtype=torch.float32)

# Create small tensors
batch_size = 2
embedding_dim = 4
ref_size = 3
label_dim = 2

embeddings = torch.randn(batch_size, embedding_dim)
labels = torch.randint(0, 5, (batch_size, label_dim))
ref_embeddings = torch.randn(ref_size, embedding_dim)
ref_labels = torch.randint(0, 5, (ref_size, label_dim))

ARGS = {
    'rank_approximation': RankApproximation(),
    'hrank_approximation': HRankApproximation(),
    'hierarchy_level': 'MULTI',
    'return_type': '1-mHAP',
    'reduce_type': 'mean',
    'stop_grad': False,
}
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 SmoothRankHAP — 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 SmoothRankHAP 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
avg_non_zero_reducer Ran
ran, honoured the contract we drafted
elias-ramzi/HAPPIER/happier/losses/hap_loss.py
code served (permissive licence) · get_code("b61e3950faef80b0")
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 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)

# The function expects a tensor of losses
# It filters for values > 0.0 and computes mean of those
# If no values pass the filter, it returns sum of losses * 0 (which is 0)

# Create a small tensor with mixed positive and zero/negative values
losses = torch.tensor([1.5, 0.0, 2.3, -0.5], dtype=torch.float32)

ARGS = {
    "losses": losses
}
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 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
heaviside Ran
ran, honoured the contract we drafted
elias-ramzi/HAPPIER/happier/losses/hap_loss.py
code served (permissive licence) · get_code("a2a835592cd98f2b")
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

torch.manual_seed(0)

# Construct arguments for the heaviside function
tens = torch.randn(2, 4)
val = 1.0
target = None
general = None

ARGS = {
    "tens": tens,
    "val": val,
    "target": target,
    "general": general
}
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
rank Ran
ran, honoured the contract we drafted
elias-ramzi/HAPPIER/happier/losses/hap_loss.py
code served (permissive licence) · get_code("85bac81fb967d1ed")
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 int, 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 function 'rank' takes a tensor and performs argsort operations
# It expects a 2D tensor (batch dimension first, then feature/values dimension)
# The operations: argsort(1, True) sorts along dimension 1 in descending order
# Then argsort(1) again on the result to get ranks

tens = torch.randn(2, 4)  # batch=2, dim=4 as specified

ARGS = {
    'tens': tens
}
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 int, 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
reduce Ran
ran; our contract draft was wrong, not the code
elias-ramzi/HAPPIER/happier/losses/hap_loss.py
code served (permissive licence) · get_code("f3c0efc31c507b36")
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 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)

def avg_non_zero_reducer(losses):
    threshold_condition = losses > 0.0
    num_past_filter = torch.sum(threshold_condition)
    if num_past_filter >= 1:
        loss = torch.mean(losses[threshold_condition])
    else:
        loss = torch.sum(losses * 0)
    return loss

REDUCE_DICT = {'none': torch.nn.Identity(), 'mean': torch.mean, 'sum': torch.sum, 'avg_non_zero': avg_non_zero_reducer}

def reduce(tens, reduce_type='mean'):
    return REDUCE_DICT[reduce_type](tens)

# Create a small tensor with distinct shape
tens = torch.randn(2, 4)

# Test with different reduce types
ARGS = {
    'tens': tens,
    'reduce_type': 'mean'
}
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 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
tau_sigmoid Ran
ran, honoured the contract we drafted
elias-ramzi/HAPPIER/happier/losses/hap_loss.py
code served (permissive licence) · get_code("4166f6849af69137")
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

torch.manual_seed(0)

# Create a small tensor (batch=2, dim=4)
tensor = torch.randn(2, 4)

# tau is a temperature parameter (scalar)
tau = 0.5

# target can be None or a tensor, but the function doesn't use it
target = None

# general is a boolean flag, but the function doesn't use it
general = False

ARGS = {
    "tensor": tensor,
    "tau": tau,
    "target": target,
    "general": general,
}
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
HAPLoss Not yet run
unverified (harvested, no recorded run)
elias-ramzi/HAPPIER/happier/losses/hap_loss.py
code served (permissive licence) · get_code("de52fe23104f1338")
How it ran

no invocation recorded.

step_hrank Not yet run
unverified (harvested, no recorded run)
elias-ramzi/HAPPIER/happier/losses/hap_loss.py
code served (permissive licence) · get_code("6dfe8890c17d85e0")
How it ran

no invocation recorded.

step_rank Not yet run
unverified (harvested, no recorded run)
elias-ramzi/HAPPIER/happier/losses/hap_loss.py
code served (permissive licence) · get_code("3543d7a337574447")
How it ran

no invocation recorded.

Also present in other papers' code

Of 9 samples lifted from this paper's linked repositories, 9 carry a function identity and 0 do not. Of the 9 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, 0 later) and 8 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
heaviside
brick of this paper's assembly: helper
1 other paper
1 dated earlier
2110.01445 (2021-10)
Robust and Decomposable Average Precision for Image Retrieval

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

Image Retrieval is commonly evaluated with Average Precision (AP) or Recall@k. Yet, those metrics, are limited to binary labels and do not take into account errors' severity. This paper introduces a new hierarchical AP training method for pertinent image retrieval (HAPPIER). HAPPIER is based on a new H-AP metric, which leverages a concept hierarchy to refine AP by integrating errors' importance and better evaluate rankings. To train deep models with H-AP, we carefully study the problem's structure and design a smooth lower bound surrogate combined with a clustering loss that ensures consistent ordering. Extensive experiments on 6 datasets show that HAPPIER significantly outperforms state-of-the-art methods for hierarchical retrieval, while being on par with the latest approaches when evaluating fine-grained ranking performances. Finally, we show that HAPPIER leads to better organization of the embedding space, and prevents most severe failure cases of non-hierarchical methods. Our code is publicly available at https://github.com/elias-ramzi/HAPPIER.

For agents

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

get_harvested_code_for_paper("2207.04873")
get_code_for_paper("2207.04873")
have("2207.04873")

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

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

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

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

Connect an agent — have() is free.