Skip to content

Improve Warnings #161

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
17 changes: 9 additions & 8 deletions bert_score/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import sys
import warnings
from collections import Counter, defaultdict
from functools import partial
from itertools import chain
Expand Down Expand Up @@ -554,18 +555,18 @@ def greedy_cos_idf(
F = F.view(L, B)

if torch.any(hyp_zero_mask):
print(
"Warning: Empty candidate sentence detected; setting raw BERTscores to 0.",
file=sys.stderr,
)
warning_message = "Empty candidate sentence detected; setting raw BERTscores to 0."
warnings.warn(warning_message)
sys.stdout.write(warning_message)

P = P.masked_fill(hyp_zero_mask, 0.0)
R = R.masked_fill(hyp_zero_mask, 0.0)

if torch.any(ref_zero_mask):
print(
"Warning: Empty reference sentence detected; setting raw BERTScores to 0.",
file=sys.stderr,
)
warning_message = "Empty reference sentence detected; setting raw BERTscores to 0."
warnings.warn(warning_message)
sys.stdout.write(warning_message)

P = P.masked_fill(ref_zero_mask, 0.0)
R = R.masked_fill(ref_zero_mask, 0.0)

Expand Down