提交 bb384c41 编写于 作者: Z Zeyu Chen

simply LAC demo

上级 6fa9bf9b
......@@ -27,18 +27,18 @@ $ pip install --upgrade paddlepaddle
## 命令行方式预测
`infer.sh`给出了使用命令行调用Module预测的示例脚本
`cli_demo.sh`给出了使用命令行接口(Command Line Interface)调用Module预测的示例脚本
通过以下命令试验下效果
```shell
$ sh infer.sh
$ sh cli_demo.sh
```
## 通过python API预测
## 通过Python API预测
`infer_by_code.py`给出了使用python API调用Module预测的示例代码
`lac_demo.py`给出了使用python API调用PaddleHub LAC Module预测的示例代码
通过以下命令试验下效果
```shell
python infer_by_code.py
python lac_demo.py
```
import os
import paddlehub as hub
def infer_with_input_text():
# get lac module
lac = hub.Module(name="lac")
test_text = ["今天是个好日子", "天气预报说今天要下雨", "下一班地铁马上就要到了"]
# get the input keys for signature 'lexical_analysis'
data_format = lac.processor.data_format(sign_name='lexical_analysis')
key = list(data_format.keys())[0]
# set input dict
input_dict = {key: test_text}
# execute predict and print the result
results = lac.lexical_analysis(data=input_dict)
for index, result in enumerate(results):
hub.logger.info(
"sentence %d segmented result: %s" % (index + 1, result['word']))
def infer_with_input_file():
# get lac module
lac = hub.Module(name="lac")
# get the input keys for signature 'lexical_analysis'
data_format = lac.processor.data_format(sign_name='lexical_analysis')
key = list(data_format.keys())[0]
# parse input file
test_file = os.path.join("test", "test.txt")
test_text = hub.io.parser.txt_parser.parse(test_file)
# set input dict
input_dict = {key: test_text}
results = lac.lexical_analysis(data=input_dict)
for index, result in enumerate(results):
hub.logger.info(
"sentence %d segmented result: %s" % (index + 1, result['word']))
if __name__ == "__main__":
infer_with_input_file()
import os
import paddlehub as hub
if __name__ == "__main__":
# Load LAC Module
lac = hub.Module(name="lac")
test_text = ["今天是个好日子", "天气预报说今天要下雨", "下一班地铁马上就要到了"]
# Set input dict
inputs = {"text": test_text}
# execute predict and print the result
results = lac.lexical_analysis(data=inputs)
for result in results:
print(result['word'])
print(result['tag'])
今天是个好日子
天气预报说今天要下雨
下一班地铁马上就要到了
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册