NVIDIA-Merlin / NVIDIA-Merlin/Transformers4Rec
[BUG] CausalLanguageModeling do not mask last input item
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.3k
- Forks
- 165
- Avg merge
- 1m
- Merged PRs (30d)
- 2
Description
Bug description
The clm masking for last item only do not mask last item in input.
It will cause using the embedding of the label instead of mask.
I think following code needs to be fixed.
https://github.com/NVIDIA-Merlin/Transformers4Rec/blob/348c9636399535c566d20e8ebff2b7aa0775f136/transformers4rec/torch/masking.py#L298
Steps/Code to reproduce bug
import torch
from transformers4rec.torch import masking
item_ids = torch.tensor([[1, 2, 0], ])
mask = masking.CausalLanguageModeling(hidden_size=10, train_on_last_item_seq_only=True)
masking_info = mask.compute_masked_targets(item_ids, training=True)
print(masking_info)
MaskingInfo(schema=tensor([[ True, True, False]]), targets=tensor([[2, 0, 0]]))
Expected behavior
MaskingInfo(schema=tensor([[ True, False, False]]), targets=tensor([[2, 0, 0]]))
Environment details
- Transformers4Rec version: 23.08.00
Additional context
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in transformers4rec/torch/masking.py around line 298 and run the provided PyTorch reproduction for CausalLanguageModeling with train_on_last_item_seq_only=True. Compare the current MaskingInfo schema with the expected output; done means the last input item is not masked and the reported result matches the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, pytorch
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100