Consistency learning
Quick answer
Consistency learning encourages a model to make similar predictions for label-preserving variations of the same input. It can use unlabeled training rows by constructing a target from one view and penalizing disagreement with another. Static examples tested locally with Python 3.13.5, scikit-learn 1.8.0 SciPy 1.17.0 and NumPy 2.3.5 where imported. ByteMind package execution is unverified.
Measure prediction disagreement
p=[80,20];q=[60,40]print(sum((a-b)**2 for a,b in zip(p,q))/10000)Observed local output:
0.08Percentages are converted to probabilities before interpreting squared error.
How it works
For an input x, create a weak augmentation a(x) and a stronger augmentation b(x). A typical objective combines supervised cross-entropy on labeled rows with lambda times a consistency loss on unlabeled rows. For two probability vectors p and q, a simple loss is sum((p_i−q_i)^2); for [0.8,0.2] versus [0.6,0.4] this is 0.08. Another approach forms a hard target from the weak view when confidence passes a threshold, then uses cross-entropy on the strong view. In a teacher-student design, the teacher target is treated as fixed for the student update; a teacher can be a slowly updated copy of model weights. These are families of objectives rather than one mandatory algorithm. Augmentation must preserve task semantics: a horizontal image flip may be acceptable for some object categories but not for text direction or left/right labels. If the augmentation changes the class, consistency penalizes valid differences. A constant predictor has zero consistency loss, so the supervised term or another constraint is essential to prevent trivial agreement. Tune the loss weight and acceptance rule on labeled development data. In the simple examples below, no gradient-based neural training is claimed.
Gate weak-view targets before strong-view loss
import mathweak=[[.95,.05],[.6,.4],[.1,.9]]strong=[[.8,.2],[.4,.6],[.3,.7]]loss=[-math.log(q[max(range(2),key=p.__getitem__)]) for p,q in zip(weak,strong) if max(p)>.8]print(len(loss),round(sum(loss)/len(loss),4))Observed local output:
2 0.2899Only two confident weak views supervise the strong views. The accepted-target mean is a stated reduction convention, not a universal algorithm default.
Common mistakes
Do not reward agreement without measuring correctness, assume every transformation is label-preserving, or fit an augmentation policy to final test labels. Low consistency loss is not evidence of high accuracy.
Practice and next steps
Compute squared disagreement for [0.7,0.3] and [0.9,0.1]. Then find a pair of wrong but identical predictions and explain why its loss is zero. Complete the knowledge check and staged exercise. Next: Contrastive and pretext objectives.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Consistency learning — knowledge check
Apply consistency learning to new scenarios.
What is the key augmentation assumption?
Can identical wrong predictions have zero consistency loss?
What is a teacher target typically treated as during a student update?
What is lambda used for?
Why confidence-gate weak predictions?