Model reference · open weights
gte-multilingual is an open-weight embedding model from Alibaba. gte-multilingual-base (FP16) weighs 611 MB; the smallest configuration that runs it is RTX 3060 12 GB.
What it is
| Released by | Alibaba |
|---|---|
| Released | 2024-07-20 |
| Parameters | 305M |
| VRAM | 611 MB for the weights |
What it runs on
| Card | Runs | Memory |
|---|---|---|
| RTX 3060 12 GB | fits | 11.6 GB |
| RTX 4060 Ti 16 GB | fits | 15.4 GB |
| RTX 3090 24 GB | fits | 23.4 GB |
| RTX 4090 24 GB | fits | 23.4 GB |
| RTX 5090 32 GB | fits | 31.0 GB |
| L40S 48 GB | fits | 44.0 GB |
| A100 80 GB | fits | 78.2 GB |
| H100 80 GB | fits | 78.1 GB |
| RTX PRO 6000 Blackwell 96 GB | fits | 93.8 GB |
| DGX Spark (GB10) 128 GB unified | fits | 107 GB |
| H200 141 GB | fits | 138 GB |
| B200 180 GB | fits | 176 GB |
From the model card
The gte-multilingual-base model is the latest in the GTE (General Text Embedding) family of models, featuring several key attributes:
# Requires transformers>=4.36.0
import torch.nn.functional as F
from transformers import AutoModel, AutoTokenizer
input_texts = [
"what is the capital of China?",
"how to implement quick sort in python?",
"北京",
"快排算法介绍"
]
model_name_or_path = 'Alibaba-NLP/gte-multilingual-base'
tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
model = AutoModel.from_pretrained(model_name_or_path, trust_remote_code=True)
# Tokenize the input texts
batch_dict = tokenizer(input_texts, max_length=8192, padding=True, truncation=True, return_tensors='pt')
outputs = model(**batch_dict)
dimension=768 # The output dimension of the output embedding, should be in [128, 768]
embeddings = outputs.last_hidden_state[:, 0][:dimension]
embeddings = F.normalize(embeddings, p=2, dim=1)
scores = (embeddings[:1] @ embeddings[1:].T) * 100
print(scores.tolist())
# [[0.3016996383666992, 0.7503870129585266, 0.3203084468841553]]
# Requires sentence-transformers>=3.0.0
from sentence_transformers import SentenceTransformer
input_texts = [
"what is the capital of China?",
"how to implement quick sort in python?",
"北京",
"快排算法介绍"
]
model_name_or_path="Alibaba-NLP/gte-multilingual-base"
model = SentenceTransformer(model_name_or_path, trust_remote_code=True)
embeddings = model.encode(input_texts, normalize_embeddings=True) # embeddings.shape (4, 768)
# sim scores
scores = model.similarity(embeddings[:1], embeddings[1:])
print(scores.tolist())
# [[0.301699697971344, 0.7503870129585266, 0.32030850648880005]]
Usage via docker and infinity, MIT Licensed.
docker run --gpus all -v $PWD/data:/app/.cache -p "7997":"7997" \
michaelf34/infinity:0.0.69 \
v2 --model-id Alibaba-NLP/gte-multilingual-base --revision "main" --dtype float16 --batch-size 32 --device cuda --engine torch --port 7997
Usage via Docker and Text Embeddings Inference (TEI):
docker run --platform linux/amd64 \
-p 8080:80 \
-v $PWD/data:/data \
--pull always \
ghcr.io/huggingface/text-embeddings-inference:cpu-1.7 \
--model-id Alibaba-NLP/gte-multilingual-base \
--dtype float16
docker run --gpus all \
-p 8080:80 \
-v $PWD/data:/data \
--pull always \
ghcr.io/huggingface/text-embeddings-inference:1.7 \
--model-id Alibaba-NLP/gte-multilingual-base \
--dtype float16
Then you can send requests to the deployed API via the OpenAI-compatible v1/embeddings route (more information about the OpenAI Embeddings API):
curl https://0.0.0.0:8080/v1/embeddings \
-H "Content-Type: application/json" \
-d '{
"input": [
"what is the capital of China?",
"how to implement quick sort in python?",
"北京",
"快排算法介绍"
],
"model": "Alibaba-NLP/gte-multilingual-base",
"encoding_format": "float"
}'
# You can find the script gte_embedding.py in https://huggingface.co/Alibaba-NLP/gte-multilingual-base/blob/main/scripts/gte_embedding.py
from gte_embedding import GTEEmbeddidng
model_name_or_path = 'Alibaba-NLP/gte-multilingual-base'
model = GTEEmbeddidng(model_name_or_path)
query = "中国的首都在哪儿"
docs = [
"what is the capital of China?",
"how to implement quick sort in python?",
"北京",
"快排算法介绍"
]
embs = model.encode(docs, return_dense=True,return_sparse=True)
print('dense_embeddings vecs', embs['dense_embeddings'])
print('token_weights', embs['token_weights'])
pairs = [(query, doc) for doc in docs]
dense_scores = model.compute_scores(pairs, dense_weight=1.0, sparse_weight=0.0)
sparse_scores = model.compute_scores(pairs, denseQuoted from the model card on Hugging Face. The full card is behind the Hugging Face link above.
Benchmarks
As published on the model card: the maker's own numbers, not measured by AxForge.
| Task | Dataset | Metric | Score |
|---|---|---|---|
| Clustering | MTEB 8TagsClustering | v_measure | 33.667 |
| STS | MTEB AFQMC | cos_sim_spearman | 43.548 |
| STS | MTEB ATEC | cos_sim_spearman | 48.912 |
| Classification | MTEB AllegroReviews | accuracy | 41.690 |
| Clustering | MTEB AlloProfClusteringP2P | v_measure | 54.202 |
| Clustering | MTEB AlloProfClusteringS2S | v_measure | 44.341 |
| Reranking | MTEB AlloprofReranking | map | 64.915 |
| Retrieval | MTEB AlloprofRetrieval | ndcg_at_10 | 53.638 |
| Classification | MTEB AmazonCounterfactualClassification (en) | accuracy | 75.955 |
| Classification | MTEB AmazonPolarityClassification | accuracy | 80.718 |
| Classification | MTEB AmazonReviewsClassification (en) | accuracy | 43.642 |
| Classification | MTEB AmazonReviewsClassification (de) | accuracy | 40.108 |
| Classification | MTEB AmazonReviewsClassification (es) | accuracy | 40.170 |
| Classification | MTEB AmazonReviewsClassification (fr) | accuracy | 39.568 |
| Classification | MTEB AmazonReviewsClassification (ja) | accuracy | 35.750 |
| Classification | MTEB AmazonReviewsClassification (zh) | accuracy | 33.342 |
| Retrieval | MTEB ArguAna | ndcg_at_10 | 58.231 |
| Retrieval | MTEB ArguAna-PL | ndcg_at_10 | 53.166 |
| Clustering | MTEB ArxivClusteringP2P | v_measure | 46.019 |
| Clustering | MTEB ArxivClusteringS2S | v_measure | 41.066 |
| Reranking | MTEB AskUbuntuDupQuestions | map | 61.875 |
| STS | MTEB BIOSSES | cos_sim_spearman | 81.215 |
| STS | MTEB BQ | cos_sim_spearman | 51.716 |
| Retrieval | MTEB BSARDRetrieval | ndcg_at_10 | 26.115 |