|
2 | 2 |
|
3 | 3 | ## 安装 |
4 | 4 |
|
5 | | -推荐安装gpu版本的[PaddlePaddle](https://www.paddlepaddle.org.cn/install/quick?docurl=/documentation/docs/zh/install/conda/linux-conda.html),以cuda11.7的paddle为例,安装命令如下: |
| 5 | +推荐安装 gpu 版本的[PaddlePaddle](https://www.paddlepaddle.org.cn/install/quick?docurl=/documentation/docs/zh/install/conda/linux-conda.html),以 cuda11.7的 paddle 为例,安装命令如下: |
6 | 6 |
|
7 | 7 | ``` |
8 | 8 | conda install nccl -c conda-forge |
9 | 9 | conda install paddlepaddle-gpu==2.6.1 -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/Paddle/ -c conda-forge |
10 | 10 | ``` |
11 | 11 | 安装其他依赖: |
12 | 12 | ``` |
| 13 | +pip install git+https://github.com/PaddlePaddle/PaddleNLP.git@develop |
13 | 14 | pip install -r requirements.txt |
14 | 15 | ``` |
15 | 16 |
|
16 | | -下载DuReader-Retrieval中文数据集: |
| 17 | +下载 DuReader-Retrieval 中文数据集: |
17 | 18 |
|
18 | 19 | ``` |
19 | 20 | cd data |
@@ -42,34 +43,34 @@ python train.py --do_train \ |
42 | 43 | --use_matryoshka |
43 | 44 | ``` |
44 | 45 |
|
45 | | -- `model_name_or_path`: 选择预训练模型,可选rocketqa-zh-base-query-encoder |
| 46 | +- `model_name_or_path`: 选择预训练模型,可选 rocketqa-zh-base-query-encoder |
46 | 47 | - `output_dir`: 模型保存路径 |
47 | | -- `train_data`: 训练数据集路径,这里使用的是dureader中文数据集 |
48 | | -- `overwrite_output_dir`: 是否覆盖模型保存路径,默认为False |
49 | | -- `fine_tune_type`: 训练模式,可选sft和lora, bitfit等策略 |
50 | | -- `sentence_pooling_method`: 句子池化方法,可选cls和mean, cls为CLS层,mean为平均池化 |
| 48 | +- `train_data`: 训练数据集路径,这里使用的是 dureader 中文数据集 |
| 49 | +- `overwrite_output_dir`: 是否覆盖模型保存路径,默认为 False |
| 50 | +- `fine_tune_type`: 训练模式,可选 sft 和 lora, bitfit 等策略 |
| 51 | +- `sentence_pooling_method`: 句子池化方法,可选 cls 和 mean, cls 为 CLS 层,mean 为平均池化 |
51 | 52 | - `num_train_epochs`: 训练轮数 |
52 | | -- `per_device_train_batch_size`: 单卡训练batch大小 |
| 53 | +- `per_device_train_batch_size`: 单卡训练 batch 大小 |
53 | 54 | - `learning_rate`: 学习率 |
54 | | -- `train_group_size`: 每个训练集正负样本的数据,默认为8,例如train_group_size=4,则每个训练集包含1个正样本和3个负样本 |
| 55 | +- `train_group_size`: 每个训练集正负样本的数据,默认为8,例如 train_group_size=4,则每个训练集包含1个正样本和3个负样本 |
55 | 56 | - `max_example_num_per_dataset`: 每个训练集的最大样本数,默认为100000000 |
56 | | -- `recompute`: 是否重新计算,默认为False |
57 | | -- `query_max_len`: query的最大长度,默认为32 |
58 | | -- `query_instruction_for_retrieval`: query的检索指令,默认为None |
59 | | -- `passage_instruction_for_retrieval`: passage的检索指令,默认为None |
60 | | -- `passage_max_len`: passage的最大长度,默认为512 |
61 | | -- `use_matryoshka`: 是否使用俄罗斯套娃策略(matryoshka),默认为False |
| 57 | +- `recompute`: 是否重新计算,默认为 False |
| 58 | +- `query_max_len`: query 的最大长度,默认为32 |
| 59 | +- `query_instruction_for_retrieval`: query 的检索指令,默认为 None |
| 60 | +- `passage_instruction_for_retrieval`: passage 的检索指令,默认为 None |
| 61 | +- `passage_max_len`: passage 的最大长度,默认为512 |
| 62 | +- `use_matryoshka`: 是否使用俄罗斯套娃策略(matryoshka),默认为 False |
62 | 63 | - `matryoshka_dims`: 俄罗斯套娃策略的维度,默认为[64, 128, 256, 512, 768] |
63 | 64 | - `matryoshka_loss_weights`: 俄罗斯套娃策略的损失权重,默认为[1, 1, 1, 1, 1] |
64 | | -- `use_inbatch_neg`: 是否使用in batch negatives策略,默认为False |
65 | | -- `use_flash_attention`: 是否使用flash attention,默认为False |
66 | | -- `temperature`: in batch negatives策略的temperature参数,默认为0.02 |
67 | | -- `negatives_cross_device`: 跨设备in batch negatives策略,默认为False |
68 | | -- `margin`: in batch negatives策略的margin参数,默认为0.2 |
| 65 | +- `use_inbatch_neg`: 是否使用 in batch negatives 策略,默认为 False |
| 66 | +- `use_flash_attention`: 是否使用 flash attention,默认为 False |
| 67 | +- `temperature`: in batch negatives 策略的 temperature 参数,默认为0.02 |
| 68 | +- `negatives_cross_device`: 跨设备 in batch negatives 策略,默认为 False |
| 69 | +- `margin`: in batch negatives 策略的 margin 参数,默认为0.2 |
69 | 70 |
|
70 | 71 | ### 多卡训练 |
71 | 72 |
|
72 | | -单卡训练效率过低,batch_size较小,建议使用多卡训练,对于对比学习训练推荐使用大batch_size,多卡训练,示例命令如下: |
| 73 | +单卡训练效率过低,batch_size 较小,建议使用多卡训练,对于对比学习训练推荐使用大 batch_size,多卡训练,示例命令如下: |
73 | 74 |
|
74 | 75 | ``` |
75 | 76 | python -m paddle.distributed.launch --gpus "1,2,3,4" train.py --do_train \ |
@@ -100,21 +101,42 @@ python evaluation/benchmarks.py --model_type bert \ |
100 | 101 | --query_max_length 64 \ |
101 | 102 | --passage_max_length 512 \ |
102 | 103 | ``` |
103 | | -- `model_type`: 模型的类似,可选bert或roberta等等 |
104 | | -- `query_model`: query向量模型的路径 |
105 | | -- `passage_model`: passage向量模型的路径 |
106 | | -- `query_max_length`: query的最大长度 |
107 | | -- `passage_max_length`: passage的最大长度 |
108 | | -- `evaluate_all`: 是否评估所有的checkpoint,默认为False,即只评估指定的checkpoint |
| 104 | +- `model_type`: 模型的类似,可选 bert 或 roberta 等等 |
| 105 | +- `query_model`: query 向量模型的路径 |
| 106 | +- `passage_model`: passage 向量模型的路径 |
| 107 | +- `query_max_length`: query 的最大长度 |
| 108 | +- `passage_max_length`: passage 的最大长度 |
| 109 | +- `evaluate_all`: 是否评估所有的 checkpoint,默认为 False,即只评估指定的 checkpoint |
109 | 110 | - `checkpoint_dir`: 与`evaluate_all`一起使用 |
110 | 111 |
|
111 | 112 |
|
112 | | -## MTEB评估 |
| 113 | +## MTEB 评估 |
113 | 114 | [MTEB](https://github.com/embeddings-benchmark/mteb) |
114 | 115 | 是一个大规模文本嵌入评测基准,包含了丰富的向量检索评估任务和数据集。 |
115 | | -本仓库主要面向其中的中英文检索任务(Retrieval),并以SciFact数据集作为主要示例。 |
| 116 | +本仓库主要面向其中的中英文检索任务(Retrieval),并以 SciFact 数据集作为主要示例。 |
116 | 117 |
|
117 | | -评估RepLLaMA向量检索模型([repllama-v1-7b-lora-passage](https://huggingface.co/castorini/repllama-v1-7b-lora-passage)): |
| 118 | +评估 NV-Embed 向量检索模型([NV-Embed-v1](https://huggingface.co/nvidia/NV-Embed-v1)): |
| 119 | +``` |
| 120 | +export CUDA_VISIBLE_DEVICES=0 |
| 121 | +python eval_mteb.py \ |
| 122 | + --base_model_name_or_path NV-Embed-v1 \ |
| 123 | + --output_folder en_results/nv-embed-v1 \ |
| 124 | + --query_instruction "Given a claim, find documents that refute the claim" \ |
| 125 | + --task_name 'SciFact' \ |
| 126 | + --eval_batch_size 8 |
| 127 | +``` |
| 128 | +结果文件保存在`en_results/nv-embed-v1/SciFact/last/no_model_name_available/no_revision_available/SciFact.json`,包含以下类似的评估结果: |
| 129 | +``` |
| 130 | +'ndcg_at_1': 0.67667, |
| 131 | +'ndcg_at_3': 0.73826, |
| 132 | +'ndcg_at_5': 0.76662, |
| 133 | +'ndcg_at_10': 0.783, |
| 134 | +'ndcg_at_20': 0.7936, |
| 135 | +'ndcg_at_100': 0.80206, |
| 136 | +'ndcg_at_1000': 0.80444 |
| 137 | +``` |
| 138 | + |
| 139 | +评估 RepLLaMA 向量检索模型([repllama-v1-7b-lora-passage](https://huggingface.co/castorini/repllama-v1-7b-lora-passage)): |
118 | 140 | ``` |
119 | 141 | export CUDA_VISIBLE_DEVICES=0 |
120 | 142 | python evaluation/mteb/eval_mteb.py \ |
@@ -143,7 +165,7 @@ python evaluation/mteb/eval_mteb.py \ |
143 | 165 | 'ndcg_at_1000': 0.7794 |
144 | 166 | ``` |
145 | 167 |
|
146 | | -评估BGE向量检索模型([bge-large-en-v1.5](https://huggingface.co/BAAI/bge-large-en-v1.5)): |
| 168 | +评估 BGE 向量检索模型([bge-large-en-v1.5](https://huggingface.co/BAAI/bge-large-en-v1.5)): |
147 | 169 | ``` |
148 | 170 | export CUDA_VISIBLE_DEVICES=0 |
149 | 171 | python evaluation/mteb/eval_mteb.py \ |
@@ -174,15 +196,15 @@ python evaluation/mteb/eval_mteb.py \ |
174 | 196 | 可支持配置的参数: |
175 | 197 | - `base_model_name_or_path`: 模型名称或路径 |
176 | 198 | - `output_folder`: 结果文件存储路径 |
177 | | -- `task_name`:任务(数据集)名称,如SciFact |
178 | | -- `task_split`:测试查询集合,如test或dev |
179 | | -- `query_instruction`:查询前添加的提示文本,如'query: '或None |
180 | | -- `document_instruction`:文档前添加的提示文本,如'passage: '或None |
181 | | -- `pooling_method`:获取表示的方式,last表示取最后token,mean表示取平均,cls表示取`[CLS]`token |
| 199 | +- `task_name`:任务(数据集)名称,如 SciFact |
| 200 | +- `task_split`:测试查询集合,如 test 或 dev |
| 201 | +- `query_instruction`:查询前添加的提示文本,如'query: '或 None |
| 202 | +- `document_instruction`:文档前添加的提示文本,如'passage: '或 None |
| 203 | +- `pooling_method`:获取表示的方式,last 表示取最后 token,mean 表示取平均,cls 表示取`[CLS]`token |
182 | 204 | - `max_seq_length`: 最大序列长度 |
183 | | -- `eval_batch_size`: 模型预测的批次大小(单个GPU) |
184 | | -- `pad_token`:设置padding的token,可取unk_token、eos_token或pad_token |
185 | | -- `padding_side`:设置padding的位置,可取left或right |
| 205 | +- `eval_batch_size`: 模型预测的批次大小(单个 GPU) |
| 206 | +- `pad_token`:设置 padding 的 token,可取 unk_token、eos_token 或 pad_token |
| 207 | +- `padding_side`:设置 padding 的位置,可取 left 或 right |
186 | 208 | - `add_bos_token`:是否添加起始符,0表示不添加,1表示添加 |
187 | 209 | - `add_eos_token`:是否添加结束符,0表示不添加,1表示添加 |
188 | 210 |
|
|
0 commit comments