Skip to content

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

@osmanhayek

Description

@osmanhayek

Hi there,

I’m having an issue with the _neg_sample function in transform.MaskItemSequence.

My dataset contains around 197,000 unique users but only 10 unique items. Unfortunately, when I set MAX_ITEM_LIST_LENGTH to 50 or 100, the code sometimes encounters a user with more than 100 interactions — and their last 100 interactions include all possible item IDs. As a result, the function ends up looping forever while trying to find a negative sample that isn’t in the user’s item set.

I also tried setting train_neg_sample_args to None, but the function still gets called during BERT4Rec training.

As a temporary fix, I modified _neg_sample so that if it fails to find a negative sample after 100 attempts, it returns [PAD] (i.e., 0).

Would this be considered an acceptable workaround for my situation?

Thanks,
Osman

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions