Model reference · open weights
Dmeta-embedding-zh is an open-weight embedding model from DMetaSoul. 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 | DMetaSoul |
|---|---|
| Type | Embedding models |
| Task | Embeddings |
| Context | 1k tokens |
| Runs with | sentence-transformers |
| Released | 2024-01-25 |
| Popularity | 910 downloads / month |
| Licence | Open weights |
About
Update News
2024.04.01, The Dmeta-embedding small version is released. Just with 8 layers, inference is more efficient, about 30% improved.
2024.02.07, The Embedding API service based on the Dmeta-embedding model now open for internal beta testing. Click the link to apply, and you will receive 400M tokens for free, which can encode approximately GB-level Chinese text.
Dmeta-embedding is a cross-domain, cross-task, out-of-the-box Chinese embedding model. It is suitable for various scenarios such as search engine, Q&A, intelligent customer service, LLM+RAG, etc. It supports inference using tools like Transformers/Sentence-Transformers/Langchain.
Features:
The model supports inference through frameworks such as Sentence-Transformers, Langchain, Huggingface Transformers, etc. For specific usage, please refer to the following examples.
Load and inference Dmeta-embedding via sentence-transformers as following:
pip install -U sentence-transformers
from sentence_transformers import SentenceTransformer
texts1 = ["胡子长得太快怎么办?", "在香港哪里买手表好"]
texts2 = ["胡子长得快怎么办?", "怎样使胡子不浓密!", "香港买手表哪里好", "在杭州手机到哪里买"]
model = SentenceTransformer('DMetaSoul/Dmeta-embedding')
embs1 = model.encode(texts1, normalize_embeddings=True)
embs2 = model.encode(texts2, normalize_embeddings=True)
similarity = embs1 @ embs2.T
print(similarity)
for i in range(len(texts1)):
scores = []
for j in range(len(texts2)):
scores.append([texts2[j], similarity[i][j]])
scores = sorted(scores, key=lambda x:x[1], reverse=True)
print(f"查询文本:{texts1[i]}")
for text2, score in scores:
print(f"相似文本:{text2},打分:{score}")
print()
Output:
查询文本:胡子长得太快怎么办?
相似文本:胡子长得快怎么办?,打分:0.9535336494445801
相似文本:怎样使胡子不浓密!,打分:0.6776421070098877
相似文本:香港买手表哪里好,打分:0.2297907918691635
相似文本:在杭州手机到哪里买,打分:0.11386542022228241
查询文本:在香港哪里买手表好
相似文本:香港买手表哪里好,打分:0.9843372106552124
相似文本:在杭州手机到哪里买,打分:0.45211508870124817
相似文本:胡子长得快怎么办?,打分:0.19985519349575043
相似文本:怎样使胡子不浓密!,打分:0.18558596074581146
Load and inference Dmeta-embedding via langchain as following:
pip install -U langchain
import torch
import numpy as np
from langchain.embeddings import HuggingFaceEmbeddings
model_name = "DMetaSoul/Dmeta-embedding"
model_kwargs = {'device': 'cuda' if torch.cuda.is_available() else 'cpu'}
encode_kwargs = {'normalize_embeddings': True} # set True to compute cosine similarity
model = HuggingFaceEmbeddings(
model_name=model_name,
model_kwargs=model_kwargs,
encode_kwargs=encode_kwargs,
)
texts1 = ["胡子长得太快怎么办?", "在香港哪里买手表好"]
texts2 = ["胡子长得快怎么办?", "怎样使胡子不浓密!", "香港买手表哪里好", "在杭州手机到哪里买"]
embs1 = model.embed_documents(texts1)
embs2 = model.embed_documents(texts2)
embs1, embs2 = np.array(embs1), np.array(embs2)
similarity = embs1 @ embs2.T
print(similarity)
for i in range(len(texts1)):
scores = []
for j in range(len(texts2)):
scores.append([texts2[j], similarity[i][j]])
scores = sorted(scores, key=lambda x:x[1], reverse=True)
print(f"查询文本:{texts1[i]}")
for text2, score in scores:
print(f"相似文本:{text2},打分:{score}")
print()
Load and inference Dmeta-embedding via HuggingFace Transformers as following:
pip install -U transformers
import torch
from transformers import AutoTokenizer, AutoModel
def mean_pooling(model_output, attention_mask):
token_embeddings = model_output[0] #First element of model_output contains all token embeddings
input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
def cls_pooling(model_output):
return model_output[0][:, 0]
texts1 = ["胡子长得太快怎么办?", "在香港哪里买手表好"]
texts2 = ["胡子长得快怎么办?", "怎样使胡子不浓密!", "香港买手表哪里好", "在杭州手机到哪里买"]
tokenizer = AutoTokenizer.from_pretrained('DMetaSoul/Dmeta-embedding')
model = AutoModel.from_pretrained('DMetaSoul/Dmeta-embedding')
model.eval()
with torch.no_grad():
inputs1 = tokenizer(texts1, padding=True, truncation=True, return_tensors='pt')
inputs2 = tokenizer(texts2, padding=True, truncation=True, return_tensors='pt')
model_output1 = model(**inputs1)
model_output2 = model(**inputs2)
embs1From 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 | 65.608 |
| STS | MTEB AFQMC | cos_sim_spearman | 71.129 |
| STS | MTEB AFQMC | euclidean_pearson | 70.181 |
| STS | MTEB AFQMC | euclidean_spearman | 71.129 |
| STS | MTEB AFQMC | manhattan_pearson | 70.145 |
| STS | MTEB AFQMC | manhattan_spearman | 71.052 |
| STS | MTEB ATEC | cos_sim_pearson | 65.524 |
| STS | MTEB ATEC | cos_sim_spearman | 64.642 |
| STS | MTEB ATEC | euclidean_pearson | 73.202 |
| STS | MTEB ATEC | euclidean_spearman | 64.642 |
| STS | MTEB ATEC | manhattan_pearson | 73.228 |
| STS | MTEB ATEC | manhattan_spearman | 64.626 |
| Classification | MTEB AmazonReviewsClassification (zh) | accuracy | 44.926 |
| Classification | MTEB AmazonReviewsClassification (zh) | f1 | 42.826 |
| STS | MTEB BQ | cos_sim_pearson | 71.352 |
| STS | MTEB BQ | cos_sim_spearman | 72.296 |
| STS | MTEB BQ | euclidean_pearson | 70.946 |
| STS | MTEB BQ | euclidean_spearman | 72.296 |
| STS | MTEB BQ | manhattan_pearson | 70.845 |
| STS | MTEB BQ | manhattan_spearman | 72.245 |
| Clustering | MTEB CLSClusteringP2P | v_measure | 40.242 |
| Clustering | MTEB CLSClusteringS2S | v_measure | 39.168 |
| Reranking | MTEB CMedQAv1 | map | 88.488 |
| Reranking | MTEB CMedQAv1 | mrr | 90.369 |
Using it via the API
Once AxForge deploys dmeta-embedding-zh for you, it answers on the OpenAI-compatible API — the same base URL and keys as every other model. (dmeta-embedding-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":"dmeta-embedding-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.