Skip to content

Commit f12a0d8

Browse files
committed
add the paddlenlp server
1 parent e002b0d commit f12a0d8

File tree

45 files changed

+2099
-22
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+2099
-22
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# 基于PaddleNLP SimpleServing 的服务化部署
2+
3+
## 目录
4+
- [环境准备](#环境准备)
5+
- [Server启动服务](#Server服务启动)
6+
- [其他参数设置](#其他参数设置)
7+
8+
## 环境准备
9+
使用有SimpleServing功能的PaddleNLP版本
10+
```shell
11+
pip install paddlenlp --upgrade
12+
```
13+
## Server服务启动
14+
### 分类任务启动
15+
#### 启动 分类 Server 服务
16+
```bash
17+
paddlenlp server server:app --host 0.0.0.0 --port 8189
18+
```
19+
20+
#### 分类任务发送服务
21+
```bash
22+
python client.py
23+
```
24+
25+
26+
## 其他参数设置
27+
可以在client端设置 `max_seq_len`, `batch_size`, `prob_limit` 参数
28+
```python
29+
data = {
30+
'data': {
31+
'text': texts,
32+
},
33+
'parameters': {
34+
'max_seq_len': args.max_seq_len,
35+
'batch_size': args.batch_size,
36+
'prob_limit': args.prob_limit
37+
}
38+
}
39+
```
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import argparse
16+
import requests
17+
import json
18+
19+
# yapf: disable
20+
parser = argparse.ArgumentParser()
21+
parser.add_argument("--max_seq_len", default=128, type=int, help="The maximum total input sequence length after tokenization.")
22+
parser.add_argument("--batch_size", default=1, type=int, help="Batch size per GPU/CPU for predicting.")
23+
parser.add_argument("--prob_limit", default=0.5, type=float, help="The limitation of probability for the label.")
24+
args = parser.parse_args()
25+
# yapf: enable
26+
27+
url = "http://0.0.0.0:8189/models/cls_hierarchical"
28+
headers = {"Content-Type": "application/json"}
29+
30+
if __name__ == "__main__":
31+
texts = [
32+
'请问木竭胶囊能同高血压药、氨糖同时服吗?', '低压100*高压140*头涨,想吃点降压药。谢谢!', '脑穿通畸形易发人群有哪些',
33+
'幼儿乱吃丙硫氧嘧啶片怎么办,我也不知道她吃了几片', '如果是可以降血糖的话,血糖值7点多的大概需要吃几个疗程?'
34+
]
35+
data = {
36+
'data': {
37+
'text': texts,
38+
},
39+
'parameters': {
40+
'max_seq_len': args.max_seq_len,
41+
'batch_size': args.batch_size,
42+
'prob_limit': args.prob_limit
43+
}
44+
}
45+
r = requests.post(url=url, headers=headers, data=json.dumps(data))
46+
print(r.text)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from paddlenlp import SimpleServer
16+
from paddlenlp.server import CustomModelHandler, MultiLabelClassificationPostHandler
17+
18+
app = SimpleServer()
19+
app.register('cls_hierarchical',
20+
model_path="../../export",
21+
tokenizer_name='ernie-3.0-medium-zh',
22+
model_handler=CustomModelHandler,
23+
post_handler=MultiLabelClassificationPostHandler)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# 基于PaddleNLP SimpleServing 的服务化部署
2+
3+
## 目录
4+
- [环境准备](#环境准备)
5+
- [Server启动服务](#Server服务启动)
6+
- [其他参数设置](#其他参数设置)
7+
8+
## 环境准备
9+
使用有SimpleServing功能的PaddleNLP版本
10+
```shell
11+
pip install paddlenlp >= 2.4.4
12+
```
13+
## Server服务启动
14+
### 分类任务启动
15+
#### 启动分类 Server 服务
16+
```bash
17+
paddlenlp server server:app --host 0.0.0.0 --port 8189
18+
```
19+
20+
#### 启动分类 Client 服务
21+
```bash
22+
python client.py
23+
```
24+
25+
26+
## 其他参数设置
27+
可以在client端设置 `max_seq_len`, `batch_size` 参数
28+
```python
29+
data = {
30+
'data': {
31+
'text': texts,
32+
'text_pair': text_pairs if len(text_pairs) > 0 else None
33+
},
34+
'parameters': {
35+
'max_seq_len': args.max_seq_len,
36+
'batch_size': args.batch_size
37+
}
38+
}
39+
```
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import argparse
16+
import requests
17+
import json
18+
19+
# yapf: disable
20+
parser = argparse.ArgumentParser()
21+
parser.add_argument("--max_seq_len", default=128, type=int, help="The maximum total input sequence length after tokenization.")
22+
parser.add_argument("--batch_size", default=1, type=int, help="Batch size per GPU/CPU for predicting.")
23+
args = parser.parse_args()
24+
# yapf: enable
25+
26+
url = "http://0.0.0.0:8189/models/cls_multi_class"
27+
headers = {"Content-Type": "application/json"}
28+
29+
if __name__ == "__main__":
30+
texts = [
31+
'黑苦荞茶的功效与作用及食用方法', '交界痣会凸起吗', '检查是否能怀孕挂什么科', '鱼油怎么吃咬破吃还是直接咽下去',
32+
'幼儿挑食的生理原因是'
33+
]
34+
data = {
35+
'data': {
36+
'text': texts,
37+
},
38+
'parameters': {
39+
'max_seq_len': args.max_seq_len,
40+
'batch_size': args.batch_size
41+
}
42+
}
43+
r = requests.post(url=url, headers=headers, data=json.dumps(data))
44+
result_json = json.loads(r.text)
45+
print(result_json)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from paddlenlp import SimpleServer
16+
from paddlenlp.server import CustomModelHandler, MultiClassificationPostHandler
17+
18+
app = SimpleServer()
19+
app.register('cls_multi_class',
20+
model_path="../../export",
21+
tokenizer_name='ernie-3.0-medium-zh',
22+
model_handler=CustomModelHandler,
23+
post_handler=MultiClassificationPostHandler)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# 基于PaddleNLP SimpleServing 的服务化部署
2+
3+
## 目录
4+
- [环境准备](#环境准备)
5+
- [Server启动服务](#Server服务启动)
6+
- [其他参数设置](#其他参数设置)
7+
8+
## 环境准备
9+
使用有SimpleServing功能的PaddleNLP版本
10+
```shell
11+
pip install paddlenlp --upgrade
12+
```
13+
## Server服务启动
14+
### 分类任务启动
15+
#### 启动 分类 Server 服务
16+
```bash
17+
paddlenlp server server:app --host 0.0.0.0 --port 8189
18+
```
19+
20+
#### 分类任务发送服务
21+
```bash
22+
python client.py
23+
```
24+
25+
## 其他参数设置
26+
可以在client端设置 `max_seq_len`, `batch_size`, `prob_limit` 参数
27+
```python
28+
data = {
29+
'data': {
30+
'text': texts,
31+
},
32+
'parameters': {
33+
'max_seq_len': args.max_seq_len,
34+
'batch_size': args.batch_size,
35+
'prob_limit': args.prob_limit
36+
}
37+
}
38+
```
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import argparse
16+
import requests
17+
import json
18+
19+
# yapf: disable
20+
parser = argparse.ArgumentParser()
21+
parser.add_argument("--max_seq_len", default=128, type=int, help="The maximum total input sequence length after tokenization.")
22+
parser.add_argument("--batch_size", default=1, type=int, help="Batch size per GPU/CPU for predicting.")
23+
parser.add_argument("--prob_limit", default=0.5, type=float, help="The limitation of probability for the label.")
24+
args = parser.parse_args()
25+
# yapf: enable
26+
27+
url = "http://0.0.0.0:8189/models/cls_multi_label"
28+
headers = {"Content-Type": "application/json"}
29+
30+
if __name__ == "__main__":
31+
texts = [
32+
'原、被告另购置橱柜、碗架、电磁炉、电饭锅各一个归原告王某某所有。',
33+
'于是原告到儿子就读的幼儿园进行探望,被告碰见后对原告破口大骂,还不让儿子叫原告妈妈,而叫被告现在的妻子做妈妈。',
34+
'由我全额出资购买的联想台式电脑,我均依次放弃。'
35+
]
36+
data = {
37+
'data': {
38+
'text': texts,
39+
},
40+
'parameters': {
41+
'max_seq_len': args.max_seq_len,
42+
'batch_size': args.batch_size,
43+
'prob_limit': args.prob_limit
44+
}
45+
}
46+
r = requests.post(url=url, headers=headers, data=json.dumps(data))
47+
print(json.loads(r.text))
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from paddlenlp import SimpleServer
16+
from paddlenlp.server import CustomModelHandler, MultiLabelClassificationPostHandler
17+
18+
app = SimpleServer()
19+
app.register('cls_multi_label',
20+
model_path="../../export",
21+
tokenizer_name='ernie-3.0-medium-zh',
22+
model_handler=CustomModelHandler,
23+
post_handler=MultiLabelClassificationPostHandler)

model_zoo/ernie-health/cblue/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,22 @@ $ python train_spo.py --batch_size 12 --max_seq_length 300 --learning_rate 6e-5
108108
使用动态图训练结束之后,还可以将动态图参数导出成静态图参数,用于部署推理等,具体代码见export_model.py。静态图参数保存在`output_path`指定路径中。
109109

110110
运行方式:
111+
1. 分类任务静态图模型导出
112+
```shell
113+
python export_model.py --train_dataset CHIP-CDN-2C --params_path=./checkpoint/model_900/ --output_path=./export
114+
```
111115

116+
2. SPO任务静态图模型导出
112117
```shell
113118
python export_model.py --train_dataset CMeIE --params_path=./checkpoint/model_900/ --output_path=./export
114119
```
115120

121+
3. NER任务静态图模型导出
122+
```shell
123+
python export_model.py --train_dataset CMeEE --params_path=./checkpoint/model_1500/ --output_path=./export
124+
```
125+
126+
**NOTICE**: train_dataset分类任务选择填上训练数据集名称,params_path选择最好参数的模型的路径。
116127

117128
[1] CBLUE: A Chinese Biomedical Language Understanding Evaluation Benchmark [pdf](https://arxiv.org/abs/2106.08087) [git](https://github.com/CBLUEbenchmark/CBLUE) [web](https://tianchi.aliyun.com/specials/promotion/2021chinesemedicalnlpleaderboardchallenge)
118129

0 commit comments

Comments
 (0)