Skip to content

Instantly share code, notes, and snippets.

@jAndrewtomich
jAndrewtomich / f1_score.py
Created May 3, 2021 21:46 — forked from SuperShinyEyes/f1_score.py
F1 score in PyTorch
def f1_loss(y_true:torch.Tensor, y_pred:torch.Tensor, is_training=False) -> torch.Tensor:
'''Calculate F1 score. Can work with gpu tensors
The original implmentation is written by Michal Haltuf on Kaggle.
Returns
-------
torch.Tensor
`ndim` == 1. 0 <= val <= 1