A dense retriever next to the sparse heads¶
One encoder, one training set and one schedule, with three ways to turn the encoder into a retriever: a dense one and two sparse heads. The encoder is cl-nagoya/ruri-v3-pt-310m, the checkpoint its authors publish as pretrained and not fine-tuned, next to their fine-tuned cl-nagoya/ruri-v3-310m. Starting from it puts the fine-tuned model on the page as a reference for what a finished dense retriever on this encoder reaches.
What was run¶
| Arm | How the encoder becomes a retriever |
|---|---|
| Dense | mean pooling and cosine similarity, as the checkpoint is published; CachedMultipleNegativesRankingLoss of Sentence Transformers with its default scale of 20, and with 50 and 100 further down |
| Frozen SAE head | an SAE with 65,536 latents and k = 16, trained here on the last hidden states of this encoder, published as tkhshtsh0917/ruri-v3-pt-310m-sae-65k, and kept frozen; FLOPS weight 3e-3, loss scale 0.2 |
| Vocabulary head | the checkpoint has no language-model head, so the head of sbintuitions/modernbert-ja-310m, which has the same vocabulary, is grafted on with muscari graft-head, as SPARSEUP does; logit shift, 16 logits per position, FLOPS weight 3.33e-5, loss scale 0.2 |
| References | ruri-v3-pt-310m and ruri-v3-310m as published, with nothing trained here |
Shared by the three arms: the retrieval subsets of cl-nagoya/ruri-v3-dataset-ft without jqara and without rows whose question is a question of JQaRA; 2,000 steps of 16 queries with one hard negative each; a learning rate of 2e-5; texts cut at 256 tokens; the prefixes 検索クエリ: and 検索文書: of the model card on queries and documents; seeds 42, 43 and 44; one NVIDIA RTX 4090. The settings of the sparse arms are the ones tuned earlier in this project on modernbert-ja-30m. Of the dense arm only the scale of the loss was varied.
The SAE saw one billion tokens of the queries and documents of seven of those subsets, with the same prefixes, in 6.3 hours. Under 1% of the tokens are queries. It reconstructs this encoder less well than the published SAE reconstructs its own: the fraction of variance unexplained is 0.278 on held-out texts (0.153 there) and 0.446 on JaGovFaqs-22k (0.225 there), where 28% of the latents never fire on two million tokens. Its card has the training data and these numbers; read from the Hub on another machine, it gave 0.449 on 200,000 tokens of JaGovFaqs-22k.
JQaRA¶
nDCG@10 on 800 test queries of JQaRA with 100 candidates each, for the three seeds:
| nDCG@10 | Vectors capped at 64 / 256 weights | Non-zero weights, query / document | FLOPS | |
|---|---|---|---|---|
| Dense, trained here | 0.665 / 0.645 / 0.653 | 768 dimensions | ||
| Frozen SAE head | 0.679 / 0.669 / 0.670 | 0.681 / 0.674 / 0.671 | about 103 / 230 | 2.7 to 3.3 |
| Vocabulary head | 0.676 / 0.673 / 0.661 | 0.658 / 0.655 / 0.644 | about 125 / 477 | 7.4 to 8.3 |
| ruri-v3-pt-310m, as published | 0.641 | 768 dimensions | ||
| ruri-v3-310m, as published | 0.702 | 768 dimensions |
Mean differences over the three seeds, with 95% intervals over the queries:
| No cap | Sparse vectors capped at 64 / 256 | |
|---|---|---|
| SAE head minus dense | +0.018 (+0.010 to +0.027) | +0.021 (+0.012 to +0.030) |
| Vocabulary head minus dense | +0.016 (+0.006 to +0.026) | -0.002 (-0.013 to +0.009) |
| SAE head minus vocabulary head | +0.003 (-0.005 to +0.010) | +0.023 (+0.015 to +0.032) |
| Dense minus ruri-v3-pt-310m | +0.014 (+0.002 to +0.025) | |
| Dense minus ruri-v3-310m | -0.047 (-0.055 to -0.039) |
Retrieval from a whole corpus¶
The models of seed 42 only, so without intervals. nDCG@10, with recall@100 in brackets; the sparse models rank by the dot product of uncapped vectors.
| Queries / documents | Dense, trained here | SAE head | Vocabulary head | pt, as published | ruri-v3-310m |
|---|---|---|---|---|---|
| JaGovFaqs-22k, 2,048 / 22,794 | 0.722 (0.939) | 0.698 (0.933) | 0.676 (0.913) | 0.764 (0.957) | 0.774 (0.962) |
| NLP Journal, title to abstract, 510 / 637 | 0.973 (0.996) | 0.984 (0.996) | 0.976 (0.994) | 0.973 (0.998) | 0.979 (0.998) |
| NLP Journal, title to introduction, 510 / 637 | 0.878 (0.994) | 0.891 (0.994) | 0.873 (0.992) | 0.888 (0.990) | 0.873 (0.992) |
| NLP Journal, abstract to introduction, 510 / 637 | 0.947 (0.994) | 0.957 (0.994) | 0.953 (0.996) | 0.938 (0.996) | 0.947 (0.996) |
| MIRACL, a reduced corpus, 860 / 105,064 | 0.655 (0.981) | 0.665 (0.989) | not run | not run | 0.705 (0.986) |
The scale of the dense loss¶
The dense retriever's score on the development queries fell during training, so its loss was run again with scales of 50 and 100, everything else unchanged. The rule was fixed before the runs: the scale with the best development score after training is the dense arm.
| Scale | nDCG@10 on the test queries | Development queries, after training | SAE head minus dense |
|---|---|---|---|
| 20, the default | 0.665 / 0.645 / 0.653 | 0.948 / 0.952 / 0.952 | +0.018 (+0.010 to +0.027) |
| 50 | 0.656 / 0.650 / 0.647 | 0.940 / 0.941 / 0.944 | +0.022 (+0.013 to +0.031) |
| 100 | 0.658 / 0.643 / 0.652 | 0.936 / 0.942 / 0.947 | +0.022 (+0.013 to +0.031) |
Before training the checkpoint scores 0.956 to 0.963 on the development queries. The default stays the dense arm, and the tables above are its tables. On the five retrieval sets the three scales are within 0.01 of each other, and all three are below the untrained checkpoint on JaGovFaqs (0.722, 0.730 and 0.723 against 0.764).
Before any training¶
probe-sae with the SAE on the untrained checkpoint, 200 test queries of JQaRA: BM25 over the summed activations, which is the scoring of Latent Terms, reaches 0.638, and the checkpoint's own dense ranking 0.607. The difference is +0.031 with a standard error of 0.012.
What it shows¶
- With the same short training, the sparse heads were not behind the dense retriever. On JQaRA both are ahead of it by about 0.02, and on four of the five retrieval sets the SAE head is ahead by about 0.01.
- The short training gave the dense retriever little. It ends 0.014 above the checkpoint it started from on JQaRA, lower on the development queries (0.95 after 0.96) and lower on JaGovFaqs (0.722 against 0.764). The scale of its loss is not the reason: 50 and 100 give the same. Its loss is already low at the first logged step, 0.24, and ends near 0.1. A likely reading, not tested here: the checkpoint already ranks well as a dense retriever, and batches of 16 queries with one hard negative each leave it little to learn. Larger batches, more negatives and more steps were not tried, and the comparison says nothing about a dense retriever trained that way.
- The sparse heads start from nothing and get as far in the same steps. The head is new to the encoder in both sparse arms; before training the SAE head scores 0.85 on the development queries and the vocabulary head 0.83, and both end at about 0.95. What the encoder brings as a dense retriever carries over to a sparse head at the cost of a short run.
- None of the three reaches the fine-tuned model of the encoder's authors. ruri-v3-310m is 0.03 to 0.05 ahead on JQaRA, 0.04 to 0.05 on MIRACL and 0.05 to 0.10 on JaGovFaqs. It was trained with its authors' recipe, and their fine-tuning data has a
jqarasubset that the runs here leave out. The runs here saw 32,000 queries. - Away from the training texts the order changes. On JaGovFaqs all three trained models are below the untrained checkpoint, and the sparse heads below the dense one. The SAE reconstructs those texts poorly, as the numbers above show.
- The SAE head keeps its accuracy with capped vectors, the vocabulary head does not. At 64 and 256 weights the SAE head stays at 0.675 and the vocabulary head falls to 0.652, level with the dense retriever. The same was seen on modernbert-ja-310m.
- What this does not say. One benchmark with intervals; one seed on the retrieval sets; a short run with small batches and without distillation; a dense arm of which only the loss scale was varied; a vocabulary head grafted from another checkpoint with settings tuned elsewhere. The vocabulary head on MIRACL and every model on JaCWIR were planned and not run.
The commands¶
# The SAE, on the texts of the training subsets written to one Parquet file; it is published as
# tkhshtsh0917/ruri-v3-pt-310m-sae-65k
muscari train-sae --trainer topk --model cl-nagoya/ruri-v3-pt-310m --data-files corpus.parquet \
--columns "anc:query=検索クエリ: " "pos:document=検索文書: " "neg:document=検索文書: " \
--max-seq-length 1024 --num-latents 65536 --k 16 --batch-tokens 8192 --lr 5e-4 --warmup-frac 0.05 \
--aux-k 256 --aux-coef 0.03125 --dead-after-tokens 10000000 --total-tokens 1000000000 \
--holdout-pct 5 --seed 42 --encoder-amp --text-batch-size 64 --out runs/sae
# The vocabulary arm's model: this encoder with the head of another checkpoint
muscari graft-head --backbone cl-nagoya/ruri-v3-pt-310m --head-from sbintuitions/modernbert-ja-310m --out runs/grafted
# The SAE arm, here on the SAE as trained; --sae tkhshtsh0917/ruri-v3-pt-310m-sae-65k starts from the published one.
# The vocabulary arm has --head vocab --model runs/grafted --shift auto --fan-out 16 --regularizer-weight 3.33e-5
python examples/train_retriever --head sae --sae runs/sae --regularizer-weight 3e-3 --loss-scale 0.2 \
--dataset cl-nagoya/ruri-v3-dataset-ft --subsets auto-wiki-qa-nemotron jaquad jsquad miracl mkqa mr-tydi quiz-works \
--query-column anc --positive-column pos --negative-column neg --negatives 1 \
--query-prompt "検索クエリ: " --document-prompt "検索文書: " \
--max-seq-length 256 --max-steps 2000 --batch-size 16 --mini-batch-size 8 --learning-rate 2e-5 --seed 42 \
--eval-benchmark jqara --eval-split dev --eval-caps full 64/256 --out runs/sae-head
The dense arm is not a muscari model. It was trained with the same data loading and evaluated with the same code through a small wrapper that returns unit-length embeddings, so that the dot product the evaluation computes is the cosine similarity. The retrieval training also read the subset quiz-no-mori, which the SAE's texts leave out; the subsets come under different licenses, which the dataset card lists.