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

Update chrf.py to remove torch Warnings #2482

Merged
merged 17 commits into from
Apr 19, 2024
Merged
Changes from 2 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
6 changes: 4 additions & 2 deletions src/torchmetrics/functional/text/chrf.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def _get_total_ngrams(n_grams_counts: Dict[int, Dict[Tuple[str, ...], Tensor]])
"""Get total sum of n-grams over n-grams w.r.t n."""
total_n_grams: Dict[int, Tensor] = defaultdict(lambda: tensor(0.0))
for n in n_grams_counts:
total_n_grams[n] = tensor(sum(n_grams_counts[n].values()))
total_n_grams[n] = sum(n_grams_counts[n].values()).detach().clone()
return total_n_grams

char_n_grams_counts, word_n_grams_counts = _char_and_word_ngrams_counts(
Expand Down Expand Up @@ -216,11 +216,13 @@ def _get_ngram_matches(
"""
matching_n_grams: Dict[int, Tensor] = defaultdict(lambda: tensor(0.0))
for n in hyp_n_grams_counts:
matching_n_grams[n] = tensor(
matching_n_grams[n] = (
sum(
torch.min(ref_n_grams_counts[n][n_gram], hyp_n_grams_counts[n][n_gram])
for n_gram in hyp_n_grams_counts[n]
)
.detach()
.clone()
)
return matching_n_grams

Expand Down
Loading