arXiv:2610.09863cs.CVOct 2026

Manuscript Offprint

arXiv:2610.09863

Global Average Precision for Representation Learning

Bill Psomas, Mohammad Mahdi, Michalis Thomas, Danda Pani Paudel, Giorgos Tolias, Giorgos Kordopatis-Zilos

ABSTRACT

Standard information retrieval metrics, such as mean Average Precision (mAP), assess performance one query at a time, based on how the similarities between a query and its positives compare against those with its negatives. The same holds for common representation learning losses, such as InfoNCE and per-query AP surrogates. None of them considers whether similarities are comparable across queries, which any system with a single decision threshold relies on. Global Average Precision (gAP) does, by ranking all query–candidate pairs in one list and computing a single AP. We introduce gSAP, a differentiable surrogate of gAP. It needs only a similarity matrix and a binary matrix marking the positive pairs, the same input as existing losses, so it is a drop-in replacement for them and agnostic to the encoder, the modality, and the source of supervision. Since it considers all possible pairwise comparisons in the batch jointly, it also remains trainable at low temperatures, a regime where per-query surrogates run out of gradient. Swapping it into established recipes improves supervised metric learning, cross-modal alignment, and self-supervised pretraining, where, to our knowledge, it is the first ranking loss to replace the community standard InfoNCE in the latter two. Its similarities are more consistent across queries, which drives the gains under a universal threshold. gSAP retrieves up to four times as many positive pairs as the strongest AP surrogate at the same precision, and it degrades the least when queries with no positives in the database are added. Beyond thresholding, models trained with gSAP also learn better representations, with higher transfer, kNN and zero-shot classification accuracy.

1 INTRODUCTION

Average Precision (AP) (Schütze et al., 2008) is the standard metric for ranking quality and is reported as mean AP (mAP) over queries across retrieval and recognition tasks (Radenović et al., 2018; Li et al., 2014; Rolínek et al., 2020). mAP treats each query separately (Figure 1), so the distribution of similarities may vary from query to query. Global Average Precision (gAP) (Perronnin et al., 2009), in contrast, ranks all query–database pairs in a single global list and computes a single AP, i.e. it evaluates all queries jointly. It therefore captures the consistency of similarities across queries as well as ranking quality, and bridges retrieval and detection through a threshold that separates relevant from irrelevant pairs, which is why several benchmarks adopt it (Weyand et al., 2020; Ypsilantis et al., 2021; Douze et al., 2021; Pizzi et al., 2024; Kordopatis-Zilos et al., 2023). gAP is thus the right metric for similarity models and systems operating under a single decision threshold. In Figure 1(b), a per-query surrogate leaves positive and top-negative similarities overlapping across queries, whereas the proposed loss separates them.

Despite its desirable properties, gAP is not used as a training objective, mainly because the ranking at its core is discrete and because it is computed over every pair of the similarity matrix, which is costly when the matrix is large. In this work, we turn gAP into a practical loss for representation learning via pruning negative similarities that do not significantly impact the loss. We derive a smooth surrogate, gSAP, that directly optimizes this global metric. Per-query losses, such as the widely used InfoNCE (Oord et al., 2018) and the existing AP surrogates (Qin et al., 2010; Revaud et al., 2019;

∗^{*}Equal technical contribution.

Figure

mAP = 70.8%

(a)

Figure

gSAP

(b)

Figure 1: Overview of mAP and gAP and the effect of optimizing their surrogates. (a) Illustration of the metric computation for a batch of images. For mAP, each row of the similarity matrix is treated as an independent query: AP is computed per row after ranking the similarities, and the final score is obtained by averaging across queries. For gAP, all pairwise similarities are first aggregated into a single list, and a single AP value is computed globally. Consequently, mAP evaluates ranking quality per query and is insensitive to how similarities compare across queries, whereas gAP penalizes inconsistencies in similarity distributions across queries. (b) Distribution of positive and top-negative similarities after overfitting a single batch using mSAP (Brown et al., 2020) and the proposed gSAP loss. The proposed loss produces better separation between positive and negative similarities, allowing them to be distinguished by a single global threshold.

Brown et al., 2020; Ramzi et al., 2021), optimize the ranking of each query in isolation and therefore leave the similarity scales of different queries unconstrained. gSAP ranks the whole similarity matrix at once and replaces the loss of any model whose training objective is based on a similarity matrix.

Ranking the whole matrix also eases the trade-off between the fidelity of the surrogate and the flow of its gradient. A small temperature makes the sigmoid follow the step function closely (Qin et al., 2010; Brown et al., 2020), but saturates most comparisons, so their gradients vanish (Ramzi et al., 2021). Since gSAP involves many more comparisons than per-query surrogates, as each positive is compared with every similarity in the batch rather than with its own row only, a sufficient fraction of them remains unsaturated. This allows low temperatures, and thus an accurate AP approximation, without vanishing gradients, which is not possible for the per-query counterparts.

The formulation needs only a similarity matrix and a binary relevance matrix, and is therefore agnostic to the encoders, the modality, and the source of supervision. Relevance marks same-class pairs in supervised metric learning, matching pairs in image–text, video–text, or audio–text alignment, and augmented views of the same sample in self-supervised learning. To our knowledge, gSAP is the first ranking loss to replace InfoNCE in CLIP-style cross-modal and self-supervised training.

We evaluate gSAP by replacing only the loss in established recipes for supervised metric learning, CLIP and CLAP cross-modal alignment, MoCo v3 self-supervised pretraining, and tasks with distractor queries. Across all of them, gSAP improves gAP while remaining competitive in mAP and Recall@k, and outperforms InfoNCE and SigLIP, the two standard cross-modal losses, on every retrieval benchmark. It also yields better representations, as the encoders trained with it reach higher transfer, kNN and zero-shot classification accuracy. The gains come from the consistency across queries, which translates into more matches under a single shared threshold and the smallest loss of gAP when distractor queries are added.

In summary, our contributions are outlined below.

• We advocate gAP as a metric for representation learning, since it captures both ranking quality and the consistency of similarities across queries, which per-query metrics ignore.

• We propose gSAP, a smooth surrogate of gAP and a drop-in replacement for existing losses that keeps gradients alive at temperatures where per-query surrogates saturate, and negative dropping, which scales it to very large batches.

• On supervised, cross-modal (image, text, video, audio), self-supervised, and distractor-query tasks, where gSAP is the first ranking loss to replace InfoNCE, it attains the best gAP on every retrieval benchmark, matches or exceeds the best per-query metrics in nearly all cases, and gains by far the most when one threshold serves all queries.

References (100)

Couldn't load all references. Reload the page to try again.