-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
45 changed files
with
2,099 additions
and
22 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
applications/text_classification/hierarchical/deploy/SimpleServing/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# 基于PaddleNLP SimpleServing 的服务化部署 | ||
|
||
## 目录 | ||
- [环境准备](#环境准备) | ||
- [Server启动服务](#Server服务启动) | ||
- [其他参数设置](#其他参数设置) | ||
|
||
## 环境准备 | ||
使用有SimpleServing功能的PaddleNLP版本 | ||
```shell | ||
pip install paddlenlp --upgrade | ||
``` | ||
## Server服务启动 | ||
### 分类任务启动 | ||
#### 启动 分类 Server 服务 | ||
```bash | ||
paddlenlp server server:app --host 0.0.0.0 --port 8189 | ||
``` | ||
|
||
#### 分类任务发送服务 | ||
```bash | ||
python client.py | ||
``` | ||
|
||
|
||
## 其他参数设置 | ||
可以在client端设置 `max_seq_len`, `batch_size`, `prob_limit` 参数 | ||
```python | ||
data = { | ||
'data': { | ||
'text': texts, | ||
}, | ||
'parameters': { | ||
'max_seq_len': args.max_seq_len, | ||
'batch_size': args.batch_size, | ||
'prob_limit': args.prob_limit | ||
} | ||
} | ||
``` |
46 changes: 46 additions & 0 deletions
46
applications/text_classification/hierarchical/deploy/SimpleServing/client.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import argparse | ||
import requests | ||
import json | ||
|
||
# yapf: disable | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--max_seq_len", default=128, type=int, help="The maximum total input sequence length after tokenization.") | ||
parser.add_argument("--batch_size", default=1, type=int, help="Batch size per GPU/CPU for predicting.") | ||
parser.add_argument("--prob_limit", default=0.5, type=float, help="The limitation of probability for the label.") | ||
args = parser.parse_args() | ||
# yapf: enable | ||
|
||
url = "http://0.0.0.0:8189/models/cls_hierarchical" | ||
headers = {"Content-Type": "application/json"} | ||
|
||
if __name__ == "__main__": | ||
texts = [ | ||
'请问木竭胶囊能同高血压药、氨糖同时服吗?', '低压100*高压140*头涨,想吃点降压药。谢谢!', '脑穿通畸形易发人群有哪些', | ||
'幼儿乱吃丙硫氧嘧啶片怎么办,我也不知道她吃了几片', '如果是可以降血糖的话,血糖值7点多的大概需要吃几个疗程?' | ||
] | ||
data = { | ||
'data': { | ||
'text': texts, | ||
}, | ||
'parameters': { | ||
'max_seq_len': args.max_seq_len, | ||
'batch_size': args.batch_size, | ||
'prob_limit': args.prob_limit | ||
} | ||
} | ||
r = requests.post(url=url, headers=headers, data=json.dumps(data)) | ||
print(r.text) |
23 changes: 23 additions & 0 deletions
23
applications/text_classification/hierarchical/deploy/SimpleServing/server.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from paddlenlp import SimpleServer | ||
from paddlenlp.server import CustomModelHandler, MultiLabelClassificationPostHandler | ||
|
||
app = SimpleServer() | ||
app.register('cls_hierarchical', | ||
model_path="../../export", | ||
tokenizer_name='ernie-3.0-medium-zh', | ||
model_handler=CustomModelHandler, | ||
post_handler=MultiLabelClassificationPostHandler) |
39 changes: 39 additions & 0 deletions
39
applications/text_classification/multi_class/deploy/SimpleServing/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# 基于PaddleNLP SimpleServing 的服务化部署 | ||
|
||
## 目录 | ||
- [环境准备](#环境准备) | ||
- [Server启动服务](#Server服务启动) | ||
- [其他参数设置](#其他参数设置) | ||
|
||
## 环境准备 | ||
使用有SimpleServing功能的PaddleNLP版本 | ||
```shell | ||
pip install paddlenlp >= 2.4.4 | ||
``` | ||
## Server服务启动 | ||
### 分类任务启动 | ||
#### 启动分类 Server 服务 | ||
```bash | ||
paddlenlp server server:app --host 0.0.0.0 --port 8189 | ||
``` | ||
|
||
#### 启动分类 Client 服务 | ||
```bash | ||
python client.py | ||
``` | ||
|
||
|
||
## 其他参数设置 | ||
可以在client端设置 `max_seq_len`, `batch_size` 参数 | ||
```python | ||
data = { | ||
'data': { | ||
'text': texts, | ||
'text_pair': text_pairs if len(text_pairs) > 0 else None | ||
}, | ||
'parameters': { | ||
'max_seq_len': args.max_seq_len, | ||
'batch_size': args.batch_size | ||
} | ||
} | ||
``` |
45 changes: 45 additions & 0 deletions
45
applications/text_classification/multi_class/deploy/SimpleServing/client.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import argparse | ||
import requests | ||
import json | ||
|
||
# yapf: disable | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--max_seq_len", default=128, type=int, help="The maximum total input sequence length after tokenization.") | ||
parser.add_argument("--batch_size", default=1, type=int, help="Batch size per GPU/CPU for predicting.") | ||
args = parser.parse_args() | ||
# yapf: enable | ||
|
||
url = "http://0.0.0.0:8189/models/cls_multi_class" | ||
headers = {"Content-Type": "application/json"} | ||
|
||
if __name__ == "__main__": | ||
texts = [ | ||
'黑苦荞茶的功效与作用及食用方法', '交界痣会凸起吗', '检查是否能怀孕挂什么科', '鱼油怎么吃咬破吃还是直接咽下去', | ||
'幼儿挑食的生理原因是' | ||
] | ||
data = { | ||
'data': { | ||
'text': texts, | ||
}, | ||
'parameters': { | ||
'max_seq_len': args.max_seq_len, | ||
'batch_size': args.batch_size | ||
} | ||
} | ||
r = requests.post(url=url, headers=headers, data=json.dumps(data)) | ||
result_json = json.loads(r.text) | ||
print(result_json) |
23 changes: 23 additions & 0 deletions
23
applications/text_classification/multi_class/deploy/SimpleServing/server.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from paddlenlp import SimpleServer | ||
from paddlenlp.server import CustomModelHandler, MultiClassificationPostHandler | ||
|
||
app = SimpleServer() | ||
app.register('cls_multi_class', | ||
model_path="../../export", | ||
tokenizer_name='ernie-3.0-medium-zh', | ||
model_handler=CustomModelHandler, | ||
post_handler=MultiClassificationPostHandler) |
38 changes: 38 additions & 0 deletions
38
applications/text_classification/multi_label/deploy/SimpleServing/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# 基于PaddleNLP SimpleServing 的服务化部署 | ||
|
||
## 目录 | ||
- [环境准备](#环境准备) | ||
- [Server启动服务](#Server服务启动) | ||
- [其他参数设置](#其他参数设置) | ||
|
||
## 环境准备 | ||
使用有SimpleServing功能的PaddleNLP版本 | ||
```shell | ||
pip install paddlenlp --upgrade | ||
``` | ||
## Server服务启动 | ||
### 分类任务启动 | ||
#### 启动 分类 Server 服务 | ||
```bash | ||
paddlenlp server server:app --host 0.0.0.0 --port 8189 | ||
``` | ||
|
||
#### 分类任务发送服务 | ||
```bash | ||
python client.py | ||
``` | ||
|
||
## 其他参数设置 | ||
可以在client端设置 `max_seq_len`, `batch_size`, `prob_limit` 参数 | ||
```python | ||
data = { | ||
'data': { | ||
'text': texts, | ||
}, | ||
'parameters': { | ||
'max_seq_len': args.max_seq_len, | ||
'batch_size': args.batch_size, | ||
'prob_limit': args.prob_limit | ||
} | ||
} | ||
``` |
47 changes: 47 additions & 0 deletions
47
applications/text_classification/multi_label/deploy/SimpleServing/client.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import argparse | ||
import requests | ||
import json | ||
|
||
# yapf: disable | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--max_seq_len", default=128, type=int, help="The maximum total input sequence length after tokenization.") | ||
parser.add_argument("--batch_size", default=1, type=int, help="Batch size per GPU/CPU for predicting.") | ||
parser.add_argument("--prob_limit", default=0.5, type=float, help="The limitation of probability for the label.") | ||
args = parser.parse_args() | ||
# yapf: enable | ||
|
||
url = "http://0.0.0.0:8189/models/cls_multi_label" | ||
headers = {"Content-Type": "application/json"} | ||
|
||
if __name__ == "__main__": | ||
texts = [ | ||
'原、被告另购置橱柜、碗架、电磁炉、电饭锅各一个归原告王某某所有。', | ||
'于是原告到儿子就读的幼儿园进行探望,被告碰见后对原告破口大骂,还不让儿子叫原告妈妈,而叫被告现在的妻子做妈妈。', | ||
'由我全额出资购买的联想台式电脑,我均依次放弃。' | ||
] | ||
data = { | ||
'data': { | ||
'text': texts, | ||
}, | ||
'parameters': { | ||
'max_seq_len': args.max_seq_len, | ||
'batch_size': args.batch_size, | ||
'prob_limit': args.prob_limit | ||
} | ||
} | ||
r = requests.post(url=url, headers=headers, data=json.dumps(data)) | ||
print(json.loads(r.text)) |
23 changes: 23 additions & 0 deletions
23
applications/text_classification/multi_label/deploy/SimpleServing/server.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from paddlenlp import SimpleServer | ||
from paddlenlp.server import CustomModelHandler, MultiLabelClassificationPostHandler | ||
|
||
app = SimpleServer() | ||
app.register('cls_multi_label', | ||
model_path="../../export", | ||
tokenizer_name='ernie-3.0-medium-zh', | ||
model_handler=CustomModelHandler, | ||
post_handler=MultiLabelClassificationPostHandler) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.