Skip to content

Uncertain Ground Truth

← Noisy Labels | Transform Losses →

These losses target settings where labels are noisy, partially trusted, weakly supervised, or augmented with pseudo labels.

API references

NoisyTargetGaussianNLL — noise-aware NLL with known target variance. PseudoLabelNLL — probabilistic self-training. ConsistencyRegLoss — student-teacher agreement. PseudoLabelConsistencyLoss — combined point-regression semi-supervision.

Available losses:

  • NoisyTargetGaussianNLL
  • ConsistencyRegLoss
  • PseudoLabelNLL
  • PseudoLabelConsistencyLoss

Related utilities:

  • torchregress.utils.generate_pseudo_labels
  • torchregress.utils.update_ema_teacher_

When To Use Which

Loss Start here when Main signal API
NoisyTargetGaussianNLL labels come with reported variance/error bars explicit target-noise variance NoisyTargetGaussianNLL
PseudoLabelNLL Gaussian head + pseudo labels + confidence weights probabilistic self-training PseudoLabelNLL
ConsistencyRegLoss you already have a trusted teacher prediction student-teacher agreement ConsistencyRegLoss
PseudoLabelConsistencyLoss you want pseudo labels plus teacher consistency in one point-regression loss supervised + pseudo-label + teacher consistency PseudoLabelConsistencyLoss

Objectives

Noise-aware Gaussian NLL

If the observed target has known variance \(\sigma_y^2\) and the model predicts \((\mu, \sigma_{pred}^2)\):

\[ \mathcal{L}_{noise} = \frac{1}{2}\log\!\left(2\pi(\sigma_{pred}^2 + \sigma_y^2)\right) + \frac{(y - \mu)^2}{2(\sigma_{pred}^2 + \sigma_y^2)}. \]

Consistency regularization

\[ \mathcal{L}_{consistency} = \lVert f_{student}(x) - \operatorname{sg}(f_{teacher}(x)) \rVert_2^2. \]

Semi-supervised composite loss

PseudoLabelConsistencyLoss is intentionally narrow: it is the loss for the common student-teacher semi-supervised regression pattern where you have:

  1. a labeled subset with real targets,
  2. an unlabeled subset with pseudo targets,
  3. an optional teacher prediction used for consistency regularization.

It combines:

\[ \mathcal{L} = \mathcal{L}_{sup} + \lambda_{pseudo}\,\mathcal{L}_{pseudo} + \lambda_{cons}\,\mathcal{L}_{consistency}, \]

with label_mask controlling which samples contribute to the supervised term and pseudo_confidence controlling how strongly unlabeled pseudo labels contribute.

API Examples

Known target uncertainty

import torch
from torchregress.losses import NoisyTargetGaussianNLL

loss_fn = NoisyTargetGaussianNLL()

mean = torch.randn(64, 1)
log_var = torch.randn(64, 1)
y_obs = torch.randn(64, 1)
y_obs_var = torch.rand(64, 1) * 0.05

loss = loss_fn((mean, log_var), y_obs, target_variance=y_obs_var)

Pseudo-label Gaussian training

from torchregress.losses import PseudoLabelNLL

loss_fn = PseudoLabelNLL(pseudo_weight=0.8)
loss = loss_fn(
    (mean, log_var),
    target,
    pseudo_target=pseudo_target,
    pseudo_confidence=pseudo_confidence,
    label_mask=label_mask,
)

Point-regression semi-supervision

from torchregress.losses import PseudoLabelConsistencyLoss

loss_fn = PseudoLabelConsistencyLoss(
    pseudo_weight=0.8,
    consistency_weight=0.25,
    confidence_threshold=0.35,
)
loss = loss_fn(
    student_pred,
    target_with_placeholders,
    pseudo_target=pseudo_target,
    pseudo_confidence=pseudo_confidence,
    teacher_pred=teacher_pred,
    label_mask=label_mask,
)

Unlabelled entries of target_with_placeholders may hold any placeholder, including NaN: entries outside label_mask are replaced (via torch.where) before the supervised term is evaluated, so they affect neither the loss nor its gradient. The same holds for PseudoLabelNLL.

Pseudo-label generation and EMA teacher update

from torchregress.utils import generate_pseudo_labels, update_ema_teacher_

pseudo_target, pseudo_confidence, accepted = generate_pseudo_labels(
    teacher_mean,
    log_variance=teacher_log_var,
    confidence_threshold=0.35,
)
update_ema_teacher_(ema_teacher, student, momentum=0.95)

Selection Bias / Propensity Support

NoisyTargetGaussianNLL, PseudoLabelNLL, and PseudoLabelConsistencyLoss support optional propensity_scores or propensity_weights so weak supervision can be combined with covariate-dependent label-observation correction.

Comparison Examples

Companion metrics (torchregress.metrics)

Evaluation for the same workflow lives in torchregress.metrics.uncertain (→ See Distribution metrics):

Metric Formula / meaning Use for
noisy_target_gaussian_nll(pred_mean, pred_variance, target, target_variance, *, min_variance=1e-8) Mean Gaussian NLL with total variance \(\sigma_i^2 + s_i^2\) (prediction + known measurement noise): \(\quad \tfrac12\!\left(\log(\sigma_i^2+s_i^2) + \frac{(y_i-\mu_i)^2}{\sigma_i^2+s_i^2} + \log 2\pi\right)\) Comparing NLLs fairly when targets carry different, known noise
consistency_error(student_pred, teacher_pred, *, p=2) Mean \(\lvert\mu - \mu_{\text{teacher}}\rvert^p\) (p=1 MAE, p=2 MSE — no root is taken) How much the student disagrees with its EMA teacher during pseudo-labeling
pseudo_label_acceptance_rate(pseudo_confidence, *, threshold=0.5) Fraction of pseudo-labels at or above threshold Threshold tuning for generate_pseudo_labels
uncertain_gt_metrics_report(*, pred_mean, pred_variance, target, target_variance, teacher_pred=None, pseudo_confidence=None) One-call report combining the above (keyword-only args) Standard summary for uncertain-GT experiments
from torchregress.metrics import uncertain_gt_metrics_report

report = uncertain_gt_metrics_report(
    pred_mean=mu,
    pred_variance=var,
    target=y_noisy,
    target_variance=y_var,
    teacher_pred=teacher_mu,      # optional
    pseudo_confidence=conf,       # optional
)  # {"NoisyTargetNLL": …, "ConsistencyMSE": …, "PseudoAcceptanceRate": …}

Limitations

  1. Confirmation bias in pseudo-labeling: Pseudo-labeling is prone to confirmation bias — the model repeatedly fits its own incorrect but confident predictions, amplifying errors over epochs. Use an EMA teacher (update_ema_teacher_), apply threshold gating on pseudo_confidence via generate_pseudo_labels, and never include pseudo-labeled samples in held-out validation/test splits.
  2. Hyperparameter sensitivity: confidence_threshold gates which pseudo-labels are trusted — too low admits noise, too high rejects most unlabeled data. Tune on a small held-out labeled set, not the unlabeled data.
  3. Target variance quality (NoisyTargetGaussianNLL): If target_variance is poorly estimated (e.g., guessed rather than measured), performance can be worse than standard GaussianNLLLoss. Only use when variance estimates are trusted more than the model's ability to learn them.
  4. PseudoLabelConsistencyLoss is intentionally narrow: It covers one common pattern (labeled subset + pseudo labels + teacher consistency). For richer semi-supervised workflows with multiple views, augmentation, or density-based weighting, use TeacherStudentTrainer from Semi-supervised API.

Practical Notes

Tip

Use NoisyTargetGaussianNLL when you trust the reported measurement uncertainty more than any teacher model.

Tip

Use PseudoLabelConsistencyLoss when you want a point-regression loss that explicitly matches the pseudo-label + teacher-consistency workflow. It is not meant to stand in for every semi-supervised regression method.

Confirmation Bias & Error Propagation

Pseudo-labeling is prone to confirmation bias — when a model repeatedly fits its own incorrect but highly confident predictions, amplifying errors over epochs. - Mitigation: Use an EMA teacher (via update_ema_teacher_) to smooth predictions, apply threshold gating on pseudo_confidence (e.g., via generate_pseudo_labels), and never include pseudo-labeled samples in the held-out validation or test splits. Always maintain a clean, fully-supervised evaluation set.

Hyperparameter sensitivity

  • Confidence threshold tuning: PseudoLabelNLL and PseudoLabelConsistencyLoss use confidence_threshold to gate which pseudo-labels are trusted. Setting this too low admits noisy pseudo-labels; setting it too high rejects most unlabeled data, negating the semi-supervised benefit. Tune on a small held-out labeled set, not the unlabeled data.
  • Target variance quality: NoisyTargetGaussianNLL requires target_variance to be reasonably accurate. If the target variance is poorly estimated (e.g., guessed rather than measured), the loss can perform worse than standard GaussianNLLLoss which learns variance from data. Only use when you trust the variance estimates more than the model's ability to learn them.

Next steps


References

# Reference
1 D.-H. Lee. "Pseudo-Label: The Simple and Efficient Semi-Supervised Learning Method for Deep Neural Networks." ICML Workshop, 2013.
2 S. Laine, T. Aila. "Temporal Ensembling for Semi-Supervised Learning." ICLR, 2017.
3 A. Tarvainen, H. Valpola. "Mean Teachers are Better Role Models." NeurIPS, 2017.