Course / Lectures / Lecture 07 / Lab Lab 07

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.

~12 min play Semantic loss λ · gradient descent No install · runs in the browser

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.

A + B = 5 P(constraint) = — · semantic loss = —

Training

Data loss—
Logic loss—
Total—
MAP pair—

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.

What this shows — and what it does not

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.

← Read the semantic loss · Back to Lecture 07 · Slides →