Skip to content

[BUG] TopK metrics are wrong when model predicts same value for all items. #617

@bschifferer

Description

@bschifferer

Bug description

When the model predicts a constant value, the topk metrics scores perfect.

When the model predicts the same value for all items, the sort order doesn't change
https://github.com/NVIDIA-Merlin/models/blob/main/tests/unit/tf/metrics/test_metrics_topk.py#L53

The negative sampler creates the batches by putting the positive item on the first position and the negatives on the next ones:

predictions = tf.concat([positive_scores, negative_scores], axis=-1)

In that way, we get perfect scores by predicting a constant.

Steps/Code to reproduce bug

Based on the unttest

labels = tf.convert_to_tensor([[0, 1, 0, 1, 0], [1, 0, 0, 1, 0], [0, 0, 0, 0, 1]], tf.float32)
predictions = tf.convert_to_tensor(
    [[10, 10, 10, 10, 10], [5, 5, 5, 5, 5], [6, 6, 6, 6, 6]], tf.float32
)
label_relevant_counts = tf.convert_to_tensor([2, 2, 1], tf.float32)
print(labels)
predictions, labels, label_relevant_counts = extract_topk(5, predictions, labels)
print(labels)

Metadata

Metadata

Labels

P0bugSomething isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions