A probability threshold for the vocabulary head (experimental)¶
A language-model head is trained with a softmax, so its logits are defined only up to one constant per token: a logit is the log-probability of the entry plus the log-sum-exp of the token's logits. The shift of SPARSEUP thresholds that sum with one constant for all tokens. probability_threshold thresholds the log-probability instead, and energy adds back a share of the token's own constant, measured from a centre (muscari.heads.scores):
With energy=0 a token keeps the entries whose probability exceeds the threshold, which are fewer than 1 / threshold: raising one entry lowers the others, and the head is sparse before any regulariser acts. With energy=1 the score is a shifted logit again. energy_center="auto" takes the median log-sum-exp of the content tokens of the training documents, and saturate=False pools the scores without log(1 + x), as they are log-ratios already. The form is this project's own. It has been compared with the shifted head and the SAE head only, not with other published ways to make a vocabulary head sparse.
On modernbert-ja-30m. 2,000 steps of 16 queries (in mini-batches of 4) with one hard negative, learning rate 2e-5, scores times 0.1667, 12 logits per position, float32, on an NVIDIA RTX 4090, with the training data of the comparison above; evaluated on 800 test queries of JQaRA with texts of up to 512 tokens. The shifted head uses --shift auto (19.0). The probability head uses a threshold of 1/64, energy 0.25 with the centre at 28.0, and no saturation. Each cell gives seeds 42 and 43; "64/64" caps both vectors at their 64 largest weights.
| Head | FLOPS weight | nDCG@10, no cap | nDCG@10, 64/64 | Non-zero, query / document | FLOPS |
|---|---|---|---|---|---|
| Shifted | 3e-2 | 0.492 / 0.494 | 0.487 / 0.489 | 37 / 61, 36 / 61 | 0.39 / 0.37 |
| Shifted | 1e-2 | 0.531 / 0.525 | 0.505 / 0.496 | 47 / 90, 49 / 95 | 0.61 / 0.77 |
| Shifted | 3e-3 | 0.548 / 0.550 | 0.475 / 0.483 | 61 / 136, 60 / 145 | 1.13 / 1.25 |
| Shifted | 1e-3 | 0.551 / 0.554 | 0.435 / 0.445 | 76 / 194, 72 / 189 | 2.20 / 2.05 |
| Shifted | 0 (seed 42 only) | 0.556 | 0.356 | 78 / 396 | 8.38 |
| Probability | 1e-3 | 0.536 / 0.525 | 0.532 / 0.523 | 24 / 58, 22 / 54 | 0.46 / 0.34 |
| Probability | 3e-4 | 0.544 / 0.544 | 0.534 / 0.534 | 29 / 70, 23 / 71 | 0.84 / 0.57 |
| Probability | 1e-4 | 0.548 / 0.543 | 0.536 / 0.534 | 23 / 78, 22 / 80 | 0.75 / 0.87 |
| Probability | 3e-5 | 0.548 / 0.544 | 0.538 / 0.529 | 23 / 86, 33 / 91 | 1.03 / 2.12 |
| Probability | 0 | 0.543 / 0.547 | 0.525 / 0.531 | 23 / 105, 29 / 98 | 1.29 / 2.01 |
- Small vectors are more accurate with the probability head. Each of its eight regularised runs, paired with the shifted run of the same seed whose document vectors are closest in size, is ahead by 0.017 to 0.051 without a cap, and every 95% interval over the queries lies above zero (the lowest bound is +0.004). Two of the eight pairs differ in size by more than 15%.
- It stays sparse without a regulariser. With a weight of 0 its document vectors have about 100 entries, against about 80 at 1e-4, and it is 0.012 (0.000 to 0.024) and 0.021 (0.010 to 0.033) ahead of the shifted head at 1e-2, the closest in size. The shifted head without a regulariser grows to 396 entries and a FLOPS of 8.4. The regulariser is not without effect on the probability head: at the two weakest settings the FLOPS of the two seeds differ by a factor of 1.6 and 2.1.
- Its vectors survive a cap. Cut to 64 weights it loses at most 0.018 in the runs of this table. The shifted head loses 0.005 at its strongest regulariser and 0.11 to 0.12 at its weakest.
- Larger vectors close the gap. At about 190 entries the shifted head scores 0.551 and 0.554, as much as the best run of the probability head (0.552 with 111 entries, one seed, below). The probability head was not made larger than about 130 entries here: neither the threshold nor the limit per position moves its size much.
Single changes to the probability head, with a FLOPS weight of 1e-4 unless stated:
| Change | nDCG@10, no cap | Non-zero, document | FLOPS |
|---|---|---|---|
energy 0 |
0.541 / 0.541 | 117 / 114 | 5.53 / 7.55 |
energy 0.25 (the setting above) |
0.548 / 0.543 | 78 / 80 | 0.75 / 0.87 |
energy 0.5 |
0.535 / 0.540 | 84 / 76 | 0.86 / 0.62 |
energy 0.75 |
0.524 / 0.520 | 83 / 80 | 1.14 / 1.06 |
energy 1 |
0.521 / 0.519 | 148 / 104 | 2.06 / 1.75 |
| Threshold 1/16, seed 42 | 0.541 | 74 | 1.25 |
| Threshold 1/256 | 0.546 / 0.540 | 74 / 78 | 0.77 / 0.99 |
| No regulariser, 6 logits per position, seed 42 | 0.552 | 111 | 1.35 |
| No regulariser, 24 logits per position, seed 42 | 0.551 | 127 | 1.23 |
- A small share of the token's constant is the useful setting. Without it the accuracy holds but the FLOPS is seven to nine times as high; with a share of 0.75 or more the accuracy falls by 0.02 to 0.03. A share of 1 is a shifted logit in form, but pooled without saturation and with an offset set differently, and it is not the shifted head of the table above.
- The threshold and the limit per position hardly change the size. From a threshold of 1/16 to 1/256 the document vectors stay at 74 to 80 entries, and from 6 to 24 logits per position, without a regulariser, at 105 to 127.
On modernbert-ja-310m. The settings of the 310M section above (scores times 0.2, 16 logits per position, mini-batches of 8), with the probability head as on the small encoder and no regulariser. The shifted head and the frozen SAE head with the published SAE were trained again on the same GPU model, with seeds 42 and 43.
| Head | nDCG@10, no cap | nDCG@10, 64/256 | Non-zero, query / document | FLOPS |
|---|---|---|---|---|
| Probability, threshold 1/64, no regulariser | 0.603 / 0.609 | 0.603 / 0.609 | 17 / 74, 20 / 78 | 0.36 / 0.75 |
| Probability, threshold 1/256, no regulariser (seed 42) | 0.593 | 0.593 | 22 / 88 | 1.93 |
| Shifted, FLOPS weight 3.33e-5 | 0.640 / 0.645 | 0.614 / 0.630 | 106 / 485, 92 / 453 | 6.10 / 6.60 |
| Shifted, FLOPS weight 3e-4 (seed 42) | 0.623 | 0.620 | 91 / 244 | 2.18 |
| SAE, frozen | 0.635 / 0.641 | 0.637 / 0.643 | 113 / 228, 112 / 224 | 5.43 / 6.19 |
- At this size the probability head is behind. Over both seeds it is 0.036 below the shifted head (0.027 to 0.046, over queries) and 0.032 below the SAE head (0.022 to 0.041). With the vectors capped at 64 and 256 weights it is 0.016 below the shifted head and 0.034 below the SAE head.
- Its vectors are far smaller, and a lower threshold does not help. A document has about 75 entries, against 450 to 485 for the shifted head and about 225 for the SAE head, and a query about 20 against about 100. With a threshold of 1/256 the FLOPS rises fivefold, the documents gain 14 entries and the accuracy falls by 0.010. No shifted or SAE run of this size exists at a comparable FLOPS, so these runs do not say how the heads compare at equal cost; the shifted head with half its usual entries (weight 3e-4) is 0.020 ahead at seed 42.
- Why is not known. One reading is that the larger encoder's distributions are sharper, so that a token keeps little besides its own entry and queries are hardly expanded. A temperature above 1 (
temperature) would test that, and was not tried. - The repeated runs agree with the section above. The shifted head and the SAE head are again within 0.005 of each other without a cap, with a second seed.
What limits these results: one benchmark, 2,000 steps, two seeds, and intervals that cover the choice of queries only. The runs without a regulariser and all 310M runs of this section were made with USE_HUB_KERNELS=NO, after anonymous requests for a kernel from the Hugging Face Hub were rate-limited; the runs they are compared with did not set it, and the 310M reference runs used an earlier version of the code. The head is also slower to train: on the small encoder 2,000 steps took 11.4 minutes against 8.6 for the shifted head under otherwise equal conditions, and on the 310M encoder 43 minutes against 27, where the conditions differ as just described.