Skip to content

fix: implement label smoothing in LabelSmoothingLoss.forward - #458

Merged
Demirrr merged 1 commit into
developfrom
fix/label-smoothing-loss-453
Sep 16, 2026
Merged

Demirrr merged 1 commit into
developfrom
fix/label-smoothing-loss-453

Conversation

@Demirrr

@Demirrr Demirrr commented Sep 16, 2026

Copy link
Copy Markdown
Member

Summary

  • LabelSmoothingLoss.forward (dicee/losses/custom_losses.py) ignored self.smoothness_ratio entirely and was byte-for-byte identical to DefaultBCELoss, so loss_fn="LS" silently trained with plain BCE regardless of label_smoothing_rate. CombinedLSandLR and AggregatedLSandLR inherited the same no-op since both delegate to LabelSmoothingLoss for their smoothing term/branch.
  • Implements the same fixed-rate KL-divergence smoothing formula already used correctly in AdaptiveLabelSmoothingLoss.forward (converts logits to log-probabilities, redistributes smoothness_ratio mass from the target class(es) to the non-target classes, KL(pred || smoothed_target)), per the fix suggested in the issue.
  • Removes now-stale "no-op bug" notes from CombinedLSandLR/AggregatedLSandLR docstrings, dicee/config.py's label_smoothing_rate docstring, and CLAUDE.md.
  • Updates tests/test_unit_custom_losses.py::TestLabelSmoothingLoss, which previously pinned the buggy no-op behavior, to instead assert the loss matches the AdaptiveLabelSmoothingLoss formula at a fixed ratio and that the loss actually varies with smoothness_ratio.

Fixes #453

Test plan

  • pytest tests/test_unit_custom_losses.py -v — 37 passed
  • pytest tests/test_unit_base_model.py -q — 60 passed
  • ruff check dicee/losses/custom_losses.py dicee/config.py tests/test_unit_custom_losses.py --line-length=200 — clean

🤖 Generated with Claude Code

LabelSmoothingLoss.forward ignored self.smoothness_ratio entirely and
was byte-for-byte identical to DefaultBCELoss, so loss_fn="LS" silently
trained with plain BCE regardless of label_smoothing_rate. Same for
CombinedLSandLR/AggregatedLSandLR, which delegate to it.

Implement the same fixed-rate KL-divergence smoothing formula already
used correctly in AdaptiveLabelSmoothingLoss.forward, and update the
tests that had pinned the buggy no-op behavior to instead verify
smoothing actually varies the loss.

Fixes #453

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@Demirrr
Demirrr merged commit f105db6 into develop Sep 16, 2026
7 checks passed
@Demirrr
Demirrr deleted the fix/label-smoothing-loss-453 branch September 16, 2026 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LabelSmoothingLoss (loss_fn="LS") doesn't apply label smoothing — identical to plain BCE

1 participant