fix: add epsilon to prevent ZeroDivisionError in BPR-based models#686
Merged
qtuantruong merged 1 commit intoPreferredAI:masterfrom Apr 3, 2026
Merged
Conversation
The BPR zero-division fix (+ 1e-8) was previously applied to recom_bpr.pyx but not to other models that use the same pattern: - cornac/models/companion/recom_companion.pyx - cornac/models/comparer/recom_comparer_sub.pyx - cornac/models/lrppm/recom_lrppm.pyx When all samples are skipped (e.g., on very small datasets), the denominator (n_samples - skipped) becomes 0, causing a ZeroDivisionError during training progress display. Related to PreferredAI#675
Member
|
LGTM, thanks! |
qtuantruong
approved these changes
Apr 3, 2026
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.
Related to #675
Problem
The ZeroDivisionError fix (
+ 1e-8in the denominator) was applied torecom_bpr.pyxbut not to three other models that use the same progress-reporting pattern. When all samples are skipped (e.g., very small datasets), the denominator(n_samples - skipped)becomes 0.Fix
Added
+ 1e-8to the denominator in:cornac/models/companion/recom_companion.pyxcornac/models/comparer/recom_comparer_sub.pyxcornac/models/lrppm/recom_lrppm.pyxConsistent with the existing fix in
recom_bpr.pyx(line 199).