baidu / lac

百度NLP:分词,词性标注,命名实体识别,词重要性
Apache License 2.0
3.85k stars 597 forks source link

python2.7训练模型lac.train报错 #143

Open baronyangvip opened 3 years ago

baronyangvip commented 3 years ago

W1029 13:25:53.342841 17028 analysis_predictor.cc:1042] Deprecated. Please use CreatePredictor instead. Traceback (most recent call last): File "/home/baron/git/project-pac-nlp/prj/01-website/prj-02-11-tools-for-baiduai/LAC/test_01_cut.py", line 49, in <module> train_cut() File "/home/baron/git/project-pac-nlp/prj/01-website/prj-02-11-tools-for-baiduai/LAC/test_01_cut.py", line 21, in train_cut lac.train(model_save_dir='./my_seg_model/',train_data=train_file, test_data=test_file) File "/usr/local/lib/python2.7/dist-packages/LAC-2.0.5-py2.7.egg/LAC/lac.py", line 164, in train test_program, fetch_list = nets.do_train(self.args) File "/usr/local/lib/python2.7/dist-packages/LAC-2.0.5-py2.7.egg/LAC/nets.py", line 306, in do_train args, dataset.vocab_size, dataset.num_labels, mode='train') File "/usr/local/lib/python2.7/dist-packages/LAC-2.0.5-py2.7.egg/LAC/nets.py", line 158, in create_model name='words', shape=[-1, 1], dtype='int64', lod_level=1) File "</usr/local/lib/python2.7/dist-packages/decorator.pyc:decorator-gen-30>", line 2, in data File "/usr/local/lib/python2.7/dist-packages/paddlepaddle-2.0.0rc0-py2.7-linux-x86_64.egg/paddle/fluid/wrapped_decorator.py", line 25, in __impl__ return wrapped_func(*args, **kwargs) File "/usr/local/lib/python2.7/dist-packages/paddlepaddle-2.0.0rc0-py2.7-linux-x86_64.egg/paddle/fluid/framework.py", line 232, in __impl__ ), "We only support '%s()' in static graph mode, please call 'paddle.enable_static()' to enter static graph mode." % func.__name__ AssertionError: We only support 'data()' in static graph mode, please call 'paddle.enable_static()' to enter static graph mode.

Bond-H commented 3 years ago

从log信息应该是paddlepaddle-2.0.0rc0-py2.7版本,该版本还处于测试阶段且默认使用了动态图模式,而目前LAC的实现都是基于静态图实现的,可使用paddlepaddle-1.8.5版本,或者切换为静态图模式再运行LAC:

import paddle
paddle.enable_static()
dhao-island commented 3 years ago

运行了import paddle paddle.enable_static(),却还是出现上述一样的报错,该怎么解决啊