Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix recall metric calculation #779

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sungho-ham
Copy link

Goals ⚽

  • Fix recall metric error when batch size is 1

Implementation Details 🚧

rel_indices = (num_relevant != 0).nonzero().squeeze()

The squeeze() function removes all dimensions when batch size is 1.
I've added dim=1 argument to keep dimension along batch.

Testing Details 🔍

Test code for error reproduction

import torch
from transformers4rec.torch import ranking_metric

ks = [1, 2]
scores = torch.tensor( [ [1,2,3], ])
labels = torch.tensor( [ [0,1,0], ])
ranking_metric.RecallAt()._metric(ks, scores, labels)

Error message

    135 rel_indices = (num_relevant != 0).nonzero().squeeze()
    136 rel_count = num_relevant[rel_indices]
--> 138 if rel_indices.shape[0] > 0:
    139     for index, k in enumerate(ks):
    140         rel_labels = topk_labels[rel_indices, : int(k)]

IndexError: tuple index out of range

Copy link

copy-pr-bot bot commented May 14, 2024

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

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.

None yet

1 participant