Skip to content

Commit b7dd5ce

Browse files
author
tianxin
authored
Rename strategy according to the paper (#420)
1 parent d913275 commit b7dd5ce

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

examples/semantic_indexing/README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
语义索引库提供了前沿语义索引策略的训练、语义索引模型的效果评估方案、支持用户基于我们开源的语义索引模型进行文本 Pair 的相似度计算或者 Embedding 语义表示抽取。
66

7-
我们基于 ERNIE1.0 热启,分别采用 BatchNeg 策略和 HardestNeg 策略开源了 [batch_neg_v1.0](https://paddlenlp.bj.bcebos.com/models/semantic_index/batch_neg_v1.0.tar)[hardest_neg_v1.0](https://paddlenlp.bj.bcebos.com/models/semantic_index/hardest_neg_v1.0.tar) 模型,相比 Baseline 模型效果有显著提升:
7+
我们基于 ERNIE1.0 热启,分别采用 [In-batch negatives](https://arxiv.org/abs/2004.04906) 策略和 HardestNeg 策略开源了 [batch_neg_v1.0](https://paddlenlp.bj.bcebos.com/models/semantic_index/batch_neg_v1.0.tar)[hardest_neg_v1.0](https://paddlenlp.bj.bcebos.com/models/semantic_index/hardest_neg_v1.0.tar) 模型,相比 Baseline 模型效果有显著提升:
88

99
## 效果评估
1010
| 模型 | Recall@10 | Recall@50 |策略简要说明|
1111
| ------------ | ------------ | ------------ |--------- |
1212
| Baseline | 46.99 | 60.84 | 标准 pair-wise 训练范式,通过随机采样产生负样本|
13-
| BatchNeg | 51.20(**+4.21**) | 67.24(**+6.4**) | 在 Batch 内同时使用 batch_size 个负样本进行训练|
14-
| HardestNeg| 50.22(**+3.23**) | 65.17(**+4.33**) |<div style="width: 340pt"> 在 Batch 内先挖掘最难负样本,然后进行 pair-wise 训练</div>|
13+
| [In-batch negatives](https://arxiv.org/abs/2004.04906) | 51.20(**+4.21**) | 67.24(**+6.4**) | 在 Batch 内同时使用 batch_size 个负样本进行训练|
14+
| HardestNeg | 50.22(**+3.23**) | 65.17(**+4.33**) |<div style="width: 340pt"> 在 Batch 内先挖掘最难负样本,然后进行 pair-wise 训练</div>|
1515

1616

1717
## 语义索引预训练模型下载
@@ -30,7 +30,7 @@
3030
#### 构造训练集
3131
从开源语义相似度任务评测数据集([LCQMC](http://icrc.hitsz.edu.cn/Article/show/171.html)[BQ Corpus](http://icrc.hitsz.edu.cn/Article/show/175.html)[PAWS-X](https://github.com/google-research-datasets/paws/tree/master/pawsx))的训练集和测试集中抽取出所有语义相似的文本 Pair 作为训练集 [semantic_pair_train.tsv](https://paddlenlp.bj.bcebos.com/models/semantic_index/semantic_pair_train.tsv)
3232

33-
BatchNeg 策略和 HardestNeg 策略训练数据每一行由 `tab` 分隔的语义相似的文本 Pair 对,样例数据如下:
33+
[In-batch negatives](https://arxiv.org/abs/2004.04906) 策略和 HardestNeg 策略训练数据每一行由 `tab` 分隔的语义相似的文本 Pair 对,样例数据如下:
3434
```
3535
欢打篮球的男生喜欢什么样的女生 爱打篮球的男生喜欢什么样的女生
3636
我手机丢了,我想换个手机 我想买个新手机,求推荐
@@ -59,10 +59,10 @@ BatchNeg 策略和 HardestNeg 策略训练数据每一行由 `tab` 分隔的语
5959

6060
## 代码结构及说明
6161
```
62-
|—— train_batch_neg.py # BatchNeg 策略的训练主脚本
62+
|—— train_batch_neg.py # In-batch negatives 策略的训练主脚本
6363
|—— train_hardest_neg.py # HardestNeg 策略的训练主脚本
6464
|—— batch_negative
65-
|—— model.py # BatchNeg 策略核心网络结构
65+
|—— model.py # In-batch negatives 策略核心网络结构
6666
|——hardest_negative
6767
|—— model.py # HardestNeg 策略核心网络结构
6868
|—— ann_util.py # Ann 建索引库相关函数
@@ -74,8 +74,8 @@ BatchNeg 策略和 HardestNeg 策略训练数据每一行由 `tab` 分隔的语
7474
```
7575

7676
## 模型训练
77-
### 基于 BatchNeg 策略训练
78-
以我们提供的语义相似度训练数据为例,通过如下命令,指定 GPU 0,1,2,3 卡, 基于 BatchNeg 策略开始训练模型
77+
### 基于 [In-batch negatives](https://arxiv.org/abs/2004.04906) 策略训练
78+
以我们提供的语义相似度训练数据为例,通过如下命令,指定 GPU 0,1,2,3 卡, 基于 In-batch negatives 策略开始训练模型
7979

8080
```
8181
python -u -m paddle.distributed.launch --gpus "0,1,2,3" \
@@ -206,7 +206,7 @@ python -u -m paddle.distributed.launch --gpus "0" --log_dir "recall_log/" \
206206
```
207207

208208
### 开始预测
209-
以上述 demo 数据为例,运行如下命令基于我们开源的 BatchNeg 策略语义索引模型开始计算文本 Pair 的语义相似度:
209+
以上述 demo 数据为例,运行如下命令基于我们开源的 [In-batch negatives](https://arxiv.org/abs/2004.04906) 策略语义索引模型开始计算文本 Pair 的语义相似度:
210210
```
211211
python -u -m paddle.distributed.launch --gpus "0" \
212212
predict.py \
@@ -233,18 +233,18 @@ python -u -m paddle.distributed.launch --gpus "0" \
233233
```
234234

235235
## 模型介绍
236-
简要介绍 BatchNeg 策略和 HardestNeg 策略思路
236+
简要介绍 In-batch negatives 策略和 HardestNeg 策略思路
237237

238-
### BatchNeg 核心思路
238+
### [In-batch negatives](https://arxiv.org/abs/2004.04906) 核心思路
239239

240-
BatchNeg 策略的训练数据为语义相似的 Pair 对,如下所示为 Batch size = 4 的训练数据样例:
240+
In-batch negatives 策略的训练数据为语义相似的 Pair 对,如下所示为 Batch size = 4 的训练数据样例:
241241
```
242242
我手机丢了,我想换个手机 我想买个新手机,求推荐
243243
求秋色之空漫画全集 求秋色之空全集漫画
244244
学日语软件手机上的 手机学日语的软件
245245
侠盗飞车罪恶都市怎样改车 侠盗飞车罪恶都市怎么改车
246246
```
247-
BatchNeg 策略核心是在 1 个 Batch 内同时基于 N 个负例进行梯度更新,将Batch 内除自身之外其它所有 *Source Text* 的相似文本 *Target Text* 作为负例,例如: 上例中 `我手机丢了,我想换个手机` 有 1 个正例(`1.我想买个新手机,求推荐`),3 个负例(`1.求秋色之空全集漫画``2.手机学日语的软件``3.侠盗飞车罪恶都市怎么改车`)。
247+
In-batch negatives 策略核心是在 1 个 Batch 内同时基于 N 个负例进行梯度更新,将Batch 内除自身之外其它所有 *Source Text* 的相似文本 *Target Text* 作为负例,例如: 上例中 `我手机丢了,我想换个手机` 有 1 个正例(`1.我想买个新手机,求推荐`),3 个负例(`1.求秋色之空全集漫画``2.手机学日语的软件``3.侠盗飞车罪恶都市怎么改车`)。
248248

249249
### HardestNeg 核心思路
250250
HardestNeg 策略核心是在 1 个 Batch 内的所有负样本中先挖掘出最难区分的负样本,基于最难负样本进行梯度更新。例如: 上例中 *Source Text*: `我手机丢了,我想换个手机` 有 3 个负例(`1.求秋色之空全集漫画``2.手机学日语的软件``3.侠盗飞车罪恶都市怎么改车`),其中最难区分的负例是 `手机学日语的软件`,模型训练过程中不断挖掘出类似这样的最难负样本,然后基于最难负样本进行梯度更新。

0 commit comments

Comments
 (0)