2024-12-05 07:42:30 +00:00
|
|
|
Quick Start
|
|
|
|
===========
|
|
|
|
|
|
|
|
First, load one of the BGE embedding model:
|
|
|
|
|
|
|
|
.. code:: python
|
|
|
|
|
|
|
|
from FlagEmbedding import FlagAutoModel
|
|
|
|
|
2024-12-18 13:00:54 +00:00
|
|
|
model = FlagAutoModel.from_finetuned('BAAI/bge-base-en-v1.5')
|
2024-12-05 07:42:30 +00:00
|
|
|
|
|
|
|
.. 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
|
2024-12-18 13:00:54 +00:00
|
|
|
|
2024-12-05 07:42:30 +00:00
|
|
|
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)
|