A constraint is a prior.
Two digit distributions, one sum constraint, and a soft penalty. Train with the data alone, then add the logic. Watch the mass move — and watch what it costs.
The soft-constraint lab
Digit A · p(a)
The observed label is the orange bar. The model is a softmax over six digits.
Digit B · p(b)
The observed label is the orange bar. The constraint links the two distributions.
Training
Choose a preset and press Train 200.
With λ = 0 the model fits the data. With λ > 0 the constraint competes with the data. The MAP pair is the model's best guess, not a guaranteed solution.
It shows the semantic-loss gradient on a six-by-six constraint, with an exact computation of P(A + B = 5). It does not show a hard guarantee: a soft penalty can leave mass on violations, or satisfy the constraint while ignoring the data. The point is the trade-off, not a solved benchmark.