Ismail Ben Alla

tiny-reranker

Text, Image and Audio Rerankers from Scratch

Multimodal · Nov 2026 · In progress

A second, closer look at the top candidates: small cross-encoders for text, pictures and sounds.

Built withPyTorchNumPyHugging Face DatasetspytestJavaScript

tiny-reranker — overview

Overview

tiny-reranker is the second stage of my tiny search family. A fast first stage (BM25 or the tiny-embedder bi-encoder) finds the top-100 candidates. The reranker then reads the query and each candidate together, in one sequence, and gives each pair one score.

I built three of them. The text reranker reads [CLS] query [SEP] passage [SEP]. The image reranker reads 64 picture patches and a caption. The audio reranker reads 124 log-mel patches and a caption. All three use tiny-bert's 6 × 256 encoder and byte-level BPE, with a Linear score on [CLS].

Training uses a listwise softmax loss over 1 positive and 7 hard negatives. Text is trained on MS MARCO, Natural Questions, GooAQ and SQuAD with BM25 negatives. Pictures use Flickr30k and COCO, sounds use Clotho, AudioCaps, MACS, WavText5K, MusicCaps and Song Describer, with tiny-embedder's nearest wrong candidates as negatives.

The finished checkpoints go to the family's model store, where tiny-nn-search and tiny-rag load them.

The question

Can one small encoder, read over the query and the candidate together, put a first stage's top-100 in a better order for text, pictures and sounds?

Key features

How it works

  1. First stage

    BM25 (shared with tiny-nn-search) or tiny-embedder returns the top-100 candidates for a query.

  2. One sequence per pair

    The query and one candidate go into the same sequence: text tokens, or picture / log-mel patches with the caption. tiny-bert's 6 layers read it and a Linear layer on [CLS] gives one score.

  3. Listwise training

    Each query comes with its positive and 7 hard negatives; a softmax over the 8 scores and loss = -log p(positive).

  4. Rerank

    The candidates are sorted by score, best first, and the new top-k goes back to search or RAG.

Examples

The pipeline: a first stage finds the top-100, the cross-encoder reads query and candidate together and scores each pair.
The pipeline: a first stage finds the top-100, the cross-encoder reads query and candidate together and scores each pair.
One sequence for every modality: text tokens, 64 picture patches or 124 log-mel patches, next to the query or caption.
One sequence for every modality: text tokens, 64 picture patches or 124 log-mel patches, next to the query or caption.
A real SQuAD dev query with BM25's top-5: the right passage is ranked 2nd, the case a reranker is for.
A real SQuAD dev query with BM25's top-5: the right passage is ranked 2nd, the case a reranker is for.

Tech stack

What I learned

Limitations

Related projects