DPR on FiQA with ModernBERT-base
A dense passage retriever for personal finance questions, trained on FiQA with the DPR contrastive setup. A course project model, trained for the final project in 02456 Deep Learning at the Technical University of Denmark.
Code: linxuansong1022/02456-retrieval-project
Data
| Dataset | vibrantlabsai/fiqa, config main, splits as published |
| Questions | 5,500 train, 500 validation, 648 test |
| Corpus | 17,110 passages: the union of the gold answers of all three splits, so every passage is the right answer to some question |
Training recipe
| Backbone | answerdotai/ModernBERT-base, one encoder shared by questions and passages |
| Pooling | mean over tokens (padding ignored), then L2 normalisation, 768 dimensions |
| Loss | InfoNCE over cosine scores with temperature 0.02; a passage that is also gold for the question is masked out of its softmax |
| Batch | 128 questions per optimiser step, each with its gold passage and 1 BM25 hard negative, so 256 passages per step |
| Memory | gradient cache over micro-batches of at most 16,384 padded tokens, bf16 autocast, gradient checkpointing |
| Hard negatives | BM25 (k1 0.9, b 0.4), the 30 best non-gold passages per training question from a pool without any validation or test gold passage; each draw takes one of the top 10 |
| Lengths | questions 64 tokens, passages 512 tokens |
| Optimiser | AdamW, lr 5e-5, weight decay 0.01, 10% linear warm-up then linear decay, gradient clipping at 1.0 |
| Schedule | up to 7 epochs, validation nDCG@10 after each, patience 3; the best epoch (5) is the one saved |
| Hardware | one 6 GB laptop GPU, 7,387 s wall clock |
Test results
648 test questions against all 17,110 passages, same metric code for every row.
| Method | nDCG@10 | MRR@10 | Recall@1 | Recall@5 | Recall@10 | Recall@20 | Hit@20 |
|---|---|---|---|---|---|---|---|
| This model | 0.3658 | 0.4215 | 0.3148 | 0.3745 | 0.4576 | 0.5533 | 0.7377 |
| BM25, k1 1.5, b 0.75 | 0.2803 | 0.3481 | 0.2685 | 0.2855 | 0.3437 | 0.4186 | 0.6188 |
| BM25, k1 0.9, b 0.4 | 0.2576 | 0.3184 | 0.2423 | 0.2569 | 0.3187 | 0.3920 | 0.5880 |
| TF-IDF | 0.1222 | 0.1579 | 0.1003 | 0.1164 | 0.1639 | 0.2399 | 0.4151 |
Recall@k is the repo's definition: hits in the top k divided by min(k, number of gold passages). Hit@k is the share of questions with at least one gold passage in the top k. Search is exact cosine over the whole corpus. Validation nDCG@10 of the kept epoch is 0.3985.
Use
The checkpoint is loaded by the project code, not by transformers alone: query_encoder.pt is the state dict of the project's HFEncoder wrapper around ModernBERT-base. Because the tower is shared ("shared_tower": true in meta.json) there is no document_encoder.pt; the same encoder embeds questions and passages.
git clone -b feat/training-visualization https://github.com/linxuansong1022/02456-retrieval-project.git
cd 02456-retrieval-project
pip install -r requirements.txt
from huggingface_hub import snapshot_download
from src.training.build import load_towers
path = snapshot_download("hananinas/02456-dpr-fiqa-modernbert")
encoder, _, meta, tokenizer = load_towers(path, device="cpu")
To score it with the project's evaluation code:
python scripts/training_run_data.py evaluate --methods dpr \
--checkpoint "$(python -c 'from huggingface_hub import snapshot_download; print(snapshot_download("hananinas/02456-dpr-fiqa-modernbert"))')" \
--device cuda --out eval.json
Files
| File | What it is |
|---|---|
query_encoder.pt |
state dict of the shared encoder |
meta.json |
model settings, kept epoch and its validation scores |
run.json |
full training config and per-epoch history written by train_dpr.py |
tokenizer/ |
the ModernBERT-base tokenizer as saved at training time |
Model tree for hananinas/02456-dpr-fiqa-modernbert
Base model
answerdotai/ModernBERT-base