Skip to content

Commit dc933f3

Browse files
authored
Merge branch 'develop' into cblue
2 parents 66ccc0e + d4f0fa4 commit dc933f3

File tree

102 files changed

+4995
-1759
lines changed

Some content is hidden

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

102 files changed

+4995
-1759
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
简体中文 | [English](./README_en.md)
22

33
<p align="center">
4-
<img src="./docs/imgs/paddlenlp.png" width="718" height ="100" />
4+
<img src="./docs/imgs/paddlenlp.png" align="middle" width="500" />
55
</p>
66

77
------------------------------------------------------------------------------------------
@@ -317,8 +317,9 @@ PaddleNLP提供了多粒度、多场景的NLP应用示例,面向动态图模
317317
- 现在就加入PaddleNLP的技术交流群,一起交流NLP技术吧!⬇️
318318

319319
<div align="center">
320-
<img src="https://user-images.githubusercontent.com/11793384/150080081-8611d041-2e83-440f-9e8c-ba483fea27b5.jpg" width="250" height="300" />
321-
</div>
320+
<img src="https://user-images.githubusercontent.com/11793384/156118227-78837467-5087-40ab-9717-5ab92855cf57.JPG" width="230" height="300" />
321+
</div>
322+
322323

323324

324325

README_en.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
2+
13
English | [简体中文](./README.md)
24

35
<p align="center">
4-
<img src="./docs/imgs/paddlenlp.png" width="718" height ="100" />
6+
<img src="./docs/imgs/paddlenlp.png" align="middle" width="500" />
57
</p>
68

79
------------------------------------------------------------------------------------------
@@ -212,12 +214,13 @@ Welcome to join [PaddleNLP SIG](https://iwenjuan.baidu.com/?code=bkypg8) for con
212214
To connect with other users and contributors, welcome to join our [Slack channel](https://paddlenlp.slack.com/).
213215

214216
### WeChat
215-
Join our WeChat Technical Group for technical exchange right now! ⬇️
217+
Scan the QR code below with your Wechat⬇️. You can access to official technical exchange group. Look forward to your participation.
216218

217219
<div align="center">
218-
<img src="https://user-images.githubusercontent.com/11793384/148376503-3446b288-c88a-41d8-9dbd-dd095d8442ec.png" width="200" height="200" />
220+
<img src="https://user-images.githubusercontent.com/11793384/156119400-1bdbfb6f-9af0-4886-8f98-7d17f386638f.jpg" width="210" height="200" />
219221
</div>
220222

223+
221224
## ChangeLog
222225

223226
For more details about our release, please refer to [ChangeLog](./docs/changelog.md)

applications/neural_search/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ pip install -r requirements.txt
197197
| Domain-adaptive Pretraining + SimCSE | 51.031 | 66.648| 71.338 | 75.676 |80.144| ERNIE 预训练,SimCSE 无监督训练|
198198
| Domain-adaptive Pretraining + SimCSE + In-batch Negatives| **58.248** | **75.099**| **79.813**| **83.801**|**87.733**| ERNIE 预训练,SimCSE 无监督训训练,In-batch Negatives 有监督训练|
199199

200-
从上述表格可以看出,首先利用ERNIE 1.0 做 Domain-adaptive Pretraining ,然后把训练好的模型加载到 SimCSE 上进行无监督训练,最后利用 In-batch Negatives 在有监督数据上进行训练能够获得最佳的性能。
200+
从上述表格可以看出,首先利用ERNIE 1.0 做 Domain-adaptive Pretraining ,然后把训练好的模型加载到 SimCSE 上进行无监督训练,最后利用 In-batch Negatives 在有监督数据上进行训练能够获得最佳的性能。[模型下载](https://paddlenlp.bj.bcebos.com/models/inbatch_model_best.zip),模型的使用方式参考[In-batch Negatives](./recall/in_batch_negative/)
201201

202202
**召回系统搭建**
203203

applications/neural_search/recall/domain_adaptive_pretraining/scripts/run_pretrain_static.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,3 @@ PYTHONPATH=../../../ python -u -m paddle.distributed.launch \
3232
--logging_freq 20\
3333
--eval_freq 1000 \
3434
--device "gpu"
35-
36-
# NOTE: please set use_sharding=True for sharding_degree > 1

applications/neural_search/recall/in_batch_negative/README.md

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,11 @@ python export_to_serving.py \
481481
sh scripts/export_to_serving.sh
482482
```
483483

484-
然后启动server:
484+
Paddle Serving的部署有两种方式,第一种方式是Pipeline的方式,第二种是C++的方式,下面分别介绍这两种方式的用法:
485+
486+
#### Pipeline方式
487+
488+
启动 Pipeline Server:
485489

486490
```
487491
python web_service.py
@@ -517,6 +521,57 @@ PipelineClient::predict before time:1641450851.375738
517521

518522
可以看到客户端发送了2条文本,返回了2个 embedding 向量
519523

524+
#### C++的方式
525+
526+
启动C++的Serving:
527+
528+
```
529+
python -m paddle_serving_server.serve --model serving_server --port 9393 --gpu_id 2 --thread 5 --ir_optim True --use_trt --precision FP16
530+
```
531+
也可以使用脚本:
532+
533+
```
534+
sh deploy/C++/start_server.sh
535+
```
536+
Client 可以使用 http 或者 rpc 两种方式,rpc 的方式为:
537+
538+
```
539+
python deploy/C++/rpc_client.py
540+
```
541+
运行的输出为:
542+
```
543+
I0209 20:40:07.978225 20896 general_model.cpp:490] [client]logid=0,client_cost=395.695ms,server_cost=392.559ms.
544+
time to cost :0.3960278034210205 seconds
545+
{'output_embedding': array([[ 9.01343748e-02, -1.21870913e-01, 1.32834800e-02,
546+
-1.57673359e-01, -2.60387752e-02, 6.98455423e-02,
547+
1.58108603e-02, 3.89952064e-02, 3.22783105e-02,
548+
3.49135026e-02, 7.66086206e-02, -9.12970975e-02,
549+
6.25643134e-02, 7.21886680e-02, 7.03565404e-02,
550+
5.44054210e-02, 3.25332815e-03, 5.01751155e-02,
551+
......
552+
```
553+
可以看到服务端返回了向量
554+
555+
或者使用 http 的客户端访问模式:
556+
557+
```
558+
python deploy/C++/http_client.py
559+
```
560+
运行的输出为:
561+
562+
```
563+
(2, 64)
564+
(2, 64)
565+
outputs {
566+
tensor {
567+
float_data: 0.09013437479734421
568+
float_data: -0.12187091261148453
569+
float_data: 0.01328347995877266
570+
float_data: -0.15767335891723633
571+
......
572+
```
573+
可以看到服务端返回了向量
574+
520575
## Reference
521576

522577
[1] Vladimir Karpukhin, Barlas Oğuz, Sewon Min, Patrick Lewis, Ledell Wu, Sergey Edunov, Danqi Chen, Wen-tau Yih, Dense Passage Retrieval for Open-Domain Question Answering, Preprint 2020.
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# coding:utf-8
2+
# pylint: disable=doc-string-missing
3+
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
import sys
18+
import time
19+
import numpy as np
20+
import requests
21+
import json
22+
23+
from paddle_serving_client import HttpClient
24+
import paddlenlp as ppnlp
25+
26+
27+
def convert_example(example,
28+
tokenizer,
29+
max_seq_length=512,
30+
pad_to_max_seq_len=True):
31+
list_input_ids = []
32+
list_token_type_ids = []
33+
for text in example:
34+
encoded_inputs = tokenizer(
35+
text=text,
36+
max_seq_len=max_seq_length,
37+
pad_to_max_seq_len=pad_to_max_seq_len)
38+
input_ids = encoded_inputs["input_ids"]
39+
token_type_ids = encoded_inputs["token_type_ids"]
40+
41+
list_input_ids.append(input_ids)
42+
list_token_type_ids.append(token_type_ids)
43+
return list_input_ids, list_token_type_ids
44+
45+
46+
# 启动python客户端
47+
endpoint_list = ['127.0.0.1:9393']
48+
client = HttpClient()
49+
client.load_client_config('serving_client')
50+
client.connect(endpoint_list)
51+
feed_names = client.feed_names_
52+
fetch_names = client.fetch_names_
53+
print(feed_names)
54+
print(fetch_names)
55+
56+
# 创建tokenizer
57+
tokenizer = ppnlp.transformers.ErnieTokenizer.from_pretrained('ernie-1.0')
58+
max_seq_len = 64
59+
60+
# 数据预处理
61+
62+
list_data = ['国有企业引入非国有资本对创新绩效的影响——基于制造业国有上市公司的经验证据.', '面向生态系统服务的生态系统分类方案研发与应用']
63+
# for i in range(5):
64+
# list_data.extend(list_data)
65+
# print(len(list_data))
66+
examples = convert_example(list_data, tokenizer, max_seq_length=max_seq_len)
67+
print(examples)
68+
69+
feed_dict = {}
70+
feed_dict['input_ids'] = np.array(examples[0])
71+
feed_dict['token_type_ids'] = np.array(examples[1])
72+
73+
print(feed_dict['input_ids'].shape)
74+
print(feed_dict['token_type_ids'].shape)
75+
76+
# batch设置为True表示的是批量预测
77+
b_start = time.time()
78+
result = client.predict(feed=feed_dict, fetch=fetch_names, batch=True)
79+
b_end = time.time()
80+
print(result)
81+
print("time to cost :{} seconds".format(b_end - b_start))
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# coding:utf-8
2+
# pylint: disable=doc-string-missing
3+
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
import sys
18+
import time
19+
import numpy as np
20+
21+
from paddle_serving_client import Client
22+
import paddlenlp as ppnlp
23+
24+
25+
def convert_example(example,
26+
tokenizer,
27+
max_seq_length=512,
28+
pad_to_max_seq_len=True):
29+
list_input_ids = []
30+
list_token_type_ids = []
31+
for text in example:
32+
encoded_inputs = tokenizer(
33+
text=text,
34+
max_seq_len=max_seq_length,
35+
pad_to_max_seq_len=pad_to_max_seq_len)
36+
input_ids = encoded_inputs["input_ids"]
37+
token_type_ids = encoded_inputs["token_type_ids"]
38+
list_input_ids.append(input_ids)
39+
list_token_type_ids.append(token_type_ids)
40+
return list_input_ids, list_token_type_ids
41+
42+
43+
# 启动python客户端
44+
endpoint_list = ['127.0.0.1:9393']
45+
client = Client()
46+
client.load_client_config('serving_client')
47+
client.connect(endpoint_list)
48+
feed_names = client.feed_names_
49+
fetch_names = client.fetch_names_
50+
print(feed_names)
51+
print(fetch_names)
52+
53+
# 创建tokenizer
54+
tokenizer = ppnlp.transformers.ErnieTokenizer.from_pretrained('ernie-1.0')
55+
max_seq_len = 64
56+
57+
# 数据预处理
58+
59+
list_data = ['国有企业引入非国有资本对创新绩效的影响——基于制造业国有上市公司的经验证据.', '面向生态系统服务的生态系统分类方案研发与应用']
60+
# for i in range(5):
61+
# list_data.extend(list_data)
62+
# print(len(list_data))
63+
examples = convert_example(list_data, tokenizer, max_seq_length=max_seq_len)
64+
print(examples)
65+
66+
feed_dict = {}
67+
feed_dict['input_ids'] = np.array(examples[0])
68+
feed_dict['token_type_ids'] = np.array(examples[1])
69+
70+
print(feed_dict['input_ids'].shape)
71+
print(feed_dict['token_type_ids'].shape)
72+
# batch设置为True表示的是批量预测
73+
b_start = time.time()
74+
result = client.predict(feed=feed_dict, fetch=fetch_names, batch=True)
75+
b_end = time.time()
76+
print("time to cost :{} seconds".format(b_end - b_start))
77+
print(result)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
python -m paddle_serving_server.serve --model serving_server --port 9393 --gpu_id 2 --thread 5 --ir_optim True --use_trt --precision FP16

applications/neural_search/recall/in_batch_negative/deploy/python/config_nlp.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ op:
2222
local_service_conf:
2323
# client类型,包括brpc, grpc和local_predictor.local_predictor不启动Serving服务,进程内预测
2424
client_type: local_predictor
25+
#ir_optim
26+
ir_optim: True
2527
# device_type, 0=cpu, 1=gpu, 2=tensorRT, 3=arm cpu, 4=kunlun xpu
2628
device_type: 1
2729
# 计算硬件ID,当devices为""或不写时为CPU预测;当devices为"0", "0,1,2"时为GPU预测,表示使用的GPU卡

applications/neural_search/recall/in_batch_negative/deploy/python/rpc_client.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
import time
15+
import numpy as np
1416

1517
from paddle_serving_server.pipeline import PipelineClient
16-
import numpy as np
1718

1819
client = PipelineClient()
1920
client.connect(['127.0.0.1:8080'])
@@ -27,8 +28,11 @@
2728
feed[str(i)] = item
2829

2930
print(feed)
31+
start_time = time.time()
3032
ret = client.predict(feed_dict=feed)
31-
# print(ret)
33+
end_time = time.time()
34+
print("time to cost :{} seconds".format(end_time - start_time))
35+
3236
result = np.array(eval(ret.value[0]))
3337
print(ret.key)
3438
print(result.shape)

0 commit comments

Comments
 (0)