From 5a70d655916431a2c866004460815214516ac218 Mon Sep 17 00:00:00 2001 From: h00Jiang <378213564@qq.com> Date: Wed, 29 Aug 2018 14:02:24 +0800 Subject: [PATCH 1/3] fix a bug (when restore the pickle_file , cannot restore dev.pkl) --- fastNLP/core/preprocess.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fastNLP/core/preprocess.py b/fastNLP/core/preprocess.py index dfaf3e94..90a32c12 100644 --- a/fastNLP/core/preprocess.py +++ b/fastNLP/core/preprocess.py @@ -59,7 +59,6 @@ class BasePreprocess(object): def run(self, train_dev_data, test_data=None, pickle_path="./", train_dev_split=0, cross_val=False, n_fold=10): """Main preprocessing pipeline. - :param train_dev_data: three-level list, with either single label or multiple labels in a sample. :param test_data: three-level list, with either single label or multiple labels in a sample. (optional) :param pickle_path: str, the path to save the pickle files. @@ -98,6 +97,7 @@ class BasePreprocess(object): save_pickle(data_train, pickle_path, "data_train.pkl") else: data_train = load_pickle(pickle_path, "data_train.pkl") + data_dev = load_pickle(pickle_path, "data_dev.pkl") else: # cross_val is True if not pickle_exist(pickle_path, "data_train_0.pkl"): @@ -307,4 +307,4 @@ def infer_preprocess(pickle_path, data): data_index = [] for example in data: data_index.append([word2index.get(w, DEFAULT_UNKNOWN_LABEL) for w in example]) - return data_index + return data_index \ No newline at end of file From 18586c9c6db7fbc181fe12948f95c17b62f26903 Mon Sep 17 00:00:00 2001 From: h00Jiang <378213564@qq.com> Date: Wed, 29 Aug 2018 14:08:29 +0800 Subject: [PATCH 2/3] fix a bug (when init_emb is not None , get an error) --- fastNLP/modules/encoder/embedding.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fastNLP/modules/encoder/embedding.py b/fastNLP/modules/encoder/embedding.py index b2641bff..73ddd77a 100644 --- a/fastNLP/modules/encoder/embedding.py +++ b/fastNLP/modules/encoder/embedding.py @@ -15,7 +15,7 @@ class Embedding(nn.Module): def __init__(self, nums, dims, padding_idx=0, sparse=False, init_emb=None, dropout=0.0): super(Embedding, self).__init__() self.embed = nn.Embedding(nums, dims, padding_idx, sparse=sparse) - if init_emb: + if init_emb is not None: self.embed.weight = nn.Parameter(init_emb) self.dropout = nn.Dropout(dropout) From 50b53455391ba1ff126b4f2ff76a2d149d22b567 Mon Sep 17 00:00:00 2001 From: Coet Date: Wed, 29 Aug 2018 17:03:26 +0800 Subject: [PATCH 3/3] check if data_dev.pkl exists In line 100, add a if statement to check whether there exists a file named "data_dev.pkl" in the pickle path. If not, the file won't be loaded. --- fastNLP/core/preprocess.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fastNLP/core/preprocess.py b/fastNLP/core/preprocess.py index 90a32c12..77df6b51 100644 --- a/fastNLP/core/preprocess.py +++ b/fastNLP/core/preprocess.py @@ -97,7 +97,8 @@ class BasePreprocess(object): save_pickle(data_train, pickle_path, "data_train.pkl") else: data_train = load_pickle(pickle_path, "data_train.pkl") - data_dev = load_pickle(pickle_path, "data_dev.pkl") + if pickle_exist(pickle_path, "data_dev.pkl"): + data_dev = load_pickle(pickle_path, "data_dev.pkl") else: # cross_val is True if not pickle_exist(pickle_path, "data_train_0.pkl"): @@ -307,4 +308,4 @@ def infer_preprocess(pickle_path, data): data_index = [] for example in data: data_index.append([word2index.get(w, DEFAULT_UNKNOWN_LABEL) for w in example]) - return data_index \ No newline at end of file + return data_index