Views
No views yet
| 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 |
| Dataset | Introduction |
|---|---|
| MLDR | Docuemtn Retrieval Dataset, covering 13 languages |
git clone https://github.com/FlagOpen/FlagEmbedding.git
cd FlagEmbedding
pip install -e .pip install -U FlagEmbedding1from FlagEmbedding import BGEM3FlagModel
2
3model = BGEM3FlagModel('BAAI/bge-m3',
4 use_fp16=True) # Setting use_fp16 to True speeds up computation with a slight performance degradation
5
6sentences_1 = ["What is BGE M3?", "Defination of BM25"]
7sentences_2 = ["BGE M3 is an embedding model supporting dense retrieval, lexical matching and multi-vector interaction.",
8 "BM25 is a bag-of-words retrieval function that ranks a set of documents based on the query terms appearing in each document"]
9
10embeddings_1 = model.encode(sentences_1,
11 batch_size=12,
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.
13 )['dense_vecs']
14embeddings_2 = model.encode(sentences_2)['dense_vecs']
15similarity = embeddings_1 @ embeddings_2.T
16print(similarity)
17# [[0.6265, 0.3477], [0.3499, 0.678 ]]1from FlagEmbedding import BGEM3FlagModel
2
3model = BGEM3FlagModel('BAAI/bge-m3', use_fp16=True) # Setting use_fp16 to True speeds up computation with a slight performance degradation
4
5sentences_1 = ["What is BGE M3?", "Defination of BM25"]
6sentences_2 = ["BGE M3 is an embedding model supporting dense retrieval, lexical matching and multi-vector interaction.",
7 "BM25 is a bag-of-words retrieval function that ranks a set of documents based on the query terms appearing in each document"]
8
9output_1 = model.encode(sentences_1, return_dense=True, return_sparse=True, return_colbert_vecs=False)
10output_2 = model.encode(sentences_2, return_dense=True, return_sparse=True, return_colbert_vecs=False)
11
12# you can see the weight for each token:
13print(model.convert_id_to_token(output_1['lexical_weights']))
14# [{'What': 0.08356, 'is': 0.0814, 'B': 0.1296, 'GE': 0.252, 'M': 0.1702, '3': 0.2695, '?': 0.04092},
15# {'De': 0.05005, 'fin': 0.1368, 'ation': 0.04498, 'of': 0.0633, 'BM': 0.2515, '25': 0.3335}]
16
17
18# compute the scores via lexical mathcing
19lexical_scores = model.compute_lexical_matching_score(output_1['lexical_weights'][0], output_2['lexical_weights'][0])
20print(lexical_scores)
21# 0.19554901123046875
22
23print(model.compute_lexical_matching_score(output_1['lexical_weights'][0], output_1['lexical_weights'][1]))
24# 0.01from FlagEmbedding import BGEM3FlagModel
2
3model = BGEM3FlagModel('BAAI/bge-m3', use_fp16=True)
4
5sentences_1 = ["What is BGE M3?", "Defination of BM25"]
6sentences_2 = ["BGE M3 is an embedding model supporting dense retrieval, lexical matching and multi-vector interaction.",
7 "BM25 is a bag-of-words retrieval function that ranks a set of documents based on the query terms appearing in each document"]
8
9output_1 = model.encode(sentences_1, return_dense=True, return_sparse=True, return_colbert_vecs=True)
10output_2 = model.encode(sentences_2, return_dense=True, return_sparse=True, return_colbert_vecs=True)
11
12print(model.colbert_score(output_1['colbert_vecs'][0], output_2['colbert_vecs'][0]))
13print(model.colbert_score(output_1['colbert_vecs'][0], output_2['colbert_vecs'][1]))
14# 0.7797
15# 0.46201from FlagEmbedding import BGEM3FlagModel
2
3model = BGEM3FlagModel('BAAI/bge-m3', use_fp16=True)
4
5sentences_1 = ["What is BGE M3?", "Defination of BM25"]
6sentences_2 = ["BGE M3 is an embedding model supporting dense retrieval, lexical matching and multi-vector interaction.",
7 "BM25 is a bag-of-words retrieval function that ranks a set of documents based on the query terms appearing in each document"]
8
9sentence_pairs = [[i,j] for i in sentences_1 for j in sentences_2]
10
11print(model.compute_score(sentence_pairs,
12 max_passage_length=128, # a smaller max length leads to a lower latency
13 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
14
15# {
16# 'colbert': [0.7796499729156494, 0.4621465802192688, 0.4523794651031494, 0.7898575067520142],
17# 'sparse': [0.195556640625, 0.00879669189453125, 0.0, 0.1802978515625],
18# 'dense': [0.6259765625, 0.347412109375, 0.349853515625, 0.67822265625],
19# 'sparse+dense': [0.482503205537796, 0.23454029858112335, 0.2332356721162796, 0.5122477412223816],
20# 'colbert+sparse+dense': [0.6013619303703308, 0.3255828022956848, 0.32089319825172424, 0.6232916116714478]
21# }


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.
@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}
}