piccolo-large-zh
piccolo是一个通用embedding模型(中文), 由来自商汤科技的通用模型组完成训练。piccolo借鉴了E5以及GTE的训练流程,采用了两阶段的训练方式。 在第一阶段中,我们搜集和爬取了4亿的中文文本对(可视为弱监督文本对数据),并采用二元组的softmax对比学习损失来优化模型。 在第二阶段中,我们搜集整理了2000万人工标注的中文文本对(精标数据),并采用带有难负样本的三元组的softmax对比学习损失来帮助模型更好地优化。 目前,我们提供了piccolo-base-zh和piccolo-large-zh两个模型。
piccolo is a general text embedding model(chinese), powered by General Model Group from SenseTime Research. Inspired from E5 and GTE, piccolo is trained using a two stage pipeline. On the first stage, we collect and crawl 400 million weakly supervised Chinese text pairs from the Internet, and train the model with the pair(text and text pos) softmax contrastive loss. On the second stage, we collect 20 million human labeled chinese text pairs dataset, and finetune the model with tiplet (text, text_pos, text_neg) contrastive loss. Currently here we offer two different sizes of models, including piccolo-base-zh, piccolo-large-zh.
Metric
我们将piccolo与其他的开源embedding模型在CMTEB榜单上进行了比较,请参考CMTEB榜单。我们在eval文件夹中提供了复现结果的脚本。
We compared the performance of the piccolo with other embedding models on the C-MTEB benchmark. please refer to the C-MTEB leaderboard. we provide scripts in "eval" folder for results reproducing.
Model Name | Model Size (GB) | Dimension | Sequence Length | Average (35) | Classification (9) | Clustering (4) | Pair Classification (2) | Reranking (4) | Retrieval (8) | STS (8) |
---|---|---|---|---|---|---|---|---|---|---|
[piccolo-large-zh] | 0.65 | 1024 | 512 | 64.11 | 67.03 | 47.04 | 78.38 | 65.98 | 70.93 | 58.02 |
[bge-large-zh] | 1.3 | 1024 | 512 | 63.96 | 68.32 | 48.39 | 78.94 | 65.11 | 71.52 | 54.98 |
[piccolo-base-zh] | 0.2 | 768 | 512 | 63.66 | 66.98 | 47.12 | 76.61 | 66.68 | 71.2 | 55.9 |
[bge-large-zh-no-instruct] | 1.3 | 1024 | 512 | 63.4 | 68.58 | 50.01 | 76.77 | 64.9 | 70.54 | 53 |
[bge-base-zh] | 0.41 | 768 | 512 | 62.8 | 67.07 | 47.64 | 77.5 | 64.91 | 69.53 | 54.12 |
Usage
在sentence-transformer package中可以很容易地调用piccolo模型
# for s2s dataset, you can use piccolo as below
# 对于短对短数据集,下面是通用的使用方式
from sentence_transformers import SentenceTransformer
sentences = ["数据1", "数据2"]
model = SentenceTransformer('sensenova/piccolo-base-zh')
embeddings_1 = model.encode(sentences, normalize_embeddings=True)
embeddings_2 = model.encode(sentences, normalize_embeddings=True)
similarity = embeddings_1 @ embeddings_2.T
print(similarity)
# for s2p dataset, we recommend to add instruction for passage retrieval
# 对于短对长数据集,我们推荐添加instruction,来帮助模型更好地进行检索。
from sentence_transformers import SentenceTransformer
queries = ['query_1', 'query_2']
passages = ["doc_1", "doc_2"]
model = SentenceTransformer('sensenova/piccolo-base-zh')
q_embeddings = model.encode(["查询:" + q for q in queries], normalize_embeddings=True)
p_embeddings = model.encode(["结果:" + p for p in passages], normalize_embeddings=True)
scores = q_embeddings @ p_embeddings.T
Training Detail
pretrain
pretrain 通常不需要太大的max length, 推荐128。小的max length用以提高batch size,加快训练速度,从而适应大规模数据。 pretrain 损失我们采用二元组contrastive loss,不加入hard negative, 直接采用inbatch negative,在实际训练中,我们使用了32张40G A100进行训练,单卡的batch size为1024。
Pretrain usually does not require a large max length, and 128 is recommended. A small max length is used to increase batch size and speed up training to adapt to large-scale data. We use binary contrastive loss for pretrain loss, without adding hard negative, and directly use inbatch negative. In actual training, we used 32 40G A100 for training, and the batch size of a single card is 1024.
finetune
finetune 通常会将 max length扩增到512。用以适应更大长度的文本输入,finetune时会多sample S2P的数据,以增强模型在retrieval任务上的性能。 finetune 损失采用三元组contrastive loss,加入hard negative,neg num通常设置为2-7,loss计算方式可以参考GTE里的improved contrastive loss。 注意: 我们给query和passage设置了不同的max length,query的max length始终保持在64。
For finetuning, we usually expands the max length to 512. To adapt to larger length text input, finetune will sample more S2P data to enhance the performance of the model on retrieval tasks. The finetune loss uses triple contrastive loss, adding hard negative. Neg num is usually set to 2-7. The loss calculation method can refer to the improved contrastive loss in GTE. Note: We set different max lengths for query and passage, and the max length of query is always kept at 64.
Others
一些有用的trick:
- 减小显存的方式: fp16 + gradient checkpointing + ZERO STAGE1 (stage2 不支持双塔结构下的gradient checkpointing) 相关issue见: https://github.com/microsoft/DeepSpeed/issues/988
- dataset sampler,我们采用了M3E的dataset sampler,用以保证每个batch里的样本均来自于一个dataset,负样本更有价值。
- instruction。instruction在我们的实验中对retrieval任务有非常大的性能提升,我们在每个训练样本前都加入'查询: '和'结果: '这样的instruction。
some useful tricks:
- The way to reduce memory usage: fp16 + gradient checkpointing + ZERO STAGE1 (stage2 does not support gradient checkpointing under the double-tower structure) For related issues, see: https://github.com/microsoft/DeepSpeed/issues/ 988
- Dataset sampler, we use M3E's dataset sampler to ensure that the samples in each batch come from a dataset, and negative samples are more valuable.
- instruction. Instruction has greatly improved the performance of the retrieval task in our experiments. We added instructions like 'query: ' and 'result: ' before each training sample.
Reference
这里我们列出了我们参考过的embedding项目和论文
- M3E。非常棒的中文开源embedding项目,收集和整理了较多的中文高质量数据集,uniem也是一个不错的框架。
- Text2vec。另一个一个非常棒的中文开源embedding项目。
- FlagEmbedding。智源AI开源的embedding模型,收集和整理了CMTEB benchmark,填补了中文embedding系统性评测的空缺。
- E5。来自微软的一篇文章,有非常详细的消融实验以及数据处理过滤细节。
- GTE。一篇来自阿里达摩的embedding论文。
Here we list the embedding projects and papers we have referenced
- M3E. A great Chinese open source embedding project that collects and organizes a large number of high-quality Chinese datasets. Uniem is also a good framework.
- Text2vec. Another great Chinese open source embedding project.
- Flag Embedding. Zhiyuan AI’s open source embedding model.They collect and organize CMTEB benchmark, filling the gap in systematic evaluation of Chinese embeddings.
- E5. Powerd by microsoft,producing very detailed ablation experiments and data processing filtering details.
- GTE. An embedding paper from Alibaba Damo.
License
Piccolo 使用 MIT License,免费商用。 Piccolo use MIT License. It can be used for commercial purposes free of charge.
Acknowledgement
piccolo 由来自商汤科技研究院的通用模型组完成训练,Jinkin 完成了代码实现和模型训练, Jinkin, CCCCxxx 一起完成了数据搜集、整理和评测工作. 项目由 Gaomengya 和 chaorenwu111 主导。 同时,感谢lux0933以及yangkai001的交流与讨论,提供了非常多有用的建议。
piccolo is powered by Genral Model group from SenseTime Research. Jinkin complete code implementation and model training. Jinkin, CCCCxxx completed the data collection、processing and model evaluation together. Project is led by Gaomengya and chaorenwu111. At the same time, thank lux0933 and yangkai001 for the discussion, which provide a lot of useful suggestions.
- Downloads last month
- 1,637
Evaluation results
- cos_sim_pearson on MTEB AFQMCvalidation set self-reported51.405
- cos_sim_spearman on MTEB AFQMCvalidation set self-reported54.168
- euclidean_pearson on MTEB AFQMCvalidation set self-reported52.405
- euclidean_spearman on MTEB AFQMCvalidation set self-reported54.262
- manhattan_pearson on MTEB AFQMCvalidation set self-reported52.354
- manhattan_spearman on MTEB AFQMCvalidation set self-reported54.206
- cos_sim_pearson on MTEB ATECtest set self-reported53.480
- cos_sim_spearman on MTEB ATECtest set self-reported54.279
- euclidean_pearson on MTEB ATECtest set self-reported56.858
- euclidean_spearman on MTEB ATECtest set self-reported54.389
- manhattan_pearson on MTEB ATECtest set self-reported56.813
- manhattan_spearman on MTEB ATECtest set self-reported54.360
- accuracy on MTEB AmazonReviewsClassification (zh)test set self-reported40.332
- f1 on MTEB AmazonReviewsClassification (zh)test set self-reported39.569
- cos_sim_pearson on MTEB BQtest set self-reported60.814
- cos_sim_spearman on MTEB BQtest set self-reported62.315
- euclidean_pearson on MTEB BQtest set self-reported61.217
- euclidean_spearman on MTEB BQtest set self-reported62.353
- manhattan_pearson on MTEB BQtest set self-reported61.156
- manhattan_spearman on MTEB BQtest set self-reported62.288
- v_measure on MTEB CLSClusteringP2Ptest set self-reported38.984
- v_measure on MTEB CLSClusteringS2Stest set self-reported36.043
- map on MTEB CMedQAv1test set self-reported84.792
- mrr on MTEB CMedQAv1test set self-reported87.172
- map on MTEB CMedQAv2test set self-reported84.891
- mrr on MTEB CMedQAv2test set self-reported87.460
- map_at_1 on MTEB CmedqaRetrievalself-reported23.351
- map_at_10 on MTEB CmedqaRetrievalself-reported35.284
- map_at_100 on MTEB CmedqaRetrievalself-reported37.222
- map_at_1000 on MTEB CmedqaRetrievalself-reported37.338
- map_at_3 on MTEB CmedqaRetrievalself-reported31.135
- map_at_5 on MTEB CmedqaRetrievalself-reported33.445
- mrr_at_1 on MTEB CmedqaRetrievalself-reported36.134
- mrr_at_10 on MTEB CmedqaRetrievalself-reported44.282
- mrr_at_100 on MTEB CmedqaRetrievalself-reported45.310
- mrr_at_1000 on MTEB CmedqaRetrievalself-reported45.356
- mrr_at_3 on MTEB CmedqaRetrievalself-reported41.615
- mrr_at_5 on MTEB CmedqaRetrievalself-reported43.169
- ndcg_at_1 on MTEB CmedqaRetrievalself-reported36.134
- ndcg_at_10 on MTEB CmedqaRetrievalself-reported41.982
- ndcg_at_100 on MTEB CmedqaRetrievalself-reported49.672
- ndcg_at_1000 on MTEB CmedqaRetrievalself-reported51.669
- ndcg_at_3 on MTEB CmedqaRetrievalself-reported36.521
- ndcg_at_5 on MTEB CmedqaRetrievalself-reported38.858
- precision_at_1 on MTEB CmedqaRetrievalself-reported36.134
- precision_at_10 on MTEB CmedqaRetrievalself-reported9.515
- precision_at_100 on MTEB CmedqaRetrievalself-reported1.578
- precision_at_1000 on MTEB CmedqaRetrievalself-reported0.183
- precision_at_3 on MTEB CmedqaRetrievalself-reported20.747
- precision_at_5 on MTEB CmedqaRetrievalself-reported15.229
- recall_at_1 on MTEB CmedqaRetrievalself-reported23.351
- recall_at_10 on MTEB CmedqaRetrievalself-reported52.798
- recall_at_100 on MTEB CmedqaRetrievalself-reported84.806
- recall_at_1000 on MTEB CmedqaRetrievalself-reported98.172
- recall_at_3 on MTEB CmedqaRetrievalself-reported36.513
- recall_at_5 on MTEB CmedqaRetrievalself-reported43.701
- cos_sim_accuracy on MTEB Cmnlivalidation set self-reported74.744
- cos_sim_ap on MTEB Cmnlivalidation set self-reported83.833
- cos_sim_f1 on MTEB Cmnlivalidation set self-reported76.646
- cos_sim_precision on MTEB Cmnlivalidation set self-reported70.786
- cos_sim_recall on MTEB Cmnlivalidation set self-reported83.563
- dot_accuracy on MTEB Cmnlivalidation set self-reported73.915
- dot_ap on MTEB Cmnlivalidation set self-reported82.877
- dot_f1 on MTEB Cmnlivalidation set self-reported75.935
- dot_precision on MTEB Cmnlivalidation set self-reported70.953
- dot_recall on MTEB Cmnlivalidation set self-reported81.669
- euclidean_accuracy on MTEB Cmnlivalidation set self-reported74.949
- euclidean_ap on MTEB Cmnlivalidation set self-reported84.006
- euclidean_f1 on MTEB Cmnlivalidation set self-reported76.787
- euclidean_precision on MTEB Cmnlivalidation set self-reported69.996
- euclidean_recall on MTEB Cmnlivalidation set self-reported85.036
- manhattan_accuracy on MTEB Cmnlivalidation set self-reported74.925
- manhattan_ap on MTEB Cmnlivalidation set self-reported83.975
- manhattan_f1 on MTEB Cmnlivalidation set self-reported76.571
- manhattan_precision on MTEB Cmnlivalidation set self-reported71.999
- manhattan_recall on MTEB Cmnlivalidation set self-reported81.763
- max_accuracy on MTEB Cmnlivalidation set self-reported74.949
- max_ap on MTEB Cmnlivalidation set self-reported84.006
- max_f1 on MTEB Cmnlivalidation set self-reported76.787