thenlper/gte-large-zh

Model

121

stars

8

commits

1

linked in READMEs

Feb 5, 2024

updated

bert
endpoints_compatible
model-index
mteb
pytorch
safetensors
sentence-similarity
sentence-transformers
Sentence Transformers
text-embeddings-inference
Browse cluster: Sentence Embeddings and Dense Retrieval

README

gte-large-zh

General Text Embeddings (GTE) model. Towards General Text Embeddings with Multi-stage Contrastive Learning

The GTE models are trained by Alibaba DAMO Academy. They are mainly based on the BERT framework and currently offer different sizes of models for both Chinese and English Languages. The GTE models are trained on a large-scale corpus of relevance text pairs, covering a wide range of domains and scenarios. This enables the GTE models to be applied to various downstream tasks of text embeddings, including information retrieval, semantic textual similarity, text reranking, etc.

Model List

ModelsLanguageMax Sequence LengthDimensionModel Size
GTE-large-zhChinese51210240.67GB
GTE-base-zhChinese5125120.21GB
GTE-small-zhChinese5125120.10GB
GTE-largeEnglish51210240.67GB
GTE-baseEnglish5125120.21GB
GTE-smallEnglish5123840.10GB

Metrics

We compared the performance of the GTE models with other popular text embedding models on the MTEB (CMTEB for Chinese language) benchmark. For more detailed comparison results, please refer to the MTEB leaderboard.

  • Evaluation results on CMTEB
ModelModel Size (GB)Embedding DimensionsSequence LengthAverage (35 datasets)Classification (9 datasets)Clustering (4 datasets)Pair Classification (2 datasets)Reranking (4 datasets)Retrieval (8 datasets)STS (8 datasets)
gte-large-zh0.65102451266.7271.3453.0781.1467.4272.4957.82
gte-base-zh0.2076851265.9271.2653.8680.4467.0071.7155.96
stella-large-zh-v20.651024102465.1369.0549.1682.6866.4170.1458.66
stella-large-zh0.651024102464.5467.6248.6578.7265.9871.0258.3
bge-large-zh-v1.51.3102451264.5369.1348.9981.665.8470.4656.25
stella-base-zh-v20.21768102464.3668.2949.479.9666.170.0856.92
stella-base-zh0.21768102464.1667.7748.776.0966.9571.0756.54
piccolo-large-zh0.65102451264.1167.0347.0478.3865.9870.9358.02
piccolo-base-zh0.276851263.6666.9847.1276.6166.6871.255.9
gte-small-zh0.151251260.0464.3548.9569.9966.2165.5049.72
bge-small-zh-v1.50.151251257.8263.9644.1870.460.9261.7749.1
m3e-base0.4176851257.7967.5247.6863.9959.5456.9150.47
text-embedding-ada-002(openai)-1536819253.0264.3145.6869.5654.2852.043.35

Usage

Code example

import torch.nn.functional as F
from torch import Tensor
from transformers import AutoTokenizer, AutoModel

input_texts = [
    "中国的首都是哪里",
    "你喜欢去哪里旅游",
    "北京",
    "今天中午吃什么"
]

tokenizer = AutoTokenizer.from_pretrained("thenlper/gte-large-zh")
model = AutoModel.from_pretrained("thenlper/gte-large-zh")

# Tokenize the input texts
batch_dict = tokenizer(input_texts, max_length=512, padding=True, truncation=True, return_tensors='pt')

outputs = model(**batch_dict)
embeddings = outputs.last_hidden_state[:, 0]
 
# (Optionally) normalize embeddings
embeddings = F.normalize(embeddings, p=2, dim=1)
scores = (embeddings[:1] @ embeddings[1:].T) * 100
print(scores.tolist())

Use with sentence-transformers:

from sentence_transformers import SentenceTransformer
from sentence_transformers.util import cos_sim

sentences = ['That is a happy person', 'That is a very happy person']

model = SentenceTransformer('thenlper/gte-large-zh')
embeddings = model.encode(sentences)
print(cos_sim(embeddings[0], embeddings[1]))

Limitation

This model exclusively caters to Chinese texts, and any lengthy texts will be truncated to a maximum of 512 tokens.

Citation

If you find our paper or models helpful, please consider citing them as follows:

@article{li2023towards,
  title={Towards general text embeddings with multi-stage contrastive learning},
  author={Li, Zehan and Zhang, Xin and Zhang, Yanzhao and Long, Dingkun and Xie, Pengjun and Zhang, Meishan},
  journal={arXiv preprint arXiv:2308.03281},
  year={2023}
}

Contributors

thenlper

7 commits

SFconvertbot

1 commits

thenlper/gte-large-zh

Model

121

stars

8

commits

1

linked in READMEs

Feb 5, 2024

updated

bert
endpoints_compatible
model-index
mteb
pytorch
safetensors
sentence-similarity
sentence-transformers
Sentence Transformers
text-embeddings-inference
Browse cluster: Sentence Embeddings and Dense Retrieval

README

gte-large-zh

General Text Embeddings (GTE) model. Towards General Text Embeddings with Multi-stage Contrastive Learning

The GTE models are trained by Alibaba DAMO Academy. They are mainly based on the BERT framework and currently offer different sizes of models for both Chinese and English Languages. The GTE models are trained on a large-scale corpus of relevance text pairs, covering a wide range of domains and scenarios. This enables the GTE models to be applied to various downstream tasks of text embeddings, including information retrieval, semantic textual similarity, text reranking, etc.

Model List

ModelsLanguageMax Sequence LengthDimensionModel Size
GTE-large-zhChinese51210240.67GB
GTE-base-zhChinese5125120.21GB
GTE-small-zhChinese5125120.10GB
GTE-largeEnglish51210240.67GB
GTE-baseEnglish5125120.21GB
GTE-smallEnglish5123840.10GB

Metrics

We compared the performance of the GTE models with other popular text embedding models on the MTEB (CMTEB for Chinese language) benchmark. For more detailed comparison results, please refer to the MTEB leaderboard.

  • Evaluation results on CMTEB
ModelModel Size (GB)Embedding DimensionsSequence LengthAverage (35 datasets)Classification (9 datasets)Clustering (4 datasets)Pair Classification (2 datasets)Reranking (4 datasets)Retrieval (8 datasets)STS (8 datasets)
gte-large-zh0.65102451266.7271.3453.0781.1467.4272.4957.82
gte-base-zh0.2076851265.9271.2653.8680.4467.0071.7155.96
stella-large-zh-v20.651024102465.1369.0549.1682.6866.4170.1458.66
stella-large-zh0.651024102464.5467.6248.6578.7265.9871.0258.3
bge-large-zh-v1.51.3102451264.5369.1348.9981.665.8470.4656.25
stella-base-zh-v20.21768102464.3668.2949.479.9666.170.0856.92
stella-base-zh0.21768102464.1667.7748.776.0966.9571.0756.54
piccolo-large-zh0.65102451264.1167.0347.0478.3865.9870.9358.02
piccolo-base-zh0.276851263.6666.9847.1276.6166.6871.255.9
gte-small-zh0.151251260.0464.3548.9569.9966.2165.5049.72
bge-small-zh-v1.50.151251257.8263.9644.1870.460.9261.7749.1
m3e-base0.4176851257.7967.5247.6863.9959.5456.9150.47
text-embedding-ada-002(openai)-1536819253.0264.3145.6869.5654.2852.043.35

Usage

Code example

import torch.nn.functional as F
from torch import Tensor
from transformers import AutoTokenizer, AutoModel

input_texts = [
    "中国的首都是哪里",
    "你喜欢去哪里旅游",
    "北京",
    "今天中午吃什么"
]

tokenizer = AutoTokenizer.from_pretrained("thenlper/gte-large-zh")
model = AutoModel.from_pretrained("thenlper/gte-large-zh")

# Tokenize the input texts
batch_dict = tokenizer(input_texts, max_length=512, padding=True, truncation=True, return_tensors='pt')

outputs = model(**batch_dict)
embeddings = outputs.last_hidden_state[:, 0]
 
# (Optionally) normalize embeddings
embeddings = F.normalize(embeddings, p=2, dim=1)
scores = (embeddings[:1] @ embeddings[1:].T) * 100
print(scores.tolist())

Use with sentence-transformers:

from sentence_transformers import SentenceTransformer
from sentence_transformers.util import cos_sim

sentences = ['That is a happy person', 'That is a very happy person']

model = SentenceTransformer('thenlper/gte-large-zh')
embeddings = model.encode(sentences)
print(cos_sim(embeddings[0], embeddings[1]))

Limitation

This model exclusively caters to Chinese texts, and any lengthy texts will be truncated to a maximum of 512 tokens.

Citation

If you find our paper or models helpful, please consider citing them as follows:

@article{li2023towards,
  title={Towards general text embeddings with multi-stage contrastive learning},
  author={Li, Zehan and Zhang, Xin and Zhang, Yanzhao and Long, Dingkun and Xie, Pengjun and Zhang, Meishan},
  journal={arXiv preprint arXiv:2308.03281},
  year={2023}
}

Contributors

thenlper

7 commits

SFconvertbot

1 commits