File tree 4 files changed +52
-6
lines changed
slm/applications/neural_search/recall/in_batch_negative
4 files changed +52
-6
lines changed Original file line number Diff line number Diff line change @@ -182,14 +182,15 @@ Recall@K 召回率是指预测的前 topK(top-k 是指从最后的按得分排
182
182
183
183
如果使用 CPU 进行训练,则需要吧` --gpus ` 参数去除,然后吧` device ` 设置成 cpu 即可,详细请参考 train_batch_neg.sh 文件的训练设置
184
184
185
+ 如果不存在``` checkpoints/inbatch ``` , 需要在命令行运行``` mkdir -p checkpoints/inbatch ``` 创建相关目录(如果运行脚本进行训练则不需要)。
186
+
185
187
然后运行下面的命令使用 GPU 训练,得到语义索引模型:
186
188
187
189
```
188
- root_path=inbatch
189
190
python -u -m paddle.distributed.launch --gpus "0,1,2,3" \
190
191
train_batch_neg.py \
191
192
--device gpu \
192
- --save_dir ./checkpoints/${root_path} \
193
+ --save_dir ./checkpoints/inbatch \
193
194
--batch_size 64 \
194
195
--learning_rate 5E-5 \
195
196
--epochs 3 \
@@ -464,7 +465,7 @@ python deploy/python/predict.py \
464
465
也可以运行下面的 bash 脚本:
465
466
466
467
```
467
- sh deploy.sh
468
+ sh deploy/python/deploy .sh
468
469
```
469
470
最终输出的是256维度的特征向量和句子对的预测概率:
470
471
Original file line number Diff line number Diff line change 12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
14
14
15
- python predict.py --model_dir=../../output
15
+ python ./deploy/python/predict.py --model_dir=./output \
16
+ --model_name_or_path rocketqa-zh-base-query-encoder
Original file line number Diff line number Diff line change 22
22
from paddlenlp .data import Pad , Tuple
23
23
from paddlenlp .transformers import AutoTokenizer
24
24
from paddlenlp .utils .log import logger
25
+ from paddlenlp .utils .env import PADDLE_INFERENCE_MODEL_SUFFIX , PADDLE_INFERENCE_WEIGHTS_SUFFIX
25
26
26
27
sys .path .append ("." )
27
28
@@ -87,8 +88,8 @@ def __init__(
87
88
self .max_seq_length = max_seq_length
88
89
self .batch_size = batch_size
89
90
90
- model_file = model_dir + "/inference.pdmodel "
91
- params_file = model_dir + "/inference.pdiparams "
91
+ model_file = model_dir + f "/inference{ PADDLE_INFERENCE_MODEL_SUFFIX } "
92
+ params_file = model_dir + f "/inference{ PADDLE_INFERENCE_WEIGHTS_SUFFIX } "
92
93
if not os .path .exists (model_file ):
93
94
raise ValueError ("not find model file path {}" .format (model_file ))
94
95
if not os .path .exists (params_file ):
Original file line number Diff line number Diff line change
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
+ root_dir=" ./checkpoints/inbatch"
16
+
17
+ if [ ! -d " $root_dir " ]; then
18
+ mkdir -p " $root_dir "
19
+ echo " Created directory: $root_dir "
20
+ else
21
+ echo " Directory already exists: $root_dir "
22
+ fi
23
+
24
+ python -u -m paddle.distributed.launch --gpus " 0" \
25
+ train_batch_neg.py \
26
+ --device gpu \
27
+ --save_dir ${root_dir} \
28
+ --batch_size 64 \
29
+ --learning_rate 5E-5 \
30
+ --epochs 3 \
31
+ --output_emb_size 256 \
32
+ --model_name_or_path rocketqa-zh-base-query-encoder \
33
+ --save_steps 10 \
34
+ --max_seq_length 64 \
35
+ --margin 0.2 \
36
+ --train_set_file recall/train.csv \
37
+ --recall_result_dir " recall_result_dir" \
38
+ --recall_result_file " recall_result.txt" \
39
+ --hnsw_m 100 \
40
+ --hnsw_ef 100 \
41
+ --recall_num 50 \
42
+ --similar_text_pair_file " recall/dev.csv" \
43
+ --corpus_file " recall/corpus.csv"
You can’t perform that action at this time.
0 commit comments