From 22a465a91fb4f3708c8c9437db8765e38fad8ae0 Mon Sep 17 00:00:00 2001 From: Yongbo Wang Date: Wed, 13 Mar 2019 09:42:06 +0800 Subject: [PATCH 1/6] Simplify code, delete redundancy line delete redundancy line `if args.train`, simplify code. --- examples/run_classifier.py | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/run_classifier.py b/examples/run_classifier.py index f023a4cf20f..238a49a836c 100644 --- a/examples/run_classifier.py +++ b/examples/run_classifier.py @@ -594,7 +594,6 @@ def main(): optimizer.zero_grad() global_step += 1 - if args.do_train: # Save a trained model and the associated configuration model_to_save = model.module if hasattr(model, 'module') else model # Only save the model it-self output_model_file = os.path.join(args.output_dir, WEIGHTS_NAME) From e5f2d9122c73db985e34beaa1c80fef98be99510 Mon Sep 17 00:00:00 2001 From: thomwolf Date: Thu, 14 Mar 2019 09:55:01 +0100 Subject: [PATCH 2/6] adding absolute imports to gpt2, openai and transfo-xl --- pytorch_pretrained_bert/modeling_gpt2.py | 2 ++ pytorch_pretrained_bert/modeling_openai.py | 2 ++ pytorch_pretrained_bert/modeling_transfo_xl.py | 2 ++ 3 files changed, 6 insertions(+) diff --git a/pytorch_pretrained_bert/modeling_gpt2.py b/pytorch_pretrained_bert/modeling_gpt2.py index 69bd088a4e7..c381b288f86 100644 --- a/pytorch_pretrained_bert/modeling_gpt2.py +++ b/pytorch_pretrained_bert/modeling_gpt2.py @@ -15,6 +15,8 @@ # limitations under the License. """PyTorch OpenAI GPT-2 model.""" +from __future__ import absolute_import, division, print_function, unicode_literals + import collections import copy import json diff --git a/pytorch_pretrained_bert/modeling_openai.py b/pytorch_pretrained_bert/modeling_openai.py index d73ee66f50c..296abbfc314 100644 --- a/pytorch_pretrained_bert/modeling_openai.py +++ b/pytorch_pretrained_bert/modeling_openai.py @@ -15,6 +15,8 @@ # limitations under the License. """PyTorch OpenAI GPT model.""" +from __future__ import absolute_import, division, print_function, unicode_literals + import collections import copy import json diff --git a/pytorch_pretrained_bert/modeling_transfo_xl.py b/pytorch_pretrained_bert/modeling_transfo_xl.py index b225316f3d8..ac895a03a7e 100644 --- a/pytorch_pretrained_bert/modeling_transfo_xl.py +++ b/pytorch_pretrained_bert/modeling_transfo_xl.py @@ -18,6 +18,8 @@ In particular https://github.com/kimiyoung/transformer-xl/blob/master/pytorch/mem_transformer.py """ +from __future__ import absolute_import, division, print_function, unicode_literals + import os import copy import json From a98dfe4cedc53ededb05a10e688034a68c4843c4 Mon Sep 17 00:00:00 2001 From: thomwolf Date: Thu, 14 Mar 2019 09:57:06 +0100 Subject: [PATCH 3/6] fixing #377 (empty nbest_predictions.json) --- examples/run_squad.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/run_squad.py b/examples/run_squad.py index a29362ffb97..783c5f530ec 100644 --- a/examples/run_squad.py +++ b/examples/run_squad.py @@ -620,7 +620,7 @@ def write_predictions(all_examples, all_features, all_results, n_best_size, all_predictions[example.qas_id] = "" else: all_predictions[example.qas_id] = best_non_null_entry.text - all_nbest_json[example.qas_id] = nbest_json + all_nbest_json[example.qas_id] = nbest_json with open(output_prediction_file, "w") as writer: writer.write(json.dumps(all_predictions, indent=4) + "\n") From 3d6452163dc7a16fb007ce16c12b0b43b408ef55 Mon Sep 17 00:00:00 2001 From: Yongbo Wang Date: Thu, 14 Mar 2019 17:03:38 +0800 Subject: [PATCH 4/6] typo modify `mull` to `null` in line 474 annotation. --- examples/run_squad.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/run_squad.py b/examples/run_squad.py index 783c5f530ec..2e478991bff 100644 --- a/examples/run_squad.py +++ b/examples/run_squad.py @@ -471,7 +471,7 @@ def write_predictions(all_examples, all_features, all_results, n_best_size, prelim_predictions = [] # keep track of the minimum score of null start+end of position 0 score_null = 1000000 # large and positive - min_null_feature_index = 0 # the paragraph slice with min mull score + min_null_feature_index = 0 # the paragraph slice with min null score null_start_logit = 0 # the start logit at the slice with min null score null_end_logit = 0 # the end logit at the slice with min null score for (feature_index, feature) in enumerate(features): From d1e4fa98a91dfebfd88ef77b5ee761665ea0fe4a Mon Sep 17 00:00:00 2001 From: Yongbo Wang Date: Thu, 14 Mar 2019 17:32:15 +0800 Subject: [PATCH 5/6] typo in annotation modify `heruistic` to `heuristic` in line 660, `charcter` to `character` in line 661. --- examples/run_squad.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/run_squad.py b/examples/run_squad.py index 2e478991bff..bb335ce75c9 100644 --- a/examples/run_squad.py +++ b/examples/run_squad.py @@ -657,8 +657,8 @@ def get_final_text(pred_text, orig_text, do_lower_case, verbose_logging=False): # # What we really want to return is "Steve Smith". # - # Therefore, we have to apply a semi-complicated alignment heruistic between - # `pred_text` and `orig_text` to get a character-to-charcter alignment. This + # Therefore, we have to apply a semi-complicated alignment heuristic between + # `pred_text` and `orig_text` to get a character-to-character alignment. This # can fail in certain cases in which case we just return `orig_text`. def _strip_spaces(text): From 83857ffeaad96a2caa5d3b9b16acbff8260b3a80 Mon Sep 17 00:00:00 2001 From: tseretelitornike Date: Fri, 15 Mar 2019 12:45:48 +0100 Subject: [PATCH 6/6] Added missing imports. --- examples/run_swag.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/run_swag.py b/examples/run_swag.py index 2ebd637223c..ab8e147cae9 100644 --- a/examples/run_swag.py +++ b/examples/run_swag.py @@ -15,6 +15,8 @@ # limitations under the License. """BERT finetuning runner.""" +from __future__ import absolute_import + import argparse import csv import logging @@ -31,7 +33,7 @@ from torch.utils.data.distributed import DistributedSampler from tqdm import tqdm, trange from pytorch_pretrained_bert.file_utils import PYTORCH_PRETRAINED_BERT_CACHE -from pytorch_pretrained_bert.modeling import BertForMultipleChoice +from pytorch_pretrained_bert.modeling import (BertForMultipleChoice, BertConfig, WEIGHTS_NAME, CONFIG_NAME) from pytorch_pretrained_bert.optimization import BertAdam, warmup_linear from pytorch_pretrained_bert.tokenization import BertTokenizer