Antevisão · Latent Rehearsal
18

Searching better
does not fix the energy

Chapter 16 showed that the energy search did not find the minimum and built an exact search. This chapter measures what the exact search does to the text, and the result points somewhere else: the trade-off between following the heading and writing something plausible is set by the energy, not by where one searches.

Chapter 18 Prerequisite: 16 (the minimum and the volume) and 12 (costs and inference modes)

1 The question chapter 16 left

In energy mode, the generator picks each token in two steps. First it builds a short list of candidates. Then it imagines, in latent space, where each candidate would take the text, and gives each one an energy with two terms: how far the predicted state lies from the requested heading, and how improbable the token is according to the token head itself.

E(a) = 1 − cos(Pred(zt, ea), heading) + γ · (−log p(a))

Chapter 16 showed that the short list — the 8 most probable tokens — often does not contain the lowest-energy token: at γ = 0 this happens in all 96 positions measured. The response was a new mode, todos (all), which computes the energy of each of the 16,392 tokens in the vocabulary and takes the lowest. One question remained, the first on that chapter's list of open questions: does finding the true minimum improve the text, or only lower the energy?

2 A defect found along the way

The first measurement came out odd. At γ = 0.1, the todos mode gave a heading affinity of 0.780, well above anything chapter 12 had measured, but with perplexity 491; in energy mode without a cost head perplexity reached 2,098. The sweep in chapter 16 said that at γ = 0.1 the true minimum is already among the 8 most probable tokens in 85% of positions. A search that finds the minimum should not produce text so much worse than the short list.

The reason was in the code. The function that orders the vocabulary (_todos_por_energia, in server/ours.py) used only the heading term and left out the γ · (−log p) term. The eight candidates were therefore the minima of the pure heading — the syllable fragments that chapter 16 §5 showed no policy would pick — and γ only reordered that set. At γ = 0 both orderings coincide, which is why the measures in chapter 16, taken by model/inference.py with the whole energy, do not change.

The ordering now uses the whole energy, the same one inference.py measures. Every number below is after the fix.

3 Three places to search, the same trade-off

To see whether where one searches is what matters, we compared three search sets, always choosing by the same energy:

  1. policy: the 8 most probable tokens (the usual behaviour);
  2. whole vocabulary: all 16,392 tokens (the todos mode);
  3. nucleus: only the tokens that, summed from the most probable down, cover a fraction of the probability — the same idea as nucleus sampling (top-p). The search is exact inside it. This is the new nucleo mode, with the mass in nucleus_mass.

The idea behind the nucleus was to keep a firm plausibility constraint, like the short list's, and search for the exact minimum inside it.

Modes table (model/modes.py), model mini-moderno-reg1-wm1-sz1-duelo, 4 prompts × 32 tokens, heading "futebol gol campeonato". Affinity: probability that the text is about the heading, given by a cost head from another model (reg1-lat1o), so the generator does not judge itself; higher = more on course. PPL: perplexity of the text under the generator itself; lower = more plausible. Guardrail: fraction of numeric tokens on the prompt "Em 1999, o total foi de" with the "sem-numeros" head applied to the real state, 3 seeds. One generation seed in the first two column pairs.
where it searchesγenergy: affinityPPLhead + real state: affinityPPLguardrail: digitsPPL
no heading (free)—0.25648.50.25648.540.6%10.7
policy, top-80.10.20019.80.35536.727.6%26.1
nucleus, 50% of the mass0.10.450694.50.48084.20.0%75.6
nucleus, 80% of the mass0.10.351421.80.47683.40.0%247.2
whole vocabulary0.10.351421.80.47683.40.0%247.2
policy, top-800.357293.10.48882.40.0%144.7
nucleus, 50% of the mass00.2501,008.40.751639.00.0%275.7
whole vocabulary00.2645,363.40.841853.50.0%625.3

The middle columns, those of the best heading configuration (cost head applied to the real state), give the answer. The four bold rows land at practically the same point: affinity between 0.476 and 0.488, perplexity between 82 and 84. Three of them are the three searches at γ = 0.1; the fourth is the usual short list at γ = 0. Searching the nucleus or the whole vocabulary at γ = 0.1 takes the text exactly where lowering γ already took it.

Put another way: there is a trade-off between following the heading and writing plausible text. Lowering γ moves along that trade-off; searching better also moves along it, and does not shift it. None of the searches bought more heading for the same price in perplexity.

One small exception is worth recording: on the guardrail, the 50% nucleus zeroes the digits at perplexity 75.6, against 144.7 for the short list at γ = 0 and 247.2 for the whole vocabulary. It is a 3-seed measure on a single prompt, and it stands as a lead to repeat, not as a result.

4 Why the searches tie

The rows for the 80% nucleus and the whole vocabulary are not similar: they are identical, to the third decimal. That is not a defect; it is what two measurements already taken predict together.

The first is the γ sweep, taken with model/inference.py over 96 validation positions. It says how often the lowest-energy token is among the policy's k most probable:

Top-k policy coverage of the exact energy minimum, heading "futebol gol campeonato", 6 sequences × 16 positions. "Actions within 5%": how many tokens fall within 5% of the lowest energy (the "multiple answers" of chapter 16 §5). The γ = 0, 0.1 and 1 rows repeat 16 §4 number for number.
γk = 1k = 8k = 32k = 128energy lost in top-8actions within 5%
00.0%0.0%0.0%9.4%+35.9%35.5
0.010.0%2.1%10.4%21.9%+22.4%43.0
0.021.0%9.4%24.0%47.9%+13.8%40.4
0.0521.9%61.5%83.3%92.7%+3.9%11.1
0.133.3%85.4%97.9%100.0%+1.2%4.1
0.256.2%96.9%100.0%100.0%+0.1%2.3
0.583.3%100.0%100.0%100.0%0.0%1.5
190.6%100.0%100.0%100.0%+0.0%1.4

The second is the size of the nucleus. The mini policy is flat: its probability spreads over many tokens.

How many tokens the policy needs to cover each fraction of the probability, 8 sequences × 64 validation positions.
nucleus massmedianmean90% of positions up to
50%71198572
80%2,0172,1484,427
90%5,3675,0798,062
95%8,8188,25310,996

Together they explain the tie. At γ = 0.1, the lowest-energy token is among the 128 most probable in every position. An 80% nucleus holds about 2,000 tokens and a 95% one almost 9,000; both contain the same eight lowest-energy tokens as the whole vocabulary. The searches differ; the candidates they return do not.

5 What holds plausibility is rank, not mass

The table in §3 therefore has a more precise reading than "the short list is better". What makes the short list produce plausible text is the cut by rank: no token below the eighth most probable gets in. The tokens the energy prefers at γ = 0.1 are almost always between rank 9 and rank 128 of the policy — inside any reasonable nucleus, but outside the short list — and that is where the perplexity of 83 comes from.

The γ · (−log p) term does not imitate that cut. A token at rank 50 has low probability, but not low enough for the term to outweigh the gain on the heading when γ is small. When γ is high the term weighs enough, and the energy goes back to being almost the policy itself (16 §4 showed this at γ = 1). In our energy, plausibility lives in a continuous term, and what worked was a cut.

What this chapter shows

Searching better does not shift the trade-off between heading and plausibility. With three different searches — exact over the vocabulary, exact inside the nucleus, and the short list with a lower γ — the text lands at the same point. What decides where the text lands is the energy: at low γ it considers cheap what the policy finds unlikely. The exact search remains useful for measuring how much the short list leaves out (chapter 16); to generate better text, the piece to change is the energy.

6 What changed in the code

Additive changes: the generator's default is still the policy's short list.
wherewhat changed
server/ours.py, _todos_por_energiafix: the vocabulary ordering uses the whole energy, with γ · (−log p). At γ = 0 nothing changes
server/ours.py, _nucleo_por_energianew candidate mode, nucleo (nucleus): exact search only among the tokens of the policy's nucleus; mass in nucleus_mass (default 0.95); the trajectory records the nucleus size at each step
model/modes.py--candidates nucleo and --nucleus-mass

7 Limits of this measurement

Open questions
References

The sources of the ideas used here. The numbers were measured in the project.

  1. LeCun, Y., Chopra, S., Hadsell, R., Ranzato, M. and Huang, F. J. (2006). A Tutorial on Energy-Based Learning. In Predicting Structured Data, MIT Press. yann.lecun.com/exdb/publis/pdf/lecun-06.pdf
  2. LeCun, Y. (2022). A Path Towards Autonomous Machine Intelligence. OpenReview. openreview.net/forum?id=BZ5a1r-kVsf
  3. Holtzman, A., Buys, J., Du, L., Fang, M. and Choi, Y. (2020). The Curious Case of Neural Text Degeneration. ICLR 2020 (nucleus sampling, top-p). arXiv:1904.09751
  4. Chapter 16 of this collection, The minimum and the volume: coverage, energy lost and the exact search.

Measured on CPU on 17/09/2026. Data in out/cpu_1709/.