Fix LMF Negative Sampling to Sample Uniformly#747
Open
Fazel94 wants to merge 2 commits intobenfred:mainfrom
Open
Fix LMF Negative Sampling to Sample Uniformly#747Fazel94 wants to merge 2 commits intobenfred:mainfrom
Fazel94 wants to merge 2 commits intobenfred:mainfrom
Conversation
Bug A: item_vectors.shape[1] returned n_factors+2, not n_items. Fix: use shape[0]. Bug B: RNGVector range was [0, nnz-1] and i = indices[index] only samples from already-interacted items (popularity-biased, never zero-interaction items). Fix: sample i directly from [0, n_items). Bug C: outer negative-sample loop and inner factor loops all used as the loop variable. Each inner loop left _ == n_factors, so the outer loop ran at most once regardless of neg_prop. Fix: use f for inner factor loops. Bug D: a single RNG seeded with nnz-1 was shared by the user-update pass (needs item IDs) and item-update pass (needs user IDs). Fix: two separate RNGVector instances with correct ranges.
test_cluster_recovery – overall in-cluster precision >= 0.70 (A+B+C+D) test_n_items_dimension – catalogue size, not n_factors+2, used as loop bound (A) test_negatives_not_in_user_positives – negative gradient term uses true negatives (B) test_negative_loop_variable_shadowing – neg_prop=5 outperforms neg_prop=1 (C) test_separate_rngs_for_user_and_item_update – both factor matrices finite + precise (D)
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.
Fix four bugs in lmf_update that gutted negative sampling
The negative sampling loop in lmf_update had four bugs that together
meant the model was barely seeing true negatives:
capping the negative loop at ~34 regardless of catalogue size
items — never zero-interaction ones, and popularity-biased on top
_got clobbered by the inner factor loops,so it ran once instead of neg_prop * seen_items times
item-update passes; each needs its own with the correct range
Fix: shape[0] for n_items, sample item/user IDs directly from [0, n)
with rejection for positives, distinct loop variables, two RNGVectors.
Added five regression tests covering each bug and the overall cluster
recovery behavior.
AI use disclosure:
I have used LLMs extensively for understanding the issue, cleaning up and generating comments for my code and pr.
I have written the code and am responsible for it.