Normalized Concentration-Corrected Token-Weighted Reconstruction

Back to reconstruction weighting and normalization

This note records an under-consideration token-level reconstruction variant that combines:

  • tempered token-level surprisal-share weighting to focus reconstruction inside each example,
  • concentration correction to cancel the scale inflation induced when surprisal is concentrated on a short prefix,
  • the same distribution-level z-free reference scale cbasec_\mathrm{base} used by Distribution-Level Z-Free-Relative Reconstruction Rescaling.

The intended role of this objective is:

focus reconstruction pressure on the most informative tokens within each example, while keeping the overall reconstruction term on the same scale as the ordinary uniform-token reconstruction loss.

Setup

Let the supervised y-region contain ∣S(x,y)∣|S(x, y)| active token positions. For one example (x,y)(x, y), define:

  • z-conditioned per-token loss: ℓt(x,y)=−log⁡pψ(yt∣x,z,y<t),\ell_t(x, y) = -\log p_\psi(y_t \mid x, z, y_{<t}),
  • z-free base-model surprisal: bt(x,y)=−log⁡pbase(yt∣x,y<t),b_t(x, y) = -\log p_\mathrm{base}(y_t \mid x, y_{<t}),
  • uniform mean z-free loss: μ(x,y)=bu(x,y)=1∣S(x,y)∣∑t∈S(x,y)bt(x,y),\mu(x, y) = b_u(x, y) = \frac{1}{|S(x, y)|}\sum_{t \in S(x, y)} b_t(x, y),
  • distribution-level z-free reference scale: cbase=E(x,y)∼D[bu(x,y)].c_\mathrm{base} = \mathbb{E}_{(x, y)\sim D}[b_u(x, y)].

For compactness, define masked raw moments of the z-free token surprisal:

mr(x,y)=1∣S(x,y)∣∑t∈S(x,y)bt(x,y)r.m_r(x, y) = \frac{1}{|S(x, y)|}\sum_{t \in S(x, y)} b_t(x, y)^r.

Then m1=μm_1 = \mu.

Implementation detail

In the current codebase, the z-free token losses bt(x,y)b_t(x, y) are already computed during token-level weighting from a frozen reference model, aligned to the conditioned sequence. So the extra quantities introduced here can be computed from the same aligned per-token z-free losses without an additional forward pass.

Raw token-weighted reconstruction

Let the tempered token-level surprisal-share weights be

πt(α)(x,y)=bt(x,y)α∑s∈S(x,y)bs(x,y)α,α≥0,\pi_t^{(\alpha)}(x, y) = \frac{b_t(x, y)^\alpha}{\sum_{s \in S(x, y)} b_s(x, y)^\alpha}, \qquad \alpha \ge 0,

with α=0\alpha = 0 interpreted by continuity as uniform token weighting.

The corresponding token-weighted reconstruction is

Rtok,α(x,y)=∑t∈S(x,y)πt(α)(x,y) ℓt(x,y).R_{\mathrm{tok},\alpha}(x, y) = \sum_{t \in S(x, y)} \pi_t^{(\alpha)}(x, y)\,\ell_t(x, y).

At the z-free baseline, where ℓt(x,y)=bt(x,y)\ell_t(x, y)=b_t(x, y), this becomes

Rtok,αbase(x,y)=∑tπt(α)bt=mα+1(x,y)mα(x,y).R_{\mathrm{tok},\alpha}^{\mathrm{base}}(x, y) = \sum_t \pi_t^{(\alpha)} b_t = \frac{m_{\alpha+1}(x, y)}{m_\alpha(x, y)}.

This is the base-model token loss after reweighting toward tokens with large btαb_t^\alpha.

Concentration factor

The corresponding token concentration factor is defined as

κα(x,y)=Rtok,αbase(x,y)bu(x,y)=mα+1(x,y)mα(x,y) m1(x,y).\kappa_\alpha(x, y) = \frac{R_{\mathrm{tok},\alpha}^{\mathrm{base}}(x, y)}{b_u(x, y)} = \frac{m_{\alpha+1}(x, y)}{m_\alpha(x, y)\,m_1(x, y)}.

This measures how much the α\alpha-tempered token weighting inflates the z-free base loss relative to ordinary uniform token averaging.

Important properties:

  • κ0(x,y)=1\kappa_0(x, y)=1,
  • κα(x,y)≥1\kappa_\alpha(x, y)\ge 1 for all α≥0\alpha \ge 0,
  • κα\kappa_\alpha increases as surprisal becomes more concentrated,
  • increasing α\alpha makes κα\kappa_\alpha weakly larger, because more weight is placed on high-surprisal tokens.

For α=1\alpha=1,

Rtok,1base(x,y)=m2(x,y)m1(x,y)=μ(x,y)(1+CV(b)2),R_{\mathrm{tok},1}^{\mathrm{base}}(x, y) = \frac{m_2(x, y)}{m_1(x, y)} = \mu(x, y)\left(1+\mathrm{CV}(b)^2\right),

where CV(⋅)\mathrm{CV}(\cdot) is the coefficient of variation CV=σ/μ\mathrm{CV} = \sigma / \mu, so

κ1(x,y)=1+CV(b)2.\kappa_1(x, y)=1+\mathrm{CV}(b)^2.

Thus κ1\kappa_1 is the factor by which linear surprisal-share weighting amplifies the z-free base loss relative to uniform token averaging.

Concentration-corrected reconstruction

Define the concentration-corrected token-weighted reconstruction

R~tok,α(x,y)=Rtok,α(x,y)κα(x,y).\widetilde R_{\mathrm{tok},\alpha}(x, y) = \frac{R_{\mathrm{tok},\alpha}(x, y)}{\kappa_\alpha(x, y)}.

At the z-free baseline,

R~tok,αbase(x,y)=Rtok,αbase(x,y)κα(x,y)=bu(x,y).\widetilde R_{\mathrm{tok},\alpha}^{\mathrm{base}}(x, y) = \frac{R_{\mathrm{tok},\alpha}^{\mathrm{base}}(x, y)}{\kappa_\alpha(x, y)} = b_u(x, y).

So the concentration correction restores the same per-example baseline scale as the uniform-token reconstruction loss.

Equivalently, the corrected loss can be written as

R~tok,α(x,y)=bu(x,y) ∑tbt(x,y)α ℓt(x,y)∑tbt(x,y)α+1.\widetilde R_{\mathrm{tok},\alpha}(x, y) = b_u(x, y)\, \frac{\sum_t b_t(x, y)^\alpha \,\ell_t(x, y)}{\sum_t b_t(x, y)^{\alpha+1}}.

This form makes the main caveat explicit:

  • within each example, the relative token emphasis is still determined by btαb_t^\alpha,
  • but across examples, the correction introduces an implicit example-level weight 1/κα(x,y)1 / \kappa_\alpha(x, y).

So this is not a purely token-level intervention. It is a token-level weighting rule plus a concentration-dependent example-level correction.

Distribution-normalized form

Finally, define the normalized concentration-corrected token-weighted reconstruction

R^tok,α(x,y)=R~tok,α(x,y)cbase.\widehat R_{\mathrm{tok},\alpha}(x, y) = \frac{\widetilde R_{\mathrm{tok},\alpha}(x, y)}{c_\mathrm{base}}.

At the z-free baseline,

R^tok,αbase(x,y)=bu(x,y)cbase.\widehat R_{\mathrm{tok},\alpha}^{\mathrm{base}}(x, y) = \frac{b_u(x, y)}{c_\mathrm{base}}.

Taking expectation over the data distribution gives

E(x,y)∼D[R^tok,αbase(x,y)]=E[bu(x,y)]cbase=1.\mathbb{E}_{(x, y)\sim D}\left[\widehat R_{\mathrm{tok},\alpha}^{\mathrm{base}}(x, y)\right] = \frac{\mathbb{E}[b_u(x, y)]}{c_\mathrm{base}} = 1.

So this objective has two useful normalization properties:

  • per example, concentration correction restores the same z-free baseline scale as ordinary uniform reconstruction;
  • in expectation over examples, the additional division by cbasec_\mathrm{base} makes the baseline value equal to 11.

Interpretation

This objective can be read as follows:

  • the raw token-weighted loss focuses attention on high-residual-surprisal positions;
  • the concentration factor κα\kappa_\alpha removes the scale inflation caused purely by surprisal being concentrated on a small subset of tokens;
  • the outer division by cbasec_\mathrm{base} expresses the result in the same distribution-level z-free-relative units used by the standard normalized reconstruction loss.

That makes R^tok,α\widehat R_{\mathrm{tok},\alpha} a natural candidate if the design goal is:

concentrate reconstruction pressure inside each example without changing the basic reconstruction scale just because surprisal mass is concentrated on a short prefix.

Useful structural properties

This objective family has several useful structural properties.

One of them is continuity at α=0\alpha = 0:

πt(0)=1∣S∣,κ0=1,R^tok,0(x,y)=bu(x,y)cbase.\pi_t^{(0)} = \frac{1}{|S|}, \qquad \kappa_0 = 1, \qquad \widehat R_{\mathrm{tok},0}(x, y) = \frac{b_u(x, y)}{c_\mathrm{base}}.

So the family reduces exactly to distribution-level normalized uniform-token reconstruction when α=0\alpha = 0.

This makes α\alpha a clean concentration knob:

  • α=0\alpha=0: ordinary distribution-normalized reconstruction,
  • α=1\alpha=1: concentration-corrected linear surprisal-share weighting,
  • α>1\alpha>1: stronger focus on the highest-surprisal tokens.

Two other important properties are:

  • the raw token-weighted loss still concentrates reconstruction pressure within each example according to the token-level surprisal-share rule defined by α\alpha;
  • the concentration correction and outer division by cbasec_\mathrm{base} keep the resulting objective on the same baseline scale as ordinary distribution-normalized reconstruction: per example at the z-free baseline it reduces to bu(x,y)b_u(x, y), and in expectation it reduces to 11 after dividing by cbasec_\mathrm{base}.

Main caveat

The main caveat is that the concentration correction changes more than scale.

Because each example is divided by κα(x,y)\kappa_\alpha(x, y), examples with more concentrated surprisal are downweighted relative to the raw token-weighted loss. This may be good if the uncorrected objective overemphasizes short strategy-revealing prefixes simply because they induce a large raw scale inflation. But it may also be undesirable if those same concentrated examples are exactly the ones where the latent variable should matter most.

So the concentration-corrected objective should be understood as a distinct methodological proposal, not merely a harmless re-expression of raw token weighting.

Current status in this repository

This variant is implemented as normalized_concentration_corrected_token_weighted_reconstruction_loss, one explicit term in the current reconstruction stack.

The current implementation computes the aligned per-token z-free baseline losses needed for:

  • Rtok,αR_{\mathrm{tok},\alpha},
  • bub_u,
  • κα\kappa_\alpha,
  • and therefore R^tok,α\widehat R_{\mathrm{tok},\alpha}.

The current code touchpoints are:

  • token-weight helper statistics in path:core/disentanglement/token_weighting.py,
  • scalar loss helper in path:core/disentanglement/losses.py,
  • discrete and continuous loss composition in path:core/disentanglement/shared_discrete_cvae.py and path:core/disentanglement/continuous_cvae.py,
  • CLI / trainer wiring in path:experiments/synthetic_sequences/disentangled/config.py, path:experiments/synthetic_sequences/disentangled/train_step.py, and path:experiments/synthetic_sequences/disentangled/train_disentangled.py.

In the current reconstruction stack, this objective is the normalized high-surprisal token-weighted term alongside the raw token-weighted term rather than a replacement for it. See Current implementation: normalized concentration-corrected token-weighted reconstruction.

Neighboring variants

Built with LogoFlowershow