From ce244e4a58cff89eed57f084de77f7fc221e343a Mon Sep 17 00:00:00 2001 From: Zeyu Chen Date: Fri, 18 Jan 2019 16:39:04 +0800 Subject: [PATCH] change get word_id interface --- .../sentiment-classification/sentiment_classify.py | 13 ++++--------- paddle_hub/module.py | 4 ++-- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/example/sentiment-classification/sentiment_classify.py b/example/sentiment-classification/sentiment_classify.py index 571b4ddc..7fa4a560 100644 --- a/example/sentiment-classification/sentiment_classify.py +++ b/example/sentiment-classification/sentiment_classify.py @@ -124,11 +124,6 @@ def train_net(train_reader, sgd_optimizer = fluid.optimizer.Adagrad(learning_rate=lr) sgd_optimizer.minimize(cost) - # write default main program - with open("./bow_net.backward.program_desc.prototxt", "w") as fo: - program_desc = str(fluid.default_main_program()) - fo.write(program_desc) - # set place, executor, datafeeder place = fluid.CUDAPlace(0) if use_gpu else fluid.CPUPlace() exe = fluid.Executor(place) @@ -221,10 +216,10 @@ def finetune_net(train_reader, fluid.layers.cross_entropy(input=pred, label=label)) acc = fluid.layers.accuracy(input=pred, label=label) - with open("./prototxt/bow_net.forward.program_desc.prototxt", - "w") as fo: - program_desc = str(fluid.default_main_program()) - fo.write(program_desc) + # with open("./prototxt/bow_net.forward.program_desc.prototxt", + # "w") as fo: + # program_desc = str(fluid.default_main_program()) + # fo.write(program_desc) # set optimizer sgd_optimizer = fluid.optimizer.Adagrad(learning_rate=lr) sgd_optimizer.minimize(cost) diff --git a/paddle_hub/module.py b/paddle_hub/module.py index 535a37a5..69ad0d86 100644 --- a/paddle_hub/module.py +++ b/paddle_hub/module.py @@ -194,7 +194,7 @@ class Module(object): return lod_tensor def _word_id_mapping(self, inputs): - word_dict = self.config.get_dict() + word_dict = self.config.get_assets_vocab() return list(map(lambda x: word_dict[x], inputs)) @@ -214,7 +214,7 @@ class ModuleConfig(object): self.dict = defaultdict(int) self.dict.setdefault(0) - def get_dict(self): + def get_assets_vocab(self): """ Return dictionary in Module""" return self.dict -- GitLab