-
Notifications
You must be signed in to change notification settings - Fork 614
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
187 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
data loader | ||
=========== | ||
|
||
.. autoclass:: FlagEmbedding.abc.evaluation.BEIREvalDataLoader | ||
.. autoclass:: FlagEmbedding.evaluation.bier.BEIREvalDataLoader |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 5 additions & 3 deletions
8
docs/source/Introduction/concept.rst → docs/source/Introduction/model.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Overview | ||
======== | ||
|
||
Our repository provides well-structured `APIs <https://github.com/FlagOpen/FlagEmbedding/tree/master/FlagEmbedding>`_ for the inference, evaluation, and fine-tuning of BGE series models. | ||
Besides that, there are abundant resources of `tutorials <https://github.com/FlagOpen/FlagEmbedding/tree/master/Tutorials>`_ and `examples <https://github.com/FlagOpen/FlagEmbedding/tree/master/examples>`_ for users to quickly get a hands-on experience. | ||
|
||
.. figure:: https://raw.githubusercontent.com/FlagOpen/FlagEmbedding/refs/heads/master/imgs/projects.png | ||
:width: 700 | ||
:align: center | ||
|
||
Structure of contents in our `repo <https://github.com/FlagOpen/FlagEmbedding>`_ | ||
|
||
Our repository provides well-structured contents |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,37 @@ | ||
BGE-Reranker | ||
============ | ||
|
||
Different from embedding model, reranker, or cross-encoder uses question and document as input and directly output similarity instead of embedding. | ||
To balance the accuracy and time cost, cross-encoder is widely used to re-rank top-k documents retrieved by other simple models. | ||
For examples, use a bge embedding model to first retrieve top 100 relevant documents, and then use bge reranker to re-rank the top 100 document to get the final top-3 results. | ||
|
||
The first series of BGE-Reranker contains two models, large and base. | ||
|
||
+-------------------------------------------------------------------------------+-----------------------+------------+--------------+-----------------------------------------------------------------------+ | ||
| Model | Language | Parameters | Model Size | Description | | ||
+===============================================================================+=======================+============+==============+=======================================================================+ | ||
| `BAAI/bge-reranker-large <https://huggingface.co/BAAI/bge-reranker-large>`_ | English & Chinese | 560M | 2.24 GB | Larger reranker model, easy to deploy with better inference | | ||
+-------------------------------------------------------------------------------+-----------------------+------------+--------------+-----------------------------------------------------------------------+ | ||
| `BAAI/bge-reranker-base <https://huggingface.co/BAAI/bge-reranker-base>`_ | English & Chinese | 278M | 1.11 GB | Lightweight reranker model, easy to deploy with fast inference | | ||
+-------------------------------------------------------------------------------+-----------------------+------------+--------------+-----------------------------------------------------------------------+ | ||
|
||
bge-reranker-large and bge-reranker-base used `XLM-RoBERTa-Large <https://huggingface.co/FacebookAI/xlm-roberta-large>`_ and `XLM-RoBERTa-Base <https://huggingface.co/FacebookAI/xlm-roberta-base>`_ respectively as the base model. | ||
They were trained on high quality English and Chinese data, and acheived State-of-The-Art performance in the level of same size models at the time released. | ||
|
||
Usage | ||
----- | ||
|
||
|
||
.. code:: python | ||
from FlagEmbedding import FlagReranker | ||
reranker = FlagReranker( | ||
'BAAI/bge-reranker-base', | ||
query_max_length=256, | ||
use_fp16=True, | ||
devices=['cuda:1'], | ||
) | ||
score = reranker.compute_score(['I am happy to help', 'Assisting you is my pleasure']) | ||
print(score) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
BGE-Reranker-v2 | ||
=============== | ||
|
||
+------------------------------------------------------------------------------------------------------------------+-----------------------+-------------+--------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+ | ||
| Model | Language | Parameters | Model Size | Description | | ||
+==================================================================================================================+=======================+=============+==============+=========================================================================================================================================================+ | ||
| `BAAI/bge-reranker-v2-m3 <https://huggingface.co/BAAI/bge-reranker-v2-m3>`_ | Multilingual | 568M | 2.27 GB | Lightweight reranker model, possesses strong multilingual capabilities, easy to deploy, with fast inference. | | ||
+------------------------------------------------------------------------------------------------------------------+-----------------------+-------------+--------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+ | ||
| `BAAI/bge-reranker-v2-gemma <https://huggingface.co/BAAI/bge-reranker-v2-gemma>`_ | Multilingual | 2.51B | 10 GB | Suitable for multilingual contexts, performs well in both English proficiency and multilingual capabilities. | | ||
+------------------------------------------------------------------------------------------------------------------+-----------------------+-------------+--------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+ | ||
| `BAAI/bge-reranker-v2-minicpm-layerwise <https://huggingface.co/BAAI/bge-reranker-v2-minicpm-layerwise>`_ | Multilingual | 2.72B | 10.9 GB | Suitable for multilingual contexts, allows freedom to select layers for output, facilitating accelerated inference. | | ||
+------------------------------------------------------------------------------------------------------------------+-----------------------+-------------+--------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+ | ||
| `BAAI/bge-reranker-v2.5-gemma2-lightweight <https://huggingface.co/BAAI/bge-reranker-v2.5-gemma2-lightweight>`_ | Multilingual | 2.72B | 10.9 GB | Suitable for multilingual contexts, allows freedom to select layers, compress ratio and compress layers for output, facilitating accelerated inference. | | ||
+------------------------------------------------------------------------------------------------------------------+-----------------------+-------------+--------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+ | ||
|
||
|
||
.. tip:: Suggessions on model selection | ||
|
||
You can select the model according your senario and resource: | ||
|
||
- For multilingual, utilize :code:`BAAI/bge-reranker-v2-m3`, :code:`BAAI/bge-reranker-v2-gemma` and :code:`BAAI/bge-reranker-v2.5-gemma2-lightweight`. | ||
- For Chinese or English, utilize :code:`BAAI/bge-reranker-v2-m3` and :code:`BAAI/bge-reranker-v2-minicpm-layerwise`. | ||
- For efficiency, utilize :code:`BAAI/bge-reranker-v2-m3` and the low layer of :code:`BAAI/bge-reranker-v2-minicpm-layerwise`. | ||
- For better performance, recommand :code:`BAAI/bge-reranker-v2-minicpm-layerwise` and :code:`BAAI/bge-reranker-v2-gemma`. | ||
|
||
Make sure always test on your real use case and choose the one with best speed-quality balance! | ||
|
||
Usage | ||
----- | ||
|
||
Use bge-reranker-v2-m3 in the same way as bge-reranker-base and bge-reranker-large. | ||
|
||
.. code:: python | ||
from FlagEmbedding import FlagReranker | ||
# Setting use_fp16 to True speeds up computation with a slight performance degradation | ||
reranker = FlagReranker('BAAI/bge-reranker-v2-m3', use_fp16=True) | ||
score = reranker.compute_score(['query', 'passage']) | ||
# or set "normalize=True" to apply a sigmoid function to the score for 0-1 range | ||
score = reranker.compute_score(['query', 'passage'], normalize=True) | ||
print(score) | ||
Use the :code:`FlagLLMReranker` class for bge-reranker-v2-gemma. | ||
|
||
.. code:: python | ||
from FlagEmbedding import FlagLLMReranker | ||
# Setting use_fp16 to True speeds up computation with a slight performance degradation | ||
reranker = FlagLLMReranker('BAAI/bge-reranker-v2-gemma', use_fp16=True) | ||
score = reranker.compute_score(['query', 'passage']) | ||
print(score) | ||
Use the :code:`LayerWiseFlagLLMReranker` class for bge-reranker-v2-minicpm-layerwise. | ||
|
||
.. code:: python | ||
from FlagEmbedding import LayerWiseFlagLLMReranker | ||
# Setting use_fp16 to True speeds up computation with a slight performance degradation | ||
reranker = LayerWiseFlagLLMReranker('BAAI/bge-reranker-v2-minicpm-layerwise', use_fp16=True) | ||
# Adjusting 'cutoff_layers' to pick which layers are used for computing the score. | ||
score = reranker.compute_score(['query', 'passage'], cutoff_layers=[28]) | ||
print(score) | ||
Use the :code:`LightWeightFlagLLMReranker` class for bge-reranker-v2.5-gemma2-lightweight. | ||
|
||
.. code:: python | ||
from FlagEmbedding import LightWeightFlagLLMReranker | ||
# Setting use_fp16 to True speeds up computation with a slight performance degradation | ||
reranker = LightWeightFlagLLMReranker('BAAI/bge-reranker-v2.5-gemma2-lightweight', use_fp16=True) | ||
# Adjusting 'cutoff_layers' to pick which layers are used for computing the score. | ||
score = reranker.compute_score(['query', 'passage'], cutoff_layers=[28], compress_ratio=2, compress_layer=[24, 40]) | ||
print(score) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,9 @@ BGE | |
bge_m3 | ||
bge_icl | ||
|
||
.. toctree:: | ||
:maxdepth: 1 | ||
:caption: Reranker | ||
|
||
bge_reranker | ||
bge_reranker_v2 |