Skip to content

: pe tasks #2988

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions torchrec/metrics/auc.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,17 @@ def _compute_auc_helper(
# TODO - [add flag to set bining dyamically] for use with soft labels, >=0.039 --> 1, <0.039 --> 0
sorted_labels = torch.ge(sorted_labels, 0.039).to(dtype=sorted_labels.dtype)
sorted_weights = torch.index_select(weights, dim=0, index=sorted_indices)
cum_fp = torch.cumsum(sorted_weights * (1.0 - sorted_labels), dim=0)
cum_tp = torch.cumsum(sorted_weights * sorted_labels, dim=0)
auc = torch.where(
cum_fp[-1] * cum_tp[-1] == 0,
0.5, # 0.5 is the no-signal default value for auc.
torch.trapz(cum_tp, cum_fp) / cum_fp[-1] / cum_tp[-1],
)
if sorted_weights.numel() > 0:
cum_fp = torch.cumsum(sorted_weights * (1.0 - sorted_labels), dim=0)
cum_tp = torch.cumsum(sorted_weights * sorted_labels, dim=0)
auc = torch.where(
cum_fp[-1] * cum_tp[-1] == 0,
0.5, # 0.5 is the no-signal default value for auc.
torch.trapz(cum_tp, cum_fp) / cum_fp[-1] / cum_tp[-1],
)
else:
# if empty predictions, default value
auc = torch.tensor(0.5, device=sorted_weights.device)
return auc


Expand Down
Loading