DPR on SQuAD with ModernBERT-base

A dense passage retriever for Wikipedia questions, trained on SQuAD v1.1 with the same recipe as the FiQA model hananinas/02456-dpr-fiqa-modernbert. 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 rajpurkar/squad
Questions 78,872 train, 8,727 validation, 10,570 test
Split validation is every 10th article title (sorted) held out of the SQuAD train split; test is the SQuAD validation split
Corpus 20,958 passages: the union of the context paragraphs of all three splits

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 9 rounds of 100 optimiser steps (115,200 questions drawn, about 1.5 passes), validation nDCG@10 after each round, patience 3; every round improved and round 9 is the one saved
Hardware one 6 GB laptop GPU, 11,844 s wall clock

Test results

10,570 test questions against all 20,958 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.7739 0.7306 0.6340 0.8588 0.9079 0.9420 0.9420
BM25, k1 0.9, b 0.4 0.8002 0.7684 0.6974 0.8606 0.8987 0.9265 0.9265
BM25, k1 1.5, b 0.75 0.7935 0.7602 0.6851 0.8571 0.8966 0.9256 0.9256
TF-IDF 0.4208 0.3667 0.2750 0.4903 0.5950 0.7048 0.7048

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. Each SQuAD question has one gold passage, so Recall@k and Hit@k coincide. Validation nDCG@10 of the kept round is 0.7675.

BM25 stays ahead on nDCG@10, MRR@10, Recall@1 and Recall@5; this model is ahead at Recall@10 and Recall@20.

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-squad-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 --dataset squad --methods dpr \
  --checkpoint "$(python -c 'from huggingface_hub import snapshot_download; print(snapshot_download("hananinas/02456-dpr-squad-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 round and its validation scores
run.json full training config and per-round history written by train_dpr.py
tokenizer/ the ModernBERT-base tokenizer as saved at training time
Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Model tree for hananinas/02456-dpr-squad-modernbert

Finetuned
(1,633)
this model

Dataset used to train hananinas/02456-dpr-squad-modernbert