-
Notifications
You must be signed in to change notification settings - Fork 590
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
14 changed files
with
193 additions
and
53 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,2 +1,43 @@ | ||
FAQ | ||
=== | ||
=== | ||
|
||
Below are some commonly asked questions. | ||
|
||
.. tip:: | ||
|
||
For more questions, search issues on GitHub or join our community! | ||
|
||
|
||
.. dropdown:: When does the query instruction need to be used? | ||
|
||
For a retrieval task that uses short queries to find long related documents, it is recommended to add instructions for these short queries. | ||
The best method to decide whether to add instructions for queries is choosing the setting that achieves better performance on your task. | ||
In all cases, the documents/passages do not need to add the instruction. | ||
|
||
.. dropdown:: Why it takes quite long to just encode 1 sentence? | ||
|
||
Note that if you have multiple CUDA GPUs, FlagEmbedding will automatically use all of them. | ||
Then the time used to start the multi-process will cost way longer than the actual encoding. | ||
Try to just use CPU or just single GPU for simple tasks. | ||
|
||
.. dropdown:: The embedding results are different for CPU and GPU? | ||
|
||
The encode function will use FP16 by default if GPU is available, which leads to different precision. | ||
Set :code:`fp16=False` to get full precision. | ||
|
||
.. dropdown:: How many languages do the multi-lingual models support? | ||
|
||
The training datasets cover up to 170+ languages. | ||
But note that due to the unbalanced distribution of languages, the performances will be different. | ||
Please further test refer to the real application scenario. | ||
|
||
.. dropdown:: How does the different retrieval method works in bge-m3? | ||
|
||
- Dense retrieval: map the text into a single embedding, e.g., `DPR <https://arxiv.org/abs/2004.04906>`_, `BGE-v1.5 <../bge/bge_v1_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 <https://arxiv.org/pdf/2106.14807>`_, and `splade <https://arxiv.org/abs/2107.05720>`_ | ||
- Multi-vector retrieval: use multiple vectors to represent a text, e.g., `ColBERT <https://arxiv.org/abs/2004.12832>`_. | ||
|
||
.. dropdown:: Recommended vector database? | ||
|
||
Generally you can use any vector database (open-sourced, commercial). We use `Faiss <https://github.com/facebookresearch/faiss>`_ by default in our evaluation pipeline and tutorials. |
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,35 @@ | ||
Quick Start | ||
=========== | ||
|
||
First, load one of the BGE embedding model: | ||
|
||
.. code:: python | ||
from FlagEmbedding import FlagAutoModel | ||
model = FlagAutoModel.from_finetuned('BAAI/bge-base-en-v1.5', | ||
query_instruction_for_retrieval="Represent this sentence for searching relevant passages:", | ||
use_fp16=True) | ||
.. tip:: | ||
|
||
If there's difficulty connecting to Hugging Face, you can use the `HF mirror <https://hf-mirror.com/>`_ instead. | ||
|
||
.. code:: bash | ||
export HF_ENDPOINT=https://hf-mirror.com | ||
Then, feed some sentences to the model and get their embeddings: | ||
|
||
.. code:: python | ||
sentences_1 = ["I love NLP", "I love machine learning"] | ||
sentences_2 = ["I love BGE", "I love text retrieval"] | ||
embeddings_1 = model.encode(sentences_1) | ||
embeddings_2 = model.encode(sentences_2) | ||
Once we get the embeddings, we can compute similarity by inner product: | ||
|
||
.. code:: python | ||
similarity = embeddings_1 @ embeddings_2.T | ||
print(similarity) |
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 |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Quick Start" | ||
"# Retrieval Demo" | ||
] | ||
}, | ||
{ | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,51 @@ | ||
BGE-en-icl | ||
========== | ||
BGE-EN-ICL | ||
========== | ||
|
||
BGE-EN-ICL is the new SoTA embedding model in BGE series with capabilities: | ||
- In-context learning ability: By providing few-shot examples in the query, it can significantly enhance the model's ability to handle new tasks. | ||
- Outstanding performance: The model has achieved state-of-the-art (SOTA) performance on MTEB and AIR-Bench. | ||
|
||
+-------------------------------------------------------------------+-----------------+------------+--------------+----------------------------------------------------------------------------------------------------+ | ||
| Model | Language | Parameters | Model Size | Description | | ||
+===================================================================+=================+============+==============+====================================================================================================+ | ||
| `BAAI/bge-en-icl <https://huggingface.co/BAAI/bge-en-icl>`_ | English | 7.1B | 28.5 GB | In-context learning capabilities, fully leverage the model's potential based on a few shot examples| | ||
+-------------------------------------------------------------------+-----------------+------------+--------------+----------------------------------------------------------------------------------------------------+ | ||
|
||
|
||
|
||
Usage | ||
----- | ||
|
||
.. code:: python | ||
from FlagEmbedding import FlagICLModel | ||
documents = [ | ||
"As a general guideline, the CDC's average requirement of protein for women ages 19 to 70 is 46 grams per day. But, as you can see from this chart, you'll need to increase that if you're expecting or training for a marathon. Check out the chart below to see how much protein you should be eating each day.", | ||
"Definition of summit for English Language Learners. : 1 the highest point of a mountain : the top of a mountain. : 2 the highest level. : 3 a meeting or series of meetings between the leaders of two or more governments." | ||
] | ||
examples = [ | ||
{ | ||
'instruct': 'Given a web search query, retrieve relevant passages that answer the query.', | ||
'query': 'what is a virtual interface', | ||
'response': "A virtual interface is a software-defined abstraction that mimics the behavior and characteristics of a physical network interface. It allows multiple logical network connections to share the same physical network interface, enabling efficient utilization of network resources. Virtual interfaces are commonly used in virtualization technologies such as virtual machines and containers to provide network connectivity without requiring dedicated hardware. They facilitate flexible network configurations and help in isolating network traffic for security and management purposes." | ||
}, | ||
{ | ||
'instruct': 'Given a web search query, retrieve relevant passages that answer the query.', | ||
'query': 'causes of back pain in female for a week', | ||
'response': "Back pain in females lasting a week can stem from various factors. Common causes include muscle strain due to lifting heavy objects or improper posture, spinal issues like herniated discs or osteoporosis, menstrual cramps causing referred pain, urinary tract infections, or pelvic inflammatory disease. Pregnancy-related changes can also contribute. Stress and lack of physical activity may exacerbate symptoms. Proper diagnosis by a healthcare professional is crucial for effective treatment and management." | ||
} | ||
] | ||
queries = ["how much protein should a female eat", "summit define"] | ||
model = FlagICLModel('BAAI/bge-en-icl', | ||
examples_for_task=examples, # set `examples_for_task=None` to use model without examples | ||
examples_instruction_format="<instruct>{}\n<query>{}\n<response>{}") # specify the format to use examples_for_task | ||
embeddings_1 = model.encode_queries(queries) | ||
embeddings_2 = model.encode_corpus(documents) | ||
similarity = embeddings_1 @ embeddings_2.T | ||
print(similarity) |
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,2 @@ | ||
BGE-Reranker | ||
============ | ||
============ |
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,9 +11,3 @@ BGE | |
bge_m3 | ||
bge_icl | ||
|
||
.. toctree:: | ||
:maxdepth: 1 | ||
:caption: Embedder | ||
|
||
bge_reranker | ||
|
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,12 @@ | ||
Community | ||
========= | ||
========= | ||
|
||
Visit our `GitHub repo <https://github.com/FlagOpen/FlagEmbedding>`_ and | ||
`Hugging Face collection <https://huggingface.co/collections/BAAI/bge-66797a74476eb1f085c7446d>`_ for more materials! | ||
|
||
We are also holding WeChat groups for for BGE. Scan the QR code to join the group chat! | ||
To get the first hand message about our updates and new release, or having any questions or ideas, join us now! | ||
|
||
.. figure:: ../_static/img/BGE_WeChat_Group.png | ||
:width: 400 | ||
:align: center |
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