Model reference · open weights
piccolo-zh is an open-weight embedding model from sensenova. AxForge deploys and operates it for you on dedicated EU-owned hardware — with the licence handled where one is required.
Available as managed deployment — configured and operated for you on dedicated EU hardware, quoted per deployment.
What it is
| Released by | sensenova |
|---|---|
| Type | Embedding models |
| Task | Embeddings |
| Context | 512 tokens |
| Runs with | transformers |
| Released | 2023-09-04 |
| Popularity | 505 downloads / month |
| Licence | Unknown |
About
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.
我们将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 |
在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
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 通常会将 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.
一些有用的trick:
some useful tricks:
这里我们列出了我们参考过的embedding项目和论文
Here we list the embedding projects and papers we have referenced
From the published model card. Full card on the HuggingFace links in the sidebar.
Benchmarks
As published on the model card — the maker's own numbers, not measured by AxForge.
| Task | Dataset | Metric | Score |
|---|---|---|---|
| STS | MTEB AFQMC | cos_sim_pearson | 49.166 |
| STS | MTEB AFQMC | cos_sim_spearman | 51.405 |
| STS | MTEB AFQMC | euclidean_pearson | 49.859 |
| STS | MTEB AFQMC | euclidean_spearman | 51.501 |
| STS | MTEB AFQMC | manhattan_pearson | 49.746 |
| STS | MTEB AFQMC | manhattan_spearman | 51.411 |
| STS | MTEB ATEC | cos_sim_pearson | 52.385 |
| STS | MTEB ATEC | cos_sim_spearman | 52.591 |
| STS | MTEB ATEC | euclidean_pearson | 54.995 |
| STS | MTEB ATEC | euclidean_spearman | 52.541 |
| STS | MTEB ATEC | manhattan_pearson | 54.950 |
| STS | MTEB ATEC | manhattan_spearman | 52.515 |
| Classification | MTEB AmazonReviewsClassification (zh) | accuracy | 40.236 |
| Classification | MTEB AmazonReviewsClassification (zh) | f1 | 39.430 |
| STS | MTEB BQ | cos_sim_pearson | 60.990 |
| STS | MTEB BQ | cos_sim_spearman | 62.682 |
| STS | MTEB BQ | euclidean_pearson | 61.089 |
| STS | MTEB BQ | euclidean_spearman | 62.417 |
| STS | MTEB BQ | manhattan_pearson | 61.147 |
| STS | MTEB BQ | manhattan_spearman | 62.489 |
| Clustering | MTEB CLSClusteringP2P | v_measure | 38.364 |
| Clustering | MTEB CLSClusteringS2S | v_measure | 35.646 |
| Reranking | MTEB CMedQAv1 | map | 85.251 |
| Reranking | MTEB CMedQAv1 | mrr | 87.772 |
Using it via the API
Once AxForge deploys piccolo-zh for you, it answers on the OpenAI-compatible API — the same base URL and keys as every other model. (piccolo-zh below is illustrative; you get the exact model name on deployment.)
$ curl -sS https://api.axforge.ai/v1/embeddings \
-H "Authorization: Bearer $AXFORGE_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"piccolo-zh","input":"text to embed"}'
Create an account — your API key is available in the console. 3M free tokens every 30 days with every new account.