From b7c4a42d155cdb09b1b6a8216fb21e97dd479ed0 Mon Sep 17 00:00:00 2001 From: jacky18008 <102701008@nccu.edu.tw> Date: Mon, 24 Feb 2020 14:10:54 +0800 Subject: [PATCH 1/6] postpone the initialization of the variable 'feature' until the non-emptiness of answer is checked, while empty answer has no feature --- .../question_answering/question_answering_model.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/simpletransformers/question_answering/question_answering_model.py b/simpletransformers/question_answering/question_answering_model.py index 99f94341..90e7dc89 100755 --- a/simpletransformers/question_answering/question_answering_model.py +++ b/simpletransformers/question_answering/question_answering_model.py @@ -255,7 +255,7 @@ def train_model( self._move_model_to_device() if isinstance(train_data, str): - with open(train_data, "r") as f: + with open(train_data, "r", encoding="utf-8") as f: train_examples = json.load(f) else: train_examples = train_data @@ -526,7 +526,7 @@ def eval_model(self, eval_data, output_dir=None, verbose=False): all_predictions, all_nbest_json, scores_diff_json = self.evaluate(eval_data, output_dir) if isinstance(eval_data, str): - with open(eval_data, "r") as f: + with open(eval_data, "r", encoding="utf-8") as f: truth = json.load(f) else: truth = eval_data @@ -552,7 +552,7 @@ def evaluate(self, eval_data, output_dir): args = self.args if isinstance(eval_data, str): - with open(eval_data, "r") as f: + with open(eval_data, "r", encoding="utf-8") as f: eval_examples = json.load(f) else: eval_examples = eval_data From a3988bde7b5e1a86998a2676694e7479fb1c3d17 Mon Sep 17 00:00:00 2001 From: jacky18008 <102701008@nccu.edu.tw> Date: Mon, 24 Feb 2020 14:26:45 +0800 Subject: [PATCH 2/6] postpone the initialization of the variable 'feature' until the non-emptiness of answer is checked, while empty answer has empty features --- .../question_answering/question_answering_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/simpletransformers/question_answering/question_answering_utils.py b/simpletransformers/question_answering/question_answering_utils.py index a11f6421..a33b34e9 100755 --- a/simpletransformers/question_answering/question_answering_utils.py +++ b/simpletransformers/question_answering/question_answering_utils.py @@ -600,8 +600,8 @@ def write_predictions( for pred in prelim_predictions: if len(nbest) >= n_best_size: break - feature = features[pred.feature_index] if pred.start_index > 0: # this is a non-null prediction + feature = features[pred.feature_index] tok_tokens = feature.tokens[pred.start_index : (pred.end_index + 1)] orig_doc_start = feature.token_to_orig_map[pred.start_index] orig_doc_end = feature.token_to_orig_map[pred.end_index] @@ -993,8 +993,8 @@ def get_best_predictions( for pred in prelim_predictions: if len(nbest) >= n_best_size: break - feature = features[pred.feature_index] if pred.start_index > 0: # this is a non-null prediction + feature = features[pred.feature_index] tok_tokens = feature.tokens[pred.start_index : (pred.end_index + 1)] orig_doc_start = feature.token_to_orig_map[pred.start_index] orig_doc_end = feature.token_to_orig_map[pred.end_index] From e8ca6a736de36c617dd94174d5b910228e43bdd6 Mon Sep 17 00:00:00 2001 From: jacky18008 <102701008@nccu.edu.tw> Date: Mon, 24 Feb 2020 14:29:20 +0800 Subject: [PATCH 3/6] reset encoding --- .../question_answering/question_answering_model.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/simpletransformers/question_answering/question_answering_model.py b/simpletransformers/question_answering/question_answering_model.py index 90e7dc89..99f94341 100755 --- a/simpletransformers/question_answering/question_answering_model.py +++ b/simpletransformers/question_answering/question_answering_model.py @@ -255,7 +255,7 @@ def train_model( self._move_model_to_device() if isinstance(train_data, str): - with open(train_data, "r", encoding="utf-8") as f: + with open(train_data, "r") as f: train_examples = json.load(f) else: train_examples = train_data @@ -526,7 +526,7 @@ def eval_model(self, eval_data, output_dir=None, verbose=False): all_predictions, all_nbest_json, scores_diff_json = self.evaluate(eval_data, output_dir) if isinstance(eval_data, str): - with open(eval_data, "r", encoding="utf-8") as f: + with open(eval_data, "r") as f: truth = json.load(f) else: truth = eval_data @@ -552,7 +552,7 @@ def evaluate(self, eval_data, output_dir): args = self.args if isinstance(eval_data, str): - with open(eval_data, "r", encoding="utf-8") as f: + with open(eval_data, "r") as f: eval_examples = json.load(f) else: eval_examples = eval_data From bcd11cda6dcf10cd5ce18c3d22adc05d484e0586 Mon Sep 17 00:00:00 2001 From: ThilinaRajapakse Date: Mon, 2 Mar 2020 23:04:35 +0530 Subject: [PATCH 4/6] bumped version number --- CHANGELOG.md | 10 +++++++++- setup.py | 2 +- .../question_answering/question_answering_utils.py | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e58501c..6d4443b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.21.2] - 2020-03-01 + +### Fixed + +- Fixed bug with empty answers in `QuestionAnsweringModel`. + ## [0.21.1] - 2020-02-29 ### Fixed @@ -436,7 +442,9 @@ Model checkpoint is now saved for all epochs again. - This CHANGELOG file to hopefully serve as an evolving example of a standardized open source project CHANGELOG. -[0.21.1]: https://github.com/ThilinaRajapakse/simpletransformers/compare/721c55c...HEAD +[0.21.2]: https://github.com/ThilinaRajapakse/simpletransformers/compare/d114c50...HEAD + +[0.21.1]: https://github.com/ThilinaRajapakse/simpletransformers/compare/721c55c...d114c50 [0.21.0]: https://github.com/ThilinaRajapakse/simpletransformers/compare/f484717...721c55c diff --git a/setup.py b/setup.py index c5506965..bd2ae1cf 100755 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ setup( name="simpletransformers", - version="0.21.1", + version="0.21.2", author="Thilina Rajapakse", author_email="chaturangarajapakshe@gmail.com", description="An easy-to-use wrapper library for the Transformers library.", diff --git a/simpletransformers/question_answering/question_answering_utils.py b/simpletransformers/question_answering/question_answering_utils.py index a11f6421..519d3252 100755 --- a/simpletransformers/question_answering/question_answering_utils.py +++ b/simpletransformers/question_answering/question_answering_utils.py @@ -693,7 +693,7 @@ def write_predictions( # For XLNet (and XLM which uses the same head) RawResultExtended = collections.namedtuple( "RawResultExtended", - ["unique_id", "start_top_log_probs", "start_top_index", "end_top_log_probs", "end_top_index", "cls_logits",], + ["unique_id", "start_top_log_probs", "start_top_index", "end_top_log_probs", "end_top_index", "cls_logits"], ) From 8645339e9431af453cefc231cec99b4e791e846d Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Mon, 2 Mar 2020 17:56:34 +0000 Subject: [PATCH 5/6] docs: update README.md [skip ci] --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b8943fb0..4742a25e 100755 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![Downloads](https://pepy.tech/badge/simpletransformers)](https://pepy.tech/project/simpletransformers) -[![All Contributors](https://img.shields.io/badge/all_contributors-18-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-19-orange.svg?style=flat-square)](#contributors-) # Simple Transformers @@ -1769,6 +1769,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
flaviussn

💻 📖
Marc Torrellas

🚧
Adrien Renaud

💻 +
jacky18008

💻 From 05d27b4245a4cdf6b4cd83faad660e54058eda73 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Mon, 2 Mar 2020 17:56:35 +0000 Subject: [PATCH 6/6] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index ed02193f..90f5d12a 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -173,6 +173,15 @@ "contributions": [ "code" ] + }, + { + "login": "jacky18008", + "name": "jacky18008", + "avatar_url": "https://avatars0.githubusercontent.com/u/9031441?v=4", + "profile": "https://github.com/jacky18008", + "contributions": [ + "code" + ] } ], "contributorsPerLine": 7,