-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support paddle serving http deploy for text classification (#3378)
* add_http_deploy
- Loading branch information
Showing
10 changed files
with
288 additions
and
25 deletions.
There are no files selected for viewing
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
4 changes: 2 additions & 2 deletions
4
applications/text_classification/hierarchical/deploy/paddle_serving/config.yml
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
67 changes: 67 additions & 0 deletions
67
applications/text_classification/hierarchical/deploy/paddle_serving/http_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,67 @@ | ||
# 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 numpy as np | ||
from numpy import array | ||
import requests | ||
import json | ||
import sys | ||
|
||
|
||
class Runner(object): | ||
|
||
def __init__( | ||
self, | ||
server_url: str, | ||
): | ||
self.server_url = server_url | ||
|
||
def Run(self, text, label_list): | ||
sentence = np.array([t.encode('utf-8') for t in text], dtype=np.object_) | ||
sentence = sentence.__repr__() | ||
data = {"key": ["sentence"], "value": [sentence]} | ||
data = json.dumps(data) | ||
|
||
ret = requests.post(url=self.server_url, data=data) | ||
ret = ret.json() | ||
for t, l in zip(text, eval(ret['value'][0])): | ||
print("text: ", t) | ||
label = ','.join([label_list[int(ll)] for ll in l.split(',')]) | ||
print("label: ", label) | ||
print("--------------------") | ||
return | ||
|
||
|
||
if __name__ == "__main__": | ||
server_url = "http://127.0.0.1:9878/seq_cls/prediction" | ||
runner = Runner(server_url) | ||
text = [ | ||
"消失的“外企光环”,5月份在华裁员900余人,香饽饽变“臭”了?", "卡车超载致使跨桥侧翻,没那么简单", | ||
"金属卡扣安装不到位,上海乐扣乐扣贸易有限公司将召回捣碎器1162件" | ||
] | ||
label_list = [ | ||
'交往', '交往##会见', '交往##感谢', '交往##探班', '交往##点赞', '交往##道歉', '产品行为', | ||
'产品行为##上映', '产品行为##下架', '产品行为##发布', '产品行为##召回', '产品行为##获奖', '人生', | ||
'人生##产子/女', '人生##出轨', '人生##分手', '人生##失联', '人生##婚礼', '人生##庆生', '人生##怀孕', | ||
'人生##死亡', '人生##求婚', '人生##离婚', '人生##结婚', '人生##订婚', '司法行为', '司法行为##举报', | ||
'司法行为##入狱', '司法行为##开庭', '司法行为##拘捕', '司法行为##立案', '司法行为##约谈', '司法行为##罚款', | ||
'司法行为##起诉', '灾害/意外', '灾害/意外##地震', '灾害/意外##坍/垮塌', '灾害/意外##坠机', | ||
'灾害/意外##洪灾', '灾害/意外##爆炸', '灾害/意外##袭击', '灾害/意外##起火', '灾害/意外##车祸', '竞赛行为', | ||
'竞赛行为##夺冠', '竞赛行为##晋级', '竞赛行为##禁赛', '竞赛行为##胜负', '竞赛行为##退役', '竞赛行为##退赛', | ||
'组织关系', '组织关系##停职', '组织关系##加盟', '组织关系##裁员', '组织关系##解散', '组织关系##解约', | ||
'组织关系##解雇', '组织关系##辞/离职', '组织关系##退出', '组织行为', '组织行为##开幕', '组织行为##游行', | ||
'组织行为##罢工', '组织行为##闭幕', '财经/交易', '财经/交易##上市', '财经/交易##出售/收购', | ||
'财经/交易##加息', '财经/交易##涨价', '财经/交易##涨停', '财经/交易##融资', '财经/交易##跌停', | ||
'财经/交易##降价', '财经/交易##降息' | ||
] | ||
runner.Run(text, label_list) |
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
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
55 changes: 55 additions & 0 deletions
55
applications/text_classification/multi_class/deploy/paddle_serving/http_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,55 @@ | ||
# 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 numpy as np | ||
from numpy import array | ||
import requests | ||
import json | ||
import sys | ||
|
||
|
||
class Runner(object): | ||
|
||
def __init__( | ||
self, | ||
server_url: str, | ||
): | ||
self.server_url = server_url | ||
|
||
def Run(self, text, label_list): | ||
sentence = np.array([t.encode('utf-8') for t in text], dtype=np.object_) | ||
sentence = sentence.__repr__() | ||
data = {"key": ["sentence"], "value": [sentence]} | ||
data = json.dumps(data) | ||
|
||
ret = requests.post(url=self.server_url, data=data) | ||
ret = ret.json() | ||
for t, l in zip(text, eval(ret['value'][0])): | ||
print("text: ", t) | ||
print("label: ", label_list[l]) | ||
print("--------------------") | ||
return | ||
|
||
|
||
if __name__ == "__main__": | ||
server_url = "http://127.0.0.1:9878/seq_cls/prediction" | ||
runner = Runner(server_url) | ||
text = [ | ||
"黑苦荞茶的功效与作用及食用方法", "交界痣会凸起吗", "检查是否能怀孕挂什么科", "鱼油怎么吃咬破吃还是直接咽下去", | ||
"幼儿挑食的生理原因是" | ||
] | ||
label_list = [ | ||
'病情诊断', '治疗方案', '病因分析', '指标解读', '就医建议', '疾病表述', '后果表述', '注意事项', '功效作用', | ||
'医疗费用', '其他' | ||
] | ||
runner.Run(text, label_list) |
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
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
58 changes: 58 additions & 0 deletions
58
applications/text_classification/multi_label/deploy/paddle_serving/http_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,58 @@ | ||
# 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 numpy as np | ||
from numpy import array | ||
import requests | ||
import json | ||
import sys | ||
|
||
|
||
class Runner(object): | ||
|
||
def __init__( | ||
self, | ||
server_url: str, | ||
): | ||
self.server_url = server_url | ||
|
||
def Run(self, text, label_list): | ||
sentence = np.array([t.encode('utf-8') for t in text], dtype=np.object_) | ||
sentence = sentence.__repr__() | ||
data = {"key": ["sentence"], "value": [sentence]} | ||
data = json.dumps(data) | ||
|
||
ret = requests.post(url=self.server_url, data=data) | ||
ret = ret.json() | ||
for t, l in zip(text, eval(ret['value'][0])): | ||
print("text: ", t) | ||
label = ','.join([label_list[int(ll)] for ll in l.split(',')]) | ||
print("label: ", label) | ||
print("--------------------") | ||
return | ||
|
||
|
||
if __name__ == "__main__": | ||
server_url = "http://127.0.0.1:9878/seq_cls/prediction" | ||
runner = Runner(server_url) | ||
text = [ | ||
"五松新村房屋是被告婚前购买的;", | ||
"被告于2016年3月将车牌号为皖B×××××出售了2.7万元,被告通过原告偿还了齐荷花人民币2.6万元,原、被告尚欠齐荷花2万元。", | ||
"2、判令被告返还借婚姻索取的现金33万元,婚前个人存款10万元;", "一、判决原告于某某与被告杨某某离婚;" | ||
] | ||
label_list = [ | ||
'婚后有子女', '限制行为能力子女抚养', '有夫妻共同财产', '支付抚养费', '不动产分割', '婚后分居', '二次起诉离婚', | ||
'按月给付抚养费', '准予离婚', '有夫妻共同债务', '婚前个人财产', '法定离婚', '不履行家庭义务', '存在非婚生子', | ||
'适当帮助', '不履行离婚协议', '损害赔偿', '感情不和分居满二年', '子女随非抚养权人生活', '婚后个人财产' | ||
] | ||
runner.Run(text, label_list) |
Oops, something went wrong.