From 8efaf8f176cdc9ebeea81893aaf6062bbffc4a4d Mon Sep 17 00:00:00 2001 From: wlhgtc Date: Fri, 15 Feb 2019 15:57:25 +0800 Subject: [PATCH] fix 'best_non_null_entry' is None error --- examples/run_squad.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/examples/run_squad.py b/examples/run_squad.py index e8ed71cd55..451b4241bb 100644 --- a/examples/run_squad.py +++ b/examples/run_squad.py @@ -573,6 +573,13 @@ def write_predictions(all_examples, all_features, all_results, n_best_size, text="", start_logit=null_start_logit, end_logit=null_end_logit)) + + # In very rare edge cases we could only have single null prediction. + # So we just create a nonce prediction in this case to avoid failure. + if len(nbest)==1: + nbest.insert(0, + _NbestPrediction(text="empty", start_logit=0.0, end_logit=0.0)) + # In very rare edge cases we could have no valid predictions. So we # just create a nonce prediction in this case to avoid failure. if not nbest: