Skip to content
Edit this page

The SAE this project publishes

tkhshtsh0917/modernbert-ja-310m-sae-65k is a Top-K SAE on the last hidden states of sbintuitions/modernbert-ja-310m: 65,536 latents, k = 16, one billion tokens. It is the only run of this project at the size of its reference, the SAE used by Shizuku, and it was made to check that the toolkit gets from a corpus to an SAE of that quality end to end. The examples in this documentation load it.

It was trained and measured before the package was reorganised for 0.1.0, with the option and key names of that time. The weights are unchanged; the keys of sae_config.json and metrics.json were renamed to the ones 0.1.0 writes.

Training

Encoder sbintuitions/modernbert-ja-310m, last hidden state (768 dimensions), bfloat16 autocast
SAE 65,536 latents, Top-K with k = 16, float32
Inputs content tokens only, no prompt, texts cut at 1,024 tokens
Tokens 999,997,440: 735,557,255 of documents and 264,791,148 of queries
Hardware one NVIDIA RTX 4090, 6.6 hours, about 42,000 tokens per second
muscari train-sae --trainer topk
  --model sbintuitions/modernbert-ja-310m --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

The corpus has 8,953,217 rows of queries and documents from public datasets: web FAQ pairs (mahiyama/mqa-ja), Wikipedia question-answer pairs (mahiyama/auto-wiki-qa), Japanese Wikipedia articles and passages, and questions of several question-answering datasets from hpprc/emb. It contains no data derived from MS MARCO and none released for non-commercial use only. Rows whose question equals a question of JQaRA after NFKC normalisation were dropped, because JQaRA evaluates the retrieval models below. The model card lists every part with its size and license. Training read the corpus as a shuffled stream and had started its second pass when it reached one billion tokens; 5% of the rows were held out.

Reconstruction

On 2 million tokens each, against the published SAE of the same encoder and size:

Texts SAE FVU Masked-LM loss recovered (100 texts) Latents never active
JaGovFaqs-22k, seen by neither SAE this project's 0.2253 0.9152 6.6%
published 0.2144 0.9077 5.6%
The 5% held out from this project's corpus this project's 0.1526 0.9360 0.05%
published 0.1543 0.9322 0.1%

The held-out texts come from sources the published SAE was also trained on, so it may have seen some of them. Running the encoder in float32 instead of bfloat16 changed these values by at most 0.0001. On the held-out tokens about a quarter of the latents fired less than a tenth as often as the average latent.

Retrieval

Each SAE as a frozen head on modernbert-ja-310m, with the encoder trained for 2,000 steps of 16 queries on the retrieval subsets of cl-nagoya/ruri-v3-dataset-ft without jqara. nDCG@10 on 800 test queries of JQaRA with 100 candidates each, for seeds 42, 43 and 44:

Head nDCG@10 Vectors capped at 64 / 256 weights Non-zero weights, query / document FLOPS
This project's SAE 0.640 / 0.643 / 0.637 0.638 / 0.647 / 0.633 about 117 / 245 5.9 to 6.4
Published SAE 0.635 / 0.641 / 0.636 0.637 / 0.643 / 0.637 about 115 / 233 5.4 to 6.2
Vocabulary head (logit shift, 16 logits per position) 0.640 / 0.645 / 0.643 0.614 / 0.630 / 0.617 about 102 / 470 6.1 to 6.6

Over the three seeds, this project's SAE minus the published one is +0.003 without a cap (95% interval over queries -0.002 to +0.008) and -0.000 with the cap (-0.006 to +0.006).

  • The two SAEs are equivalent in these measurements. The pipeline, from a corpus built here to a frozen retrieval head, gives what the published SAE gives.
  • The retrieval training is short and small. These are not results of a finished retriever, and one benchmark was used.
  • Not looked at. No other layer or encoder, no domain far from web FAQs and Wikipedia, and the latents were not labelled or inspected one by one.

Latents that are active in most texts

probe-sae on 100 queries of the JQaRA test split with their 100 candidates each, which are 9,789 distinct documents with their titles; nothing is trained, and the encoder ran on Apple MPS. A latent counts as active in a text when it fires on at least one content token.

Latent 43688 is active in every one of the documents and of the queries. Its pooled weight is 3.18 ± 0.10 in the documents, 1.88 at the lowest, and 2.87 ± 0.23 in the queries. In the pairs of texts read under Why two texts match it is strongest on the last token of each text. Seven latents are active in 99% of the documents or more, 17 in 90% or more, 72 in more than half, and 1,449 in a tenth or more.

Ranking by the dot product of the pooled vectors, with sets of these latents left out:

Left out of queries and documents Latents FLOPS Non-zero weights, query / document nDCG@10 Change nDCG@10 with IDF weights
nothing 0 35.24 264 / 875 0.470 0.524
latent 43688 1 34.24 263 / 874 0.469 -0.0001 ± 0.0001 0.524
active in 99% of the documents or more 7 29.47 259 / 868 0.472 +0.002 ± 0.002 0.524
active in 90% of the documents or more 17 26.87 256 / 859 0.473 +0.004 ± 0.002 0.524
active in more than half of the documents 72 18.10 243 / 824 0.481 +0.012 ± 0.005 0.524

Each nDCG@10 has a standard error of 0.025 over the queries. The change is the mean difference per query to the first row, with its standard error. FLOPS is the sum over latents of the share of queries times the share of documents in which the latent is active, on this collection.

  • A latent that is active everywhere does not rank. Leaving out latent 43688 changes nDCG@10 by -0.0001 and takes exactly 1.0 from FLOPS: one posting for every document, read for every query.
  • 72 of the 65,536 latents carry half of the FLOPS. Without them FLOPS falls from 35.2 to 18.1, and the ranking is not worse: +0.012 ± 0.005.
  • IDF weights already do this to the ranking, not to the index. With IDF weights nDCG@10 is 0.524 whether the latents are in or out, because a latent that is in most documents gets a weight near zero. Its postings are still stored and read; masking removes them.
  • Frequent in documents is not frequent in queries. Latent 31580 is active in 99% of the documents and 3% of the queries, latent 45296 in 98% of the documents and in no query, and seven latents (48778, 64990, 3998, 57904, 19016, 55874, 20600) each in 91% to 93% of the documents and a quarter of the queries. Such a latent adds little to FLOPS and still has a posting list nearly as long as the collection.
  • What this does not say. It is one benchmark, 100 queries and a head before retrieval training. Which latents are frequent depends on the texts, here Wikipedia passages with their titles, and nothing is trained. The next section repeats it with trained retrievers.

One row of the table:

muscari probe-sae --sae tkhshtsh0917/modernbert-ja-310m-sae-65k --benchmark jqara \
  --max-queries 100 --seed 42 --masked-latents 43688

The sets of the other rows come from text_frequencies, as Latents that are active everywhere shows. The seven latents of the third row are 43688, 37025, 14128, 31580, 17117, 59878, 55458.

The same latents in a trained retriever

Does retrieval training with a FLOPS term remove these latents on its own, and does it help to leave them out from the start? The latents were chosen before any retrieval training and without the benchmark: inspect-sae on 2,097,152 tokens of the positive documents of the training subsets lists 101 latents that are active in more than half of the documents (8 in 99% or more, 19 in 90% or more, 2,333 in a tenth or more).

Three variants of the frozen SAE head on modernbert-ja-310m, trained as in Retrieval above, for seeds 42, 43 and 44. nDCG@10 on the 800 test queries of JQaRA:

nDCG@10 Vectors capped at 64 / 256 weights Non-zero weights, query / document FLOPS
Trained with every latent 0.640 / 0.643 / 0.637 0.638 / 0.647 / 0.633 about 117 / 245 5.9 to 6.4
The same models, the 101 latents left out when searching 0.640 / 0.645 / 0.636 0.639 / 0.648 / 0.633 about 113 / 240 3.5 to 3.9
Trained with the 101 latents left out 0.636 / 0.650 / 0.644 0.638 / 0.654 / 0.646 about 103 / 231 3.1

Mean differences to the first row over the three seeds, with 95% intervals over the queries:

No cap 64 / 256
Left out when searching +0.001 (-0.001 to +0.002) +0.001 (-0.000 to +0.002)
Left out in training +0.003 (-0.002 to +0.008) +0.007 (+0.002 to +0.012)
  • Training does not remove them. After 2,000 steps with a FLOPS term the 101 latents still carry about two fifths of the FLOPS of the trained models. Leaving them out afterwards takes FLOPS from about 6.1 to 3.6 and changes nDCG@10 by +0.001.
  • Leaving them out from the start is not worse. The models trained with the mask end at a FLOPS of 3.1, level with the unmasked ones without a cap and 0.007 ahead with vectors capped at 64 and 256 weights. Before any training the masked head already ranks better on the development queries (0.72 against 0.69).
  • What this does not say. One encoder, one SAE, one benchmark and a short training run. FLOPS counts the products a search computes for a pair of texts; the time of a search in an index was not measured.

The list, and a run with it:

muscari inspect-sae --sae tkhshtsh0917/modernbert-ja-310m-sae-65k \
  --dataset cl-nagoya/ruri-v3-dataset-ft --subsets auto-wiki-qa-nemotron jaquad jsquad miracl mkqa mr-tydi quiz-works \
  --columns pos --part all --eval-tokens 2097152 --seed 42 --out latents.jsonl

python examples/train_retriever --head sae --sae tkhshtsh0917/modernbert-ja-310m-sae-65k \
  --sae-masked-latents 87 786 846 ... \
  --dataset your/dataset --out runs/masked

latents.jsonl has one line per latent with its text_frequency; the mask is every latent above 0.5. The measurement also read the subset quiz-no-mori; the subsets come under different licenses, which the dataset card lists.

Twice the latents

Would a larger SAE make a better head? An SAE with 131,072 latents was trained on the same corpus with the same settings, --num-latents 131072 being the only change: one billion tokens in 9.1 hours on the same GPU, at about 30,800 tokens per second.

Reconstruction on 2 million tokens each:

Texts SAE FVU Masked-LM loss recovered (100 texts) Latents never active
JaGovFaqs-22k 131,072 latents 0.2071 0.9178 20.6%
65,536 latents 0.2253 0.9152 6.6%
The 5% held out from the corpus 131,072 latents 0.1375 0.9377 0.9%
65,536 latents 0.1526 0.9360 0.05%

As a frozen head, trained as in Retrieval above, on the 800 test queries of JQaRA for seeds 42, 43 and 44:

Head nDCG@10 Vectors capped at 64 / 256 weights Non-zero weights, query / document FLOPS
131,072 latents 0.631 / 0.641 / 0.631 0.635 / 0.644 / 0.635 about 119 / 248 5.6 to 5.8
65,536 latents 0.640 / 0.643 / 0.637 0.638 / 0.647 / 0.633 about 117 / 245 5.9 to 6.4

Over the three seeds, the larger SAE minus the smaller one is -0.006 without a cap (95% interval over queries -0.011 to -0.000) and -0.001 with the cap (-0.007 to +0.004).

  • Better reconstruction did not make a better head. The larger SAE leaves 8% to 10% less of the variance unexplained, on texts it never saw and on its own corpus, and ranks no better: level with capped vectors, 0.006 lower without a cap.
  • Many of the added latents go unused away from the corpus. On JaGovFaqs a fifth of the 131,072 latents never fire on two million tokens, three times the share of the smaller SAE.
  • The vectors are no longer or shorter. The number of non-zero weights and FLOPS after training are about the same: the regulariser sets them, not the size of the dictionary.
  • What this does not say. One encoder, one benchmark, a short retrieval run and the settings of the smaller SAE unchanged, k = 16 included. A larger SAE may need more tokens or another k; neither was tried. The larger SAE is not published.