PaddlePaddle / PaddleHub

Awesome pre-trained models toolkit based on PaddlePaddle. (400+ models including Image, Text, Audio, Video and Cross-Modal with Easy Inference & Serving)【安全加固,暂停交互,请耐心等待】
https://www.paddlepaddle.org.cn/hub
Apache License 2.0
12.73k stars 2.07k forks source link

提问-实现lstm+attention文本分类 #950

Closed Masterkmp closed 3 years ago

Masterkmp commented 4 years ago

意自定义网络实现bilstm+attention机制实现文本分类,官网中只有视频的lstm+attention(PaddleHub-release-v1.8\PaddleHub-release-v1.8\hub_module\modules\video\classification\videotag_tsn_lstm\resource\models\attention_lstm\lstm_attention.py),参考后报错。。请问哪里写错了? 代码如下: 图片 运行报错: ` 忽略上面的的提示,这里已经对组网方式修改了,使用的并不是默认的bilstm!!!! upad_feature.shape= (-1, 1024) lstm_concat.shape== (-1, 128) lstm_weight.shape== (-1, 1) scaled.shape== (-1, 128)

---------------------------------------------------------------------------EnforceNotMet Traceback (most recent call last) in 1 #开始Finetune 2 print("忽略上面的的提示,这里已经对组网方式修改了,使用的并不是默认的bilstm!!!!") ----> 3 run_states = cls_task.finetune_and_eval() /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddlehub/finetune/task/base_task.py in finetune_and_eval(self) 943 944 def finetune_and_eval(self): --> 945 return self.finetune(do_eval=True) 946 947 def finetune(self, do_eval=False): /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddlehub/finetune/task/base_task.py in finetune(self, do_eval) 958 # Start to finetune 959 with self.phase_guard(phase="train"): --> 960 self.init_if_necessary() 961 self._finetune_start_event() 962 run_states = [] /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddlehub/finetune/task/base_task.py in init_if_necessary(self) 382 def init_if_necessary(self): 383 if not self.is_checkpoint_loaded: --> 384 if not self.load_checkpoint(): 385 self.exe.run(self._base_startup_program) 386 self.is_checkpoint_loaded = True /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddlehub/finetune/task/base_task.py in load_checkpoint(self) 909 self.config.checkpoint_dir, 910 self.exe, --> 911 main_program=self.main_program) 912 # Revise max_train_steps when incremental training 913 if is_load_successful: /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddlehub/finetune/task/base_task.py in main_program(self) 543 def main_program(self): 544 if not self.env.is_inititalized: --> 545 self._build_env() 546 return self.env.main_program 547 /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddlehub/finetune/task/base_task.py in _build_env(self) 417 self._base_startup_program): 418 with fluid.unique_name.guard(self.env.UNG): --> 419 self.env.outputs = self._build_net() 420 if self.is_train_phase or self.is_test_phase: 421 self.env.labels = self._add_label()

in _build_net(self) 34 cls_feats = net_func(self.feature) 35 else: ---> 36 cls_feats = net_func(unpad_feature) 37 if self.is_train_phase or self.is_predict_phase: 38 logger.info("%s has been added in the TextClassifierTask!" % in Bilstm_attention(token_embeddings, hid_dim, hid_dim2) 55 print(scaled.shape) 56 ---> 57 lstm_pool = fluid.layers.sequence_pool(input=scaled, pool_type='sum') 58 print("lstm_pool==") 59 print(lstm_pool.shape) /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/layers/sequence_lod.py in sequence_pool(input, pool_type, is_test, pad_value) 355 "pooltype": pool_type.upper(), 356 "is_test": is_test, --> 357 "pad_value": pad_value 358 }) 359 /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/layer_helper.py in append_op(self, *args, **kwargs) 41 42 def append_op(self, *args, **kwargs): ---> 43 return self.main_program.current_block().append_op(*args, **kwargs) 44 45 def multiple_input(self, input_param_name='input'): /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/framework.py in append_op(self, *args, **kwargs) 2608 inputs=kwargs.get("inputs", None), 2609 outputs=kwargs.get("outputs", None), -> 2610 attrs=kwargs.get("attrs", None)) 2611 2612 self.ops.append(op) /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/framework.py in __init__(***failed resolving arguments***) 1969 if self._has_kernel(type): 1970 self.desc.infer_var_type(self.block.desc) -> 1971 self.desc.infer_shape(self.block.desc) 1972 1973 def _has_kernel(self, op_type): EnforceNotMet: -------------------------------------------- C++ Call Stacks (More useful to developers): -------------------------------------------- 0 std::string paddle::platform::GetTraceBackString(std::string const&, char const*, int) 1 paddle::platform::EnforceNotMet::EnforceNotMet(std::string const&, char const*, int) 2 paddle::operators::SequencePoolOp::InferShape(paddle::framework::InferShapeContext*) const 3 paddle::framework::OpDesc::InferShape(paddle::framework::BlockDesc const&) const ------------------------------------------ Python Call Stacks (More useful to users): ------------------------------------------ File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/framework.py", line 2610, in append_op attrs=kwargs.get("attrs", None)) File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/layer_helper.py", line 43, in append_op return self.main_program.current_block().append_op(*args, **kwargs) File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/layers/sequence_lod.py", line 357, in sequence_pool "pad_value": pad_value File "", line 57, in Bilstm_attention lstm_pool = fluid.layers.sequence_pool(input=scaled, pool_type='sum') File "", line 36, in _build_net cls_feats = net_func(unpad_feature) File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddlehub/finetune/task/base_task.py", line 419, in _build_env self.env.outputs = self._build_net() File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddlehub/finetune/task/base_task.py", line 545, in main_program self._build_env() File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddlehub/finetune/task/base_task.py", line 911, in load_checkpoint main_program=self.main_program) File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddlehub/finetune/task/base_task.py", line 384, in init_if_necessary if not self.load_checkpoint(): File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddlehub/finetune/task/base_task.py", line 960, in finetune self.init_if_necessary() File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddlehub/finetune/task/base_task.py", line 945, in finetune_and_eval return self.finetune(do_eval=True) File "", line 3, in run_states = cls_task.finetune_and_eval() File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3265, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3183, in run_ast_nodes if (yield from self.run_code(code, result)): File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3018, in run_cell_async interactivity=interactivity, compiler=compiler, result=result) File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/IPython/core/async_helpers.py", line 67, in _pseudo_sync_runner coro.send(None) File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 2843, in _run_cell return runner(coro) File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 2817, in run_cell raw_cell, store_history, silent, shell_futures) File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/ipykernel/zmqshell.py", line 536, in run_cell return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs) File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/ipykernel/ipkernel.py", line 294, in do_execute res = shell.run_cell(code, store_history=store_history, silent=silent) File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/tornado/gen.py", line 326, in wrapper yielded = next(result) File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/ipykernel/kernelbase.py", line 534, in execute_request user_expressions, allow_stdin, File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/tornado/gen.py", line 326, in wrapper yielded = next(result) File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/ipykernel/kernelbase.py", line 267, in dispatch_shell yield gen.maybe_future(handler(stream, idents, msg)) File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/tornado/gen.py", line 326, in wrapper yielded = next(result) File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/ipykernel/kernelbase.py", line 357, in process_one yield gen.maybe_future(dispatch(*args)) File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/tornado/gen.py", line 1147, in run yielded = self.gen.send(value) File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/tornado/gen.py", line 1233, in inner self.run() File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/tornado/stack_context.py", line 300, in null_wrapper return fn(*args, **kwargs) File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/tornado/ioloop.py", line 758, in _run_callback ret = callback() File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/asyncio/events.py", line 88, in _run self._context.run(self._callback, *self._args) File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/asyncio/base_events.py", line 1771, in _run_once handle._run() File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/asyncio/base_events.py", line 534, in run_forever self._run_once() File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/tornado/platform/asyncio.py", line 132, in start self.asyncio_loop.run_forever() File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/ipykernel/kernelapp.py", line 505, in start self.io_loop.start() File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/traitlets/config/application.py", line 664, in launch_instance app.start() File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/ipykernel_launcher.py", line 16, in app.launch_new_instance() File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/runpy.py", line 85, in _run_code exec(code, run_globals) File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/runpy.py", line 193, in _run_module_as_main "__main__", mod_spec) ---------------------- Error Message Summary: ---------------------- InvalidArgumentError: The LoD level of Input(X) should be larger than 0, but received: lod level 0. [Hint: Expected in_lod_level > 0, but received in_lod_level:0 <= 0:0.] at (/paddle/paddle/fluid/operators/sequence_ops/sequence_pool_op.cc:37) [operator < sequence_pool > error] `
Steffy-zxf commented 4 years ago

你好!根据上述代码和报错信息,上述组网使用了dynamic_lstmsequence_poolapi,这个api 要求输入input是一个LodTensor, 可以调试看看相应api的类型,看看lod_level

haoyuying commented 3 years ago

Since you haven't replied for more than 3 months, we have closed this issue/pr. If the problem is not solved or there is a follow-up one, please reopen it at any time and we will continue to follow up. 由于您超过三个月未回复,我们将关闭这个issue/pr。 若问题未解决或有后续问题,请随时重新打开,我们会继续跟进。