huggingface.co
Total runs: 3.7M
24-hour runs: 152.1K
7-day runs: 215.7K
30-day runs: 2.1M
Model's Last Updated: July 03 2024
sentence-similarity

Introduction of bge-m3

Model Details of bge-m3

For more details please refer to our github repo: https://github.com/FlagOpen/FlagEmbedding

BGE-M3 ( paper , code )

In this project, we introduce BGE-M3, which is distinguished for its versatility in Multi-Functionality, Multi-Linguality, and Multi-Granularity.

  • Multi-Functionality: It can simultaneously perform the three common retrieval functionalities of embedding model: dense retrieval, multi-vector retrieval, and sparse retrieval.
  • Multi-Linguality: It can support more than 100 working languages.
  • Multi-Granularity: It is able to process inputs of different granularities, spanning from short sentences to long documents of up to 8192 tokens.

Some suggestions for retrieval pipeline in RAG

We recommend to use the following pipeline: hybrid retrieval + re-ranking.

  • Hybrid retrieval leverages the strengths of various methods, offering higher accuracy and stronger generalization capabilities. A classic example: using both embedding retrieval and the BM25 algorithm. Now, you can try to use BGE-M3, which supports both embedding and sparse retrieval. This allows you to obtain token weights (similar to the BM25) without any additional cost when generate dense embeddings. To use hybrid retrieval, you can refer to Vespa and Milvus .

  • As cross-encoder models, re-ranker demonstrates higher accuracy than bi-encoder embedding model. Utilizing the re-ranking model (e.g., bge-reranker , bge-reranker-v2 ) after retrieval can further filter the selected text.

News:
  • 2024/7/1: We update the MIRACL evaluation results of BGE-M3 . To reproduce the new results, you can refer to: bge-m3_miracl_2cr . We have also updated our paper on arXiv.

    Details

    The previous test results were lower because we mistakenly removed the passages that have the same id as the query from the search results. After correcting this mistake, the overall performance of BGE-M3 on MIRACL is higher than the previous results, but the experimental conclusion remains unchanged. The other results are not affected by this mistake. To reproduce the previous lower results, you need to add the --remove-query parameter when using pyserini.search.faiss or pyserini.search.lucene to search the passages.

  • 2024/3/20: Thanks Milvus team! Now you can use hybrid retrieval of bge-m3 in Milvus: pymilvus/examples /hello_hybrid_sparse_dense.py .

  • 2024/3/8: Thanks for the experimental results from @ Yannael . In this benchmark, BGE-M3 achieves top performance in both English and other languages, surpassing models such as OpenAI.

  • 2024/3/2: Release unified fine-tuning example and data

  • 2024/2/6: We release the MLDR (a long document retrieval dataset covering 13 languages) and evaluation pipeline .

  • 2024/2/1: Thanks for the excellent tool from Vespa. You can easily use multiple modes of BGE-M3 following this notebook

Specs
  • Model
Model Name Dimension Sequence Length Introduction
BAAI/bge-m3 1024 8192 multilingual; unified fine-tuning (dense, sparse, and colbert) from bge-m3-unsupervised
BAAI/bge-m3-unsupervised 1024 8192 multilingual; contrastive learning from bge-m3-retromae
BAAI/bge-m3-retromae -- 8192 multilingual; extend the max_length of xlm-roberta to 8192 and further pretrained via retromae
BAAI/bge-large-en-v1.5 1024 512 English model
BAAI/bge-base-en-v1.5 768 512 English model
BAAI/bge-small-en-v1.5 384 512 English model
  • Data
Dataset Introduction
MLDR Docuemtn Retrieval Dataset, covering 13 languages
bge-m3-data Fine-tuning data used by bge-m3
FAQ

1. Introduction for different retrieval methods

  • Dense retrieval: map the text into a single embedding, e.g., DPR , BGE-v1.5
  • Sparse retrieval (lexical matching): a vector of size equal to the vocabulary, with the majority of positions set to zero, calculating a weight only for tokens present in the text. e.g., BM25, unicoil , and splade
  • Multi-vector retrieval: use multiple vectors to represent a text, e.g., ColBERT .

2. How to use BGE-M3 in other projects?

For embedding retrieval, you can employ the BGE-M3 model using the same approach as BGE. The only difference is that the BGE-M3 model no longer requires adding instructions to the queries.

For hybrid retrieval, you can use Vespa and Milvus .

3. How to fine-tune bge-M3 model?

You can follow the common in this example to fine-tune the dense embedding.

If you want to fine-tune all embedding function of m3 (dense, sparse and colbert), you can refer to the unified_fine-tuning example

Usage

Install:

git clone https://github.com/FlagOpen/FlagEmbedding.git
cd FlagEmbedding
pip install -e .

or:

pip install -U FlagEmbedding
Generate Embedding for text
  • Dense Embedding
from FlagEmbedding import BGEM3FlagModel

model = BGEM3FlagModel('BAAI/bge-m3',  
                       use_fp16=True) # Setting use_fp16 to True speeds up computation with a slight performance degradation

sentences_1 = ["What is BGE M3?", "Defination of BM25"]
sentences_2 = ["BGE M3 is an embedding model supporting dense retrieval, lexical matching and multi-vector interaction.", 
               "BM25 is a bag-of-words retrieval function that ranks a set of documents based on the query terms appearing in each document"]

embeddings_1 = model.encode(sentences_1, 
                            batch_size=12, 
                            max_length=8192, # If you don't need such a long length, you can set a smaller value to speed up the encoding process.
                            )['dense_vecs']
embeddings_2 = model.encode(sentences_2)['dense_vecs']
similarity = embeddings_1 @ embeddings_2.T
print(similarity)
# [[0.6265, 0.3477], [0.3499, 0.678 ]]

You also can use sentence-transformers and huggingface transformers to generate dense embeddings. Refer to baai_general_embedding for details.

  • Sparse Embedding (Lexical Weight)
from FlagEmbedding import BGEM3FlagModel

model = BGEM3FlagModel('BAAI/bge-m3',  use_fp16=True) # Setting use_fp16 to True speeds up computation with a slight performance degradation

sentences_1 = ["What is BGE M3?", "Defination of BM25"]
sentences_2 = ["BGE M3 is an embedding model supporting dense retrieval, lexical matching and multi-vector interaction.", 
               "BM25 is a bag-of-words retrieval function that ranks a set of documents based on the query terms appearing in each document"]

output_1 = model.encode(sentences_1, return_dense=True, return_sparse=True, return_colbert_vecs=False)
output_2 = model.encode(sentences_2, return_dense=True, return_sparse=True, return_colbert_vecs=False)

# you can see the weight for each token:
print(model.convert_id_to_token(output_1['lexical_weights']))
# [{'What': 0.08356, 'is': 0.0814, 'B': 0.1296, 'GE': 0.252, 'M': 0.1702, '3': 0.2695, '?': 0.04092}, 
#  {'De': 0.05005, 'fin': 0.1368, 'ation': 0.04498, 'of': 0.0633, 'BM': 0.2515, '25': 0.3335}]


# compute the scores via lexical mathcing
lexical_scores = model.compute_lexical_matching_score(output_1['lexical_weights'][0], output_2['lexical_weights'][0])
print(lexical_scores)
# 0.19554901123046875

print(model.compute_lexical_matching_score(output_1['lexical_weights'][0], output_1['lexical_weights'][1]))
# 0.0
  • Multi-Vector (ColBERT)
from FlagEmbedding import BGEM3FlagModel

model = BGEM3FlagModel('BAAI/bge-m3',  use_fp16=True) 

sentences_1 = ["What is BGE M3?", "Defination of BM25"]
sentences_2 = ["BGE M3 is an embedding model supporting dense retrieval, lexical matching and multi-vector interaction.", 
               "BM25 is a bag-of-words retrieval function that ranks a set of documents based on the query terms appearing in each document"]

output_1 = model.encode(sentences_1, return_dense=True, return_sparse=True, return_colbert_vecs=True)
output_2 = model.encode(sentences_2, return_dense=True, return_sparse=True, return_colbert_vecs=True)

print(model.colbert_score(output_1['colbert_vecs'][0], output_2['colbert_vecs'][0]))
print(model.colbert_score(output_1['colbert_vecs'][0], output_2['colbert_vecs'][1]))
# 0.7797
# 0.4620
Compute score for text pairs

Input a list of text pairs, you can get the scores computed by different methods.

from FlagEmbedding import BGEM3FlagModel

model = BGEM3FlagModel('BAAI/bge-m3',  use_fp16=True) 

sentences_1 = ["What is BGE M3?", "Defination of BM25"]
sentences_2 = ["BGE M3 is an embedding model supporting dense retrieval, lexical matching and multi-vector interaction.", 
               "BM25 is a bag-of-words retrieval function that ranks a set of documents based on the query terms appearing in each document"]

sentence_pairs = [[i,j] for i in sentences_1 for j in sentences_2]

print(model.compute_score(sentence_pairs, 
                          max_passage_length=128, # a smaller max length leads to a lower latency
                          weights_for_different_modes=[0.4, 0.2, 0.4])) # weights_for_different_modes(w) is used to do weighted sum: w[0]*dense_score + w[1]*sparse_score + w[2]*colbert_score

# {
#   'colbert': [0.7796499729156494, 0.4621465802192688, 0.4523794651031494, 0.7898575067520142], 
#   'sparse': [0.195556640625, 0.00879669189453125, 0.0, 0.1802978515625], 
#   'dense': [0.6259765625, 0.347412109375, 0.349853515625, 0.67822265625], 
#   'sparse+dense': [0.482503205537796, 0.23454029858112335, 0.2332356721162796, 0.5122477412223816], 
#   'colbert+sparse+dense': [0.6013619303703308, 0.3255828022956848, 0.32089319825172424, 0.6232916116714478]
# }
Evaluation

We provide the evaluation script for MKQA and MLDR

Benchmarks from the open-source community

avatar The BGE-M3 model emerged as the top performer on this benchmark (OAI is short for OpenAI). For more details, please refer to the article and Github Repo

Our results
  • Multilingual (Miracl dataset)

avatar

  • Cross-lingual (MKQA dataset)

avatar

  • Long Document Retrieval

    • MLDR:
      avatar Please note that MLDR is a document retrieval dataset we constructed via LLM, covering 13 languages, including test set, validation set, and training set. We utilized the training set from MLDR to enhance the model's long document retrieval capabilities. Therefore, comparing baselines with Dense w.o.long (fine-tuning without long document dataset) is more equitable. Additionally, this long document retrieval dataset will be open-sourced to address the current lack of open-source multilingual long text retrieval datasets. We believe that this data will be helpful for the open-source community in training document retrieval models.

    • NarritiveQA:
      avatar

  • Comparison with BM25

We utilized Pyserini to implement BM25, and the test results can be reproduced by this script . We tested BM25 using two different tokenizers: one using Lucene Analyzer and the other using the same tokenizer as M3 (i.e., the tokenizer of xlm-roberta). The results indicate that BM25 remains a competitive baseline, especially in long document retrieval.

avatar

Training
  • Self-knowledge Distillation: combining multiple outputs from different retrieval modes as reward signal to enhance the performance of single mode(especially for sparse retrieval and multi-vec(colbert) retrival)
  • Efficient Batching: Improve the efficiency when fine-tuning on long text. The small-batch strategy is simple but effective, which also can used to fine-tune large embedding model.
  • MCLS: A simple method to improve the performance on long text without fine-tuning. If you have no enough resource to fine-tuning model with long text, the method is useful.

Refer to our report for more details.

Acknowledgement

Thanks to the authors of open-sourced datasets, including Miracl, MKQA, NarritiveQA, etc. Thanks to the open-sourced libraries like Tevatron , Pyserini .

Citation

If you find this repository useful, please consider giving a star :star: and citation

@misc{bge-m3,
      title={BGE M3-Embedding: Multi-Lingual, Multi-Functionality, Multi-Granularity Text Embeddings Through Self-Knowledge Distillation}, 
      author={Jianlv Chen and Shitao Xiao and Peitian Zhang and Kun Luo and Defu Lian and Zheng Liu},
      year={2024},
      eprint={2402.03216},
      archivePrefix={arXiv},
      primaryClass={cs.CL}
}

Runs of BAAI bge-m3 on huggingface.co

3.7M
Total runs
152.1K
24-hour runs
344.5K
3-day runs
215.7K
7-day runs
2.1M
30-day runs

More Information About bge-m3 huggingface.co Model

More bge-m3 license Visit here:

https://choosealicense.com/licenses/mit

bge-m3 huggingface.co

bge-m3 huggingface.co is an AI model on huggingface.co that provides bge-m3's model effect (), which can be used instantly with this BAAI bge-m3 model. huggingface.co supports a free trial of the bge-m3 model, and also provides paid use of the bge-m3. Support call bge-m3 model through api, including Node.js, Python, http.

bge-m3 huggingface.co Url

https://huggingface.co/BAAI/bge-m3

BAAI bge-m3 online free

bge-m3 huggingface.co is an online trial and call api platform, which integrates bge-m3's modeling effects, including api services, and provides a free online trial of bge-m3, you can try bge-m3 online for free by clicking the link below.

BAAI bge-m3 online free url in huggingface.co:

https://huggingface.co/BAAI/bge-m3

bge-m3 install

bge-m3 is an open source model from GitHub that offers a free installation service, and any user can find bge-m3 on GitHub to install. At the same time, huggingface.co provides the effect of bge-m3 install, users can directly use bge-m3 installed effect in huggingface.co for debugging and trial. It also supports api for free installation.

bge-m3 install url in huggingface.co:

https://huggingface.co/BAAI/bge-m3

Url of bge-m3

bge-m3 huggingface.co Url

Provider of bge-m3 huggingface.co

BAAI
ORGANIZATIONS

Other API from BAAI

huggingface.co

Total runs: 4.8M
Run Growth: -14.0M
Growth Rate: -289.11%
Updated: February 22 2024
huggingface.co

Total runs: 3.1M
Run Growth: -431.0M
Growth Rate: -14104.14%
Updated: February 21 2024
huggingface.co

Total runs: 2.8M
Run Growth: -166.0K
Growth Rate: -5.88%
Updated: February 21 2024
huggingface.co

Total runs: 762.0K
Run Growth: 266.3K
Growth Rate: 34.94%
Updated: December 13 2023
huggingface.co

Total runs: 703.0K
Run Growth: 531.7K
Growth Rate: 75.63%
Updated: April 02 2024
huggingface.co

Total runs: 696.3K
Run Growth: 422.8K
Growth Rate: 60.72%
Updated: October 12 2023
huggingface.co

Total runs: 220.4K
Run Growth: -234.0K
Growth Rate: -106.19%
Updated: November 14 2023
huggingface.co

Total runs: 32.8K
Run Growth: 5.6K
Growth Rate: 16.97%
Updated: April 17 2024
huggingface.co

Total runs: 31.1K
Run Growth: 17.8K
Growth Rate: 57.34%
Updated: October 12 2023
huggingface.co

Total runs: 30.5K
Run Growth: 19.7K
Growth Rate: 64.73%
Updated: October 12 2023
huggingface.co

Total runs: 23.9K
Run Growth: -22.5K
Growth Rate: -94.03%
Updated: December 26 2022
huggingface.co

Total runs: 7.9K
Run Growth: 3.9K
Growth Rate: 49.61%
Updated: October 12 2023
huggingface.co

Total runs: 6.6K
Run Growth: -304
Growth Rate: -4.59%
Updated: February 22 2024
huggingface.co

Total runs: 4.0K
Run Growth: 420
Growth Rate: 10.49%
Updated: October 12 2023
huggingface.co

Total runs: 3.1K
Run Growth: 3.0K
Growth Rate: 97.65%
Updated: October 27 2023
huggingface.co

Total runs: 3.0K
Run Growth: 2.6K
Growth Rate: 85.58%
Updated: May 13 2024
huggingface.co

Total runs: 2.4K
Run Growth: 1.8K
Growth Rate: 75.57%
Updated: April 19 2024
huggingface.co

Total runs: 2.3K
Run Growth: -1.7K
Growth Rate: -75.17%
Updated: February 07 2024
huggingface.co

Total runs: 2.3K
Run Growth: 329
Growth Rate: 14.35%
Updated: August 15 2024
huggingface.co

Total runs: 2.2K
Run Growth: 973
Growth Rate: 44.15%
Updated: June 11 2024
huggingface.co

Total runs: 1.7K
Run Growth: 918
Growth Rate: 53.50%
Updated: August 15 2024
huggingface.co

Total runs: 1.3K
Run Growth: -1.3K
Growth Rate: -105.90%
Updated: September 21 2023
huggingface.co

Total runs: 1.2K
Run Growth: 990
Growth Rate: 80.95%
Updated: March 07 2024
huggingface.co

Total runs: 749
Run Growth: -29
Growth Rate: -3.87%
Updated: June 07 2024
huggingface.co

Total runs: 730
Run Growth: -5.7K
Growth Rate: -783.42%
Updated: September 18 2023
huggingface.co

Total runs: 694
Run Growth: 46
Growth Rate: 6.63%
Updated: August 15 2024
huggingface.co

Total runs: 662
Run Growth: 154
Growth Rate: 23.26%
Updated: October 29 2023
huggingface.co

Total runs: 636
Run Growth: -561
Growth Rate: -88.21%
Updated: April 02 2024
huggingface.co

Total runs: 489
Run Growth: 414
Growth Rate: 84.66%
Updated: February 07 2024
huggingface.co

Total runs: 475
Run Growth: -1.1K
Growth Rate: -229.26%
Updated: October 12 2023
huggingface.co

Total runs: 454
Run Growth: 22
Growth Rate: 4.85%
Updated: June 24 2024
huggingface.co

Total runs: 346
Run Growth: 146
Growth Rate: 42.20%
Updated: August 23 2023
huggingface.co

Total runs: 192
Run Growth: -3
Growth Rate: -1.56%
Updated: December 21 2023
huggingface.co

Total runs: 178
Run Growth: 138
Growth Rate: 77.53%
Updated: December 31 2022
huggingface.co

Total runs: 177
Run Growth: 20
Growth Rate: 11.30%
Updated: December 21 2023
huggingface.co

Total runs: 132
Run Growth: 23
Growth Rate: 17.42%
Updated: August 23 2023
huggingface.co

Total runs: 84
Run Growth: -17
Growth Rate: -20.24%
Updated: May 13 2024
huggingface.co

Total runs: 71
Run Growth: -36
Growth Rate: -50.70%
Updated: April 18 2023
huggingface.co

Total runs: 68
Run Growth: -126
Growth Rate: -185.29%
Updated: June 24 2024
huggingface.co

Total runs: 57
Run Growth: 30
Growth Rate: 52.63%
Updated: December 25 2023
huggingface.co

Total runs: 46
Run Growth: -17
Growth Rate: -36.96%
Updated: October 02 2023
huggingface.co

Total runs: 32
Run Growth: 10
Growth Rate: 31.25%
Updated: July 24 2023
huggingface.co

Total runs: 28
Run Growth: -24
Growth Rate: -85.71%
Updated: October 27 2023
huggingface.co

Total runs: 25
Run Growth: -18
Growth Rate: -72.00%
Updated: December 05 2023
huggingface.co

Total runs: 18
Run Growth: -15
Growth Rate: -83.33%
Updated: May 31 2024
huggingface.co

Total runs: 9
Run Growth: 7
Growth Rate: 77.78%
Updated: November 28 2023
huggingface.co

Total runs: 6
Run Growth: -9
Growth Rate: -150.00%
Updated: May 13 2024
huggingface.co

Total runs: 4
Run Growth: -2
Growth Rate: -50.00%
Updated: October 09 2023
huggingface.co

Total runs: 0
Run Growth: 0
Growth Rate: 0.00%
Updated: December 07 2022
huggingface.co

Total runs: 0
Run Growth: 0
Growth Rate: 0.00%
Updated: December 30 2023
huggingface.co

Total runs: 0
Run Growth: 0
Growth Rate: 0.00%
Updated: April 21 2023
huggingface.co

Total runs: 0
Run Growth: 0
Growth Rate: 0.00%
Updated: August 13 2023
huggingface.co

Total runs: 0
Run Growth: 0
Growth Rate: 0.00%
Updated: March 26 2023
huggingface.co

Total runs: 0
Run Growth: 0
Growth Rate: 0.00%
Updated: March 18 2024