2023-08-07 18:15:30 +00:00
{
"cells": [
{
"cell_type": "markdown",
"id": "719619d3",
"metadata": {},
"source": [
2023-09-08 02:53:33 +00:00
"# BGE on Hugging Face\n",
2023-08-07 18:15:30 +00:00
"\n",
2023-09-08 02:53:33 +00:00
">[BGE models on the HuggingFace](https://huggingface.co/BAAI/bge-large-en) are [the best open-source embedding models](https://huggingface.co/spaces/mteb/leaderboard).\n",
">BGE model is created by the [Beijing Academy of Artificial Intelligence (BAAI)](https://www.baai.ac.cn/english.html). `BAAI` is a private non-profit organization engaged in AI research and development.\n",
"\n",
"This notebook shows how to use `BGE Embeddings` through `Hugging Face`"
2023-08-07 18:15:30 +00:00
]
},
{
"cell_type": "code",
2023-09-08 02:53:33 +00:00
"execution_count": null,
2023-08-07 18:15:30 +00:00
"id": "f7a54279",
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
2023-09-08 02:53:33 +00:00
"#!pip install sentence_transformers"
2023-08-07 18:15:30 +00:00
]
},
{
"cell_type": "code",
2023-09-08 02:53:33 +00:00
"execution_count": null,
2023-08-07 18:15:30 +00:00
"id": "9e1d5b6b",
"metadata": {},
"outputs": [],
"source": [
"from langchain.embeddings import HuggingFaceBgeEmbeddings\n",
"\n",
"model_name = \"BAAI/bge-small-en\"\n",
"model_kwargs = {'device': 'cpu'}\n",
"encode_kwargs = {'normalize_embeddings': False}\n",
"hf = HuggingFaceBgeEmbeddings(\n",
" model_name=model_name,\n",
" model_kwargs=model_kwargs,\n",
" encode_kwargs=encode_kwargs\n",
")"
]
},
{
"cell_type": "code",
2023-09-08 02:53:33 +00:00
"execution_count": 5,
2023-08-07 18:15:30 +00:00
"id": "e59d1a89",
"metadata": {},
2023-09-08 02:53:33 +00:00
"outputs": [
{
"data": {
"text/plain": [
"384"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
2023-08-07 18:15:30 +00:00
"source": [
2023-09-08 02:53:33 +00:00
"embedding = hf.embed_query(\"hi this is harrison\")\n",
"len(embedding)"
2023-08-07 18:15:30 +00:00
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e596315f",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
2023-09-08 02:53:33 +00:00
"version": "3.10.12"
2023-08-07 18:15:30 +00:00
}
},
"nbformat": 4,
"nbformat_minor": 5
}