GTE was proposed in mGTE: Generalized Long-Context Text Representation and Reranking Models for Multilingual Text Retrieval by Xin Zhang, Yanzhao Zhang, Dingkun Long, Wen Xie,…
GTE
This model was published in HF papers on 2024-07-29 and contributed to Hugging Face Transformers on 2026-09-30.
GTE
Overview
GTE was proposed in mGTE: Generalized Long-Context Text Representation and Reranking Models for Multilingual Text Retrieval by Xin Zhang, Yanzhao Zhang, Dingkun Long, Wen Xie, Ziqi Dai, Jialong Tang, Huan Lin, Baosong Yang, Pengjun Xie, Fei Huang, Meishan Zhang, Wenjie Li and Min Zhang.
The abstract from the paper is the following:
We present systematic efforts in building long-context multilingual text representation model (TRM) and reranker from scratch for text retrieval. We first introduce a text encoder (base size) enhanced with RoPE and unpadding, pre-trained in a native 8192-token context (longer than 512 of previous multilingual encoders). Then we construct a hybrid TRM and a cross-encoder reranker by contrastive learning. Evaluations show that our text encoder outperforms the same-sized previous state-of-the-art XLM-R. Meanwhile, our TRM and reranker match the performance of large-sized state-of-the-art BGE-M3 models and achieve better results on long-context retrieval benchmarks. Further analysis demonstrate that our proposed models exhibit higher efficiency during both training and inference. We believe their efficiency and effectiveness could benefit various researches and industrial applications.
GTE is a BERT-style bidirectional encoder that replaces absolute position embeddings with RoPE, uses a gated MLP, and applies layer normalization after each residual connection. The same architecture backs Alibaba's gte-*-v1.5, gte-multilingual-* and gte-en-mlm-* checkpoints as well as Snowflake's snowflake-arctic-embed-m-v2.0.
This model was contributed by Harshal Janjani. The original code can be found here.
Tip Click on the GTE models in the right sidebar for more examples of how to apply GTE to different language tasks.
The example below demonstrates how to extract features (embeddings) with Pipeline and AutoModel.
Pipeline
from transformers import pipeline
pipeline = pipeline(
task="feature-extraction",
model="alibaba-nlp-community/gte-multilingual-base",
)
pipeline("Plants create oxygen through a process known as photosynthesis.")
AutoModel
import torch
from transformers import AutoModel, AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("alibaba-nlp-community/gte-multilingual-base")
model = AutoModel.from_pretrained("alibaba-nlp-community/gte-multilingual-base", device_map="auto")
inputs = tokenizer("Plants create oxygen through a process known as photosynthesis.", return_tensors="pt").to(model.device)
with torch.no_grad():
outputs = model(**inputs)
embeddings = outputs.last_hidden_state[:, 0]
print(f"Embeddings shape: {embeddings.shape}")
Notes
- GTE uses RoPE, so for correct positional encoding either use right padding (the default), or use left padding and prepare
position_idsaccordingly. type_vocab_sizediffers across checkpoints.alibaba-nlp-community/gte-base-en-v1.5sets it to0, in which case no token type embedding is created andtoken_type_idsare ignored.- The
gte-*-v1.5andgte-multilingual-*checkpoints apply static NTK scaling on top of RoPE. It is expressed as alinearmodeling_rope_utils.RopeParametersentry whoserope_thetais the base scaled by the NTK factor.
GteConfig
[[autodoc]] GteConfig
GteModel
[[autodoc]] GteModel - forward
GteForMaskedLM
[[autodoc]] GteForMaskedLM - forward
GteForSequenceClassification
[[autodoc]] GteForSequenceClassification - forward
GteForTokenClassification
[[autodoc]] GteForTokenClassification - forward
Source and license
Source: Transformers documentation, adapted for this site. Licensing and attribution follow the terms of the upstream project.