Model reference · open weights
dunzhang-stella_en is an open-weight embedding model from Marqo. 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
| Maker | Marqo |
|---|---|
| Type | Embedding models |
| Task | Embeddings |
| Parameters (lead) | 435M |
| Context | 8k tokens |
| Runs with | sentence-transformers |
| Released | 2024-09-25 |
| Popularity | 71 downloads / month |
| Licence | Open weights |
About
This model is similar to the original Dunzhang stella 400m model, with a fused matryoshka layer. The hierarchical structuring from a Matryoshka Layer reduces the computational overhead for generating embeddings, while leaving relevance metrics unchanged.
import os
import torch
from transformers import AutoModel, AutoTokenizer, AutoConfig
from sklearn.preprocessing import normalize
query_prompt = "Instruct: Given a web search query, retrieve relevant passages that answer the query.\nQuery: "
queries = [
"What are some ways to reduce stress?",
"What are the benefits of drinking green tea?",
]
queries = [query_prompt + query for query in queries]
# docs do not need any prompts
docs = [
"There are many effective ways to reduce stress. Some common techniques include deep breathing, meditation, and physical activity. Engaging in hobbies, spending time in nature, and connecting with loved ones can also help alleviate stress. Additionally, setting boundaries, practicing self-care, and learning to say no can prevent stress from building up.",
"Green tea has been consumed for centuries and is known for its potential health benefits. It contains antioxidants that may help protect the body against damage caused by free radicals. Regular consumption of green tea has been associated with improved heart health, enhanced cognitive function, and a reduced risk of certain types of cancer. The polyphenols in green tea may also have anti-inflammatory and weight loss properties.",
]
# The path of your model after cloning it
model_dir = "Marqo/dunzhang-stella_en_400M_v5"
model = AutoModel.from_pretrained(model_dir, trust_remote_code=True).cuda().eval()
tokenizer = AutoTokenizer.from_pretrained(model_dir, trust_remote_code=True)
with torch.no_grad():
input_data = tokenizer(queries, padding="longest", truncation=True, max_length=512, return_tensors="pt")
input_data = {k: v.cuda() for k, v in input_data.items()}
attention_mask = input_data["attention_mask"]
last_hidden_state = model(**input_data)[0]
last_hidden = last_hidden_state.masked_fill(~attention_mask[..., None].bool(), 0.0)
query_vectors = last_hidden.sum(dim=1) / attention_mask.sum(dim=1)[..., None]
query_vectors = normalize(query_vectors.cpu().numpy())
# Embed the documents
with torch.no_grad():
input_data = tokenizer(docs, padding="longest", truncation=True, max_length=512, return_tensors="pt")
input_data = {k: v.cuda() for k, v in input_data.items()}
attention_mask = input_data["attention_mask"]
last_hidden_state = model(**input_data)[0]
last_hidden = last_hidden_state.masked_fill(~attention_mask[..., None].bool(), 0.0)
docs_vectors = last_hidden.sum(dim=1) / attention_mask.sum(dim=1)[..., None]
docs_vectors = normalize(docs_vectors.cpu().numpy())
print(query_vectors.shape, docs_vectors.shape)
# (2, 1024) (2, 1024)
similarities = query_vectors @ docs_vectors.T
print(similarities)
# [[0.8397531 0.29900077]
# [0.32818374 0.80954516]]
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 |
|---|---|---|---|
| Classification | MTEB AmazonCounterfactualClassification (en) | accuracy | 92.358 |
| Classification | MTEB AmazonCounterfactualClassification (en) | ap | 70.813 |
| Classification | MTEB AmazonCounterfactualClassification (en) | ap_weighted | 70.813 |
| Classification | MTEB AmazonCounterfactualClassification (en) | f1 | 88.951 |
| Classification | MTEB AmazonCounterfactualClassification (en) | f1_weighted | 92.686 |
| Classification | MTEB AmazonCounterfactualClassification (en) | main_score | 92.358 |
| Classification | MTEB AmazonPolarityClassification | accuracy | 97.195 |
| Classification | MTEB AmazonPolarityClassification | ap | 96.082 |
| Classification | MTEB AmazonPolarityClassification | ap_weighted | 96.082 |
| Classification | MTEB AmazonPolarityClassification | f1 | 97.194 |
| Classification | MTEB AmazonPolarityClassification | f1_weighted | 97.194 |
| Classification | MTEB AmazonPolarityClassification | main_score | 97.195 |
| Classification | MTEB AmazonReviewsClassification (en) | accuracy | 59.528 |
| Classification | MTEB AmazonReviewsClassification (en) | f1 | 59.210 |
| Classification | MTEB AmazonReviewsClassification (en) | f1_weighted | 59.210 |
| Classification | MTEB AmazonReviewsClassification (en) | main_score | 59.528 |
| Retrieval | MTEB ArguAna | main_score | 64.240 |
| Retrieval | MTEB ArguAna | map_at_1 | 40.398 |
| Retrieval | MTEB ArguAna | map_at_10 | 56.215 |
| Retrieval | MTEB ArguAna | map_at_100 | 56.834 |
| Retrieval | MTEB ArguAna | map_at_1000 | 56.835 |
| Retrieval | MTEB ArguAna | map_at_20 | 56.747 |
| Retrieval | MTEB ArguAna | map_at_3 | 52.181 |
| Retrieval | MTEB ArguAna | map_at_5 | 54.628 |
Using it via the API
Once AxForge deploys dunzhang-stella-en for you, it answers on the OpenAI-compatible API — the same base URL and keys as every other model. (dunzhang-stella-en 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":"dunzhang-stella-en","input":"text to embed"}'
Create an account — your API key is available in the console. 5M tokens/month currently included with every new account at launch.