From b93fb5cc4de498abc66c0aaf6b67a6fea006e224 Mon Sep 17 00:00:00 2001 From: Neelkant Newra Date: Tue, 1 Jun 2021 13:05:12 +0530 Subject: [PATCH 1/2] Updated for ValueError: substring not found #78 --- pipelines.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pipelines.py b/pipelines.py index 2c9c681..4c26122 100644 --- a/pipelines.py +++ b/pipelines.py @@ -134,10 +134,10 @@ def _prepare_inputs_for_qg_from_answers_hl(self, sents, answers): for i, answer in enumerate(answers): if len(answer) == 0: continue for answer_text in answer: - sent = sents[i] + sent = sents[i].lower() sents_copy = sents[:] - answer_text = answer_text.strip() + answer_text = answer_text.strip().lower() ans_start_idx = sent.index(answer_text) From 6eb9bc962a3150a71a2e6cfa99026e8ba4bb4b31 Mon Sep 17 00:00:00 2001 From: Neelkant Newra Date: Tue, 1 Jun 2021 13:26:14 +0530 Subject: [PATCH 2/2] Exception Handling for ValueError and AssertionError Added a try exception in case of ValueError and AssertionError. --- pipelines.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pipelines.py b/pipelines.py index 4c26122..7701fd2 100644 --- a/pipelines.py +++ b/pipelines.py @@ -138,8 +138,10 @@ def _prepare_inputs_for_qg_from_answers_hl(self, sents, answers): sents_copy = sents[:] answer_text = answer_text.strip().lower() - - ans_start_idx = sent.index(answer_text) + try: + ans_start_idx = sent.index(answer_text) + except (ValueError,AssertionError): + continue sent = f"{sent[:ans_start_idx]} {answer_text} {sent[ans_start_idx + len(answer_text): ]}" sents_copy[i] = sent