NVIDIA-Merlin / Transformers4Rec

Transformers4Rec is a flexible and efficient library for sequential and session-based recommendation and works with PyTorch.
https://nvidia-merlin.github.io/Transformers4Rec/main
Apache License 2.0
1.08k stars 142 forks source link

[BUG] Recall@1 higher than Recall@5 and Recall@10 #700

Closed petruzzellialessandro closed 1 year ago

petruzzellialessandro commented 1 year ago

Bug description

During training and evaluation the Recall@1 is higher than Recall@5 and Recall@10

Steps/Code to reproduce bug

That's I set up the task

body = tr.SequentialBlock(
    inputs,
    tr.TransformerBlock(
        transformer_config, masking = inputs.masking
    )

)
head = tr.Head(
    body,
    tr.NextItemPredictionTask(weight_tying=True,
                                metrics=[RecallAt(top_ks=[1, 5, 10], labels_onehot=True),  
                                        NDCGAt(top_ks=[5, 10], labels_onehot=True)]
                             ),
)
model = tr.Model(head)

input is obtained using the following code

sequence_length = 1900
d_model = 128
inputs = tr.TabularSequenceFeatures.from_schema(
        schema,
        max_sequence_length = sequence_length,
        masking = 'mlm',
        d_output = d_model,
        aggregation = "concat"
)
inputs

where the schema only contains the item_id-list

Expected behavior

Recall@5 and Recall@10 should be <= Recall@1. I get the following results aflter some epochs

{'eval_ /next-item/recall_ at 1': 0.07417218387126923, 
'eval_/next-item/recall at 5': 0.014403973706066608, 
'eval_ /next-item/recall at 10': 0.02433774806559086, 
'eval_/next-item/ndcg_at 5': 0.008305514231324196, 
'eval_ /next-item/ndcg_at 10': 0.011453937739133835, 
'eval_/loss': 7.5158371925354, "eval_runtime: 69.1242, 
'eval_samples_per_ second' : 87.495, 
'eval_steps_per second' : 2.734}

Environment details