Repository navigation
fix: implement label smoothing in LabelSmoothingLoss.forward - #458
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
LabelSmoothingLoss.forward(dicee/losses/custom_losses.py) ignoredself.smoothness_ratioentirely and was byte-for-byte identical toDefaultBCELoss, soloss_fn="LS"silently trained with plain BCE regardless oflabel_smoothing_rate.CombinedLSandLRandAggregatedLSandLRinherited the same no-op since both delegate toLabelSmoothingLossfor their smoothing term/branch.AdaptiveLabelSmoothingLoss.forward(converts logits to log-probabilities, redistributessmoothness_ratiomass from the target class(es) to the non-target classes,KL(pred || smoothed_target)), per the fix suggested in the issue.CombinedLSandLR/AggregatedLSandLRdocstrings,dicee/config.py'slabel_smoothing_ratedocstring, andCLAUDE.md.tests/test_unit_custom_losses.py::TestLabelSmoothingLoss, which previously pinned the buggy no-op behavior, to instead assert the loss matches theAdaptiveLabelSmoothingLossformula at a fixed ratio and that the loss actually varies withsmoothness_ratio.Fixes #453
Test plan
pytest tests/test_unit_custom_losses.py -v— 37 passedpytest tests/test_unit_base_model.py -q— 60 passedruff check dicee/losses/custom_losses.py dicee/config.py tests/test_unit_custom_losses.py --line-length=200— clean🤖 Generated with Claude Code