Unverified Commit 73e2faa6 authored by Billy Lee's avatar Billy Lee Committed by GitHub
Browse files

Replace assert statements with raise exceptions (#20478)

* replace assert statements with exceptions

* made conditions more readable
parent fb2b45e5
...@@ -536,7 +536,8 @@ def compute_predictions_logits( ...@@ -536,7 +536,8 @@ def compute_predictions_logits(
if not nbest: if not nbest:
nbest.append(_NbestPrediction(text="empty", start_logit=0.0, end_logit=0.0)) nbest.append(_NbestPrediction(text="empty", start_logit=0.0, end_logit=0.0))
assert len(nbest) >= 1, "No valid predictions" if len(nbest) < 1:
raise ValueError("No valid predictions")
total_scores = [] total_scores = []
best_non_null_entry = None best_non_null_entry = None
...@@ -557,7 +558,8 @@ def compute_predictions_logits( ...@@ -557,7 +558,8 @@ def compute_predictions_logits(
output["end_logit"] = entry.end_logit output["end_logit"] = entry.end_logit
nbest_json.append(output) nbest_json.append(output)
assert len(nbest_json) >= 1, "No valid predictions" if len(nbest_json) < 1:
raise ValueError("No valid predictions")
if not version_2_with_negative: if not version_2_with_negative:
all_predictions[example.qas_id] = nbest_json[0]["text"] all_predictions[example.qas_id] = nbest_json[0]["text"]
...@@ -752,8 +754,10 @@ def compute_predictions_log_probs( ...@@ -752,8 +754,10 @@ def compute_predictions_log_probs(
output["end_log_prob"] = entry.end_log_prob output["end_log_prob"] = entry.end_log_prob
nbest_json.append(output) nbest_json.append(output)
assert len(nbest_json) >= 1, "No valid predictions" if len(nbest_json) < 1:
assert best_non_null_entry is not None, "No valid predictions" raise ValueError("No valid predictions")
if best_non_null_entry is None:
raise ValueError("No valid predictions")
score_diff = score_null score_diff = score_null
scores_diff_json[example.qas_id] = score_diff scores_diff_json[example.qas_id] = score_diff
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment