Skip to content

Fix infinite loop in _neg_sample when item_set covers all items#2210

Open
he-yufeng wants to merge 1 commit intoRUCAIBox:masterfrom
he-yufeng:fix/neg-sample-infinite-loop
Open

Fix infinite loop in _neg_sample when item_set covers all items#2210
he-yufeng wants to merge 1 commit intoRUCAIBox:masterfrom
he-yufeng:fix/neg-sample-infinite-loop

Conversation

@he-yufeng
Copy link

Summary

Root Cause

When MAX_ITEM_LIST_LENGTH exceeds the number of unique items in the dataset (e.g., 100 vs 10 items), a user's masked sequence can contain all valid item IDs. The while item in item_set loop then never terminates.

Test plan

  • Verify existing tests pass
  • Test with a small dataset where a user's sequence contains all item IDs

🤖 Generated with Claude Code

When a user's interaction sequence contains all possible item IDs
(1 to n_items-1), the while loop in _neg_sample could never terminate
because no valid negative sample exists. This adds a guard check
before the loop and returns 0 (padding index) as a fallback.

Also converts item_set to a set for O(1) membership lookups.

Fixes RUCAIBox#2193

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

_neg_sample in MaskItemSequence causes infinite loop when item_set contains all items from 1 to n_items - 1."

1 participant