tiny-reranker
Text, Image and Audio Rerankers from Scratch
A second, closer look at the top candidates: small cross-encoders for text, pictures and sounds.
- 3 rerankers: text, image, audio
- 1 positive + 7 hard negatives per query
- BM25 baseline: MRR@10 0.383 on MS MARCO
Built withPyTorch
NumPy
Hugging Face Datasets
pytest
JavaScript
Code is in a private repository for now.

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
- Three cross-encoders (text, image, audio) sharing tiny-bert's encoder and tokenizer
- Listwise loss over 1 positive + 7 hard negatives (BM25 or tiny-embedder)
- Leak filter: test queries and passages removed from training
- Simple API: TextReranker / ImageReranker / AudioReranker .rerank(query, candidates, top_k)
- One-command benchmark: MRR@10, nDCG@10 and Recall@k before vs after, against random init and a public MiniLM cross-encoder
- Website with real test queries: BM25's top-5 next to the reranked order
How it works
First stage
BM25 (shared with tiny-nn-search) or tiny-embedder returns the top-100 candidates for a query.
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.
Listwise training
Each query comes with its positive and 7 hard negatives; a softmax over the 8 scores and loss = -log p(positive).
Rerank
The candidates are sorted by score, best first, and the new top-k goes back to search or RAG.
Examples



Tech stack
The three cross-encoders, the listwise loss and training
Memory-mapped token caches and media
Downloading MS MARCO, Natural Questions, GooAQ, SQuAD and SciFact
Score shapes, padding invariance, save / load and overfitting tests
Project website with the real query examples
What I learned
- Pictures and sounds fit the text recipe: cut them into patches, put them in the same sequence as the caption, and the same tiny-bert blocks read both.
- Measuring the first stage before training gives each reranker a clear bar: BM25 already reaches MRR@10 0.826 on SQuAD dev but only 0.383 on MS MARCO.
- A leak filter is needed: a training query or positive that is also in a test set is removed, and so is a test passage among the negatives.
Limitations
- No trained reranker yet: the results above are the first stage and a sanity check, not the reranking benchmark.
- Image and audio depend on tiny-embedder's prepared data and models for candidates and hard negatives.
Related projects

Tiny BERT — A Small Encoder and Its BPE Tokenizer, From Scratch
Code is in a private repository for now.
A 9M-parameter BERT-style encoder and its byte-level BPE tokenizer, written and pre-trained from scratch in PyTorch, with no Hugging Face transformers. It is the encoder the rest of my tiny family starts from.
Built with:
PyTorch
Hugging Face Datasets
NumPy
scikit-learnMatplotlib
pytest

tiny-embedder — Text, Image and Audio Embeddings from Scratch
Code is in a private repository for now.
Three small embedding models built from scratch in PyTorch: text, images and sounds each become a 256-d vector, so similar things end up close. Every text tower starts from my tiny-bert.
Built with:
PyTorch
NumPy
Hugging Face Datasets
pytest
JavaScript

Tiny NN Search — Vector and Keyword Search from Scratch
Code is in a private repository for now.
A small vector and keyword search engine I wrote from scratch in NumPy: exact search, IVF, PQ, IVF-PQ, HNSW, LSH, BM25 and hybrid fusion, with one engine each for text, images and audio. It is the retrieval engine of tiny-rag.
Built with:
NumPy
Gradio
PyTorchMatplotlib
pytest

tiny-rag — Ask Your Texts, Images and Sounds
Code is in a private repository for now.
A retrieval-augmented generation system over texts, images and sounds, built on my own tiny-* models. Each query is searched with its own kind of model, then Qwen2.5-0.5B-Instruct, run inside tiny-llm, answers from numbered sources.
Built with:
PyTorch
Gradio
NumPy
Hugging Face Datasets
pytest