Instructions to use BAAI/llm-embedder with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use BAAI/llm-embedder with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="BAAI/llm-embedder")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModel tokenizer = AutoTokenizer.from_pretrained("BAAI/llm-embedder") model = AutoModel.from_pretrained("BAAI/llm-embedder", device_map="auto") - Inference
- Notebooks
- Google Colab
- Kaggle
Commit ·
1661329
1
Parent(s): f20d0dd
Update README.md
Browse files123456789108 unmodified lines19202122232425262728293031323334353635 unmodified lines7273747576777879808182838485868788899091929394959697989910033 unmodified lines134135136137138139140225 unmodified lines3663673683693703713723733743753764 unmodified lines38138238338438538638738813 unmodified lines402403404405406407---license: mit---<h1 align="center">FlagEmbedding</h1><h4 align="center"><p>8 unmodified lines<p></h4>More details please refer to our Github: [FlagEmbedding](https://github.com/FlagOpen/FlagEmbedding).[English](README.md) | [中文](https://github.com/FlagOpen/FlagEmbedding/blob/master/README_zh.md)FlagEmbedding can map any text to a low-dimensional dense vector which can be used for tasks like retrieval, classification, clustering, or semantic search.And it also can be used in vector databases for LLMs.************* 🌟**Updates**🌟 *************- 10/12/2023: Release [LLM-Embedder](https://github.com/FlagOpen/FlagEmbedding/tree/master/FlagEmbedding/llm_embedder), a unified embedding model to support diverse retrieval augmentation needs for LLMs. [Paper](https://arxiv.org/pdf/2310.07554.pdf) :fire:- 09/15/2023: The [technical report](https://arxiv.org/pdf/2309.07597.pdf) of BGE has been released- 09/15/2023: The [masive training data](https://data.baai.ac.cn/details/BAAI-MTP) of BGE has been released- 09/12/2023: New models:- **New reranker model**: release cross-encoder models `BAAI/bge-reranker-base` and `BAAI/bge-reranker-large`, which are more powerful than embedding model. We recommend to use/fine-tune them to re-rank top-k documents returned by embedding models.- **update embedding model**: release `bge-*-v1.5` embedding model to alleviate the issue of the similarity distribution, and enhance its retrieval ability without instruction.35 unmodified lines| [BAAI/bge-small-zh](https://huggingface.co/BAAI/bge-small-zh) | Chinese | [Inference](#usage-for-embedding-model) [Fine-tune](https://github.com/FlagOpen/FlagEmbedding/tree/master/examples/finetune) | a small-scale model but with competitive performance | `为这个句子生成表示以用于检索相关文章:` |[1\]: If you need to search the relevant passages to a query, we suggest to add the instruction to the query; in other cases, no instruction is needed, just use the original query directly. In all cases, **no instruction** needs to be added to passages.[2\]: Different from embedding model, reranker 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 bge embedding model to retrieve top 100 relevant documents, and then use bge reranker to re-rank the top 100 document to get the final top-3 results.All models have been uploaded to Huggingface Hub, and you can see them at https://huggingface.co/BAAI.If you cannot open the Huggingface Hub, you also can download the models at https://model.baai.ac.cn/models .## Frequently asked questions<details><summary>1. How to fine-tune bge embedding model?</summary><!-- ### How to fine-tune bge embedding model? -->Following this [example](https://github.com/FlagOpen/FlagEmbedding/tree/master/examples/finetune) to prepare data and fine-tune your model.Some suggestions:- Mine hard negatives following this [example](https://github.com/FlagOpen/FlagEmbedding/tree/master/examples/finetune#hard-negatives), which can improve the retrieval performance.- If you pre-train bge on your data, the pre-trained model cannot be directly used to calculate similarity, and it must be fine-tuned with contrastive learning before computing similarity.- If the accuracy of the fine-tuned model is still not high, it is recommended to use/fine-tune the cross-encoder model (bge-reranker) to re-rank top-k results. Hard negatives also are needed to fine-tune reranker.</details><details><summary>2. The similarity score between two dissimilar sentences is higher than 0.5</summary>33 unmodified lines### Usage for Embedding ModelHere are some examples for using `bge` models with[FlagEmbedding](#using-flagembedding), [Sentence-Transformers](#using-sentence-transformers), [Langchain](#using-langchain), or [Huggingface Transformers](#using-huggingface-transformers).#### Using FlagEmbedding225 unmodified lines### BAAI EmbeddingWe pre-train the models using [retromae](https://github.com/staoxiao/RetroMAE) and train them on large-scale pairs data using contrastive learning.**You can fine-tune the embedding model on your data following our [examples](https://github.com/FlagOpen/FlagEmbedding/tree/master/examples/finetune).**We also provide a [pre-train example](https://github.com/FlagOpen/FlagEmbedding/tree/master/examples/pretrain).Note that the goal of pre-training is to reconstruct the text, and the pre-trained model cannot be used for similarity calculation directly, it needs to be fine-tuned.More training details for bge see [baai_general_embedding](https://github.com/FlagOpen/FlagEmbedding/blob/master/FlagEmbedding/baai_general_embedding/README.md).4 unmodified linesTherefore, it can be used to re-rank the top-k documents returned by embedding model.We train the cross-encoder on a multilingual pair data,The data format is the same as embedding model, so you can fine-tune it easily following our [example](https://github.com/FlagOpen/FlagEmbedding/tree/master/examples/reranker).More details please refer to [./FlagEmbedding/reranker/README.md](https://github.com/FlagOpen/FlagEmbedding/tree/master/FlagEmbedding/reranker)## ContactIf you have any question or suggestion related to this project, feel free to open an issue or pull request.13 unmodified linesarchivePrefix={arXiv},primaryClass={cs.CL}}```## License1234567891011121314151617188 unmodified lines27282930313233343536373839404142434435 unmodified lines808182838485868788899091929394959697989910010110210310410510633 unmodified lines140141142143144145146225 unmodified lines3723733743753763773783793803813824 unmodified lines38738838939039139239339439539639739839940013 unmodified lines414415416417418419420421422423424425426427428<h1 align="center">FlagEmbedding</h1><p align="center"><a href="https://github.com/FlagOpen/FlagEmbedding"><img alt="Build" src="https://img.shields.io/badge/Contribution-Welcome-blue"></a><a href="https://github.com/FlagOpen/FlagEmbedding/blob/master/LICENSE"><img alt="License" src="https://img.shields.io/badge/LICENSE-MIT-green"></a><a href="https://huggingface.co/C-MTEB"><img alt="Build" src="https://img.shields.io/badge/C_MTEB-🤗-yellow"></a><a href="https://github.com/FlagOpen/FlagEmbedding/tree/master/FlagEmbedding/baai_general_embedding"><img alt="Build" src="https://img.shields.io/badge/FlagEmbedding-1.1-red"></a></p><h4 align="center"><p>8 unmodified lines<p></h4>[English](README.md) | [中文](https://github.com/FlagOpen/FlagEmbedding/blob/master/README_zh.md)<span style="#FF69B4;"> **Hiring:** We're seeking experienced NLP researchers and intern students focusing on dense retrieval and retrieval-augmented LLMs. If you're interested, please feel free to reach out to us via email at zhengliu1026@gmail.com.</span>FlagEmbedding can map any text to a low-dimensional dense vector, which can be used for tasks like retrieval, classification, clustering, and semantic search.And it can also be used in vector databases for LLMs.************* 🌟**Updates**🌟 *************- 10/12/2023: Release [LLM-Embedder](https://github.com/FlagOpen/FlagEmbedding/tree/master/FlagEmbedding/llm_embedder), a unified embedding model to support diverse retrieval augmentation needs for LLMs. [Paper](https://arxiv.org/pdf/2310.07554.pdf) :fire:- 09/15/2023: The [technical report](https://arxiv.org/pdf/2309.07597.pdf) of BGE has been released- 09/15/2023: The [massive training data](https://data.baai.ac.cn/details/BAAI-MTP) of BGE has been released- 09/12/2023: New models:- **New reranker model**: release cross-encoder models `BAAI/bge-reranker-base` and `BAAI/bge-reranker-large`, which are more powerful than embedding model. We recommend to use/fine-tune them to re-rank top-k documents returned by embedding models.- **update embedding model**: release `bge-*-v1.5` embedding model to alleviate the issue of the similarity distribution, and enhance its retrieval ability without instruction.35 unmodified lines| [BAAI/bge-small-zh](https://huggingface.co/BAAI/bge-small-zh) | Chinese | [Inference](#usage-for-embedding-model) [Fine-tune](https://github.com/FlagOpen/FlagEmbedding/tree/master/examples/finetune) | a small-scale model but with competitive performance | `为这个句子生成表示以用于检索相关文章:` |[1\]: If you need to search the relevant passages in a query, we suggest to add the instruction to the query; in other cases, no instruction is needed, just use the original query directly. In all cases, **no instruction** needs to be added to passages.[2\]: Different from the embedding model, reranker 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 example, use bge embedding model to retrieve top 100 relevant documents, and then use bge reranker to re-rank the top 100 documents to get the final top-3 results.All models have been uploaded to Huggingface Hub, and you can see them at https://huggingface.co/BAAI.If you cannot open the Huggingface Hub, you can also download the models at https://model.baai.ac.cn/models .## Frequently asked questions**1. How to fine-tune bge embedding model?**Following this [example](https://github.com/FlagOpen/FlagEmbedding/tree/master/examples/finetune) to prepare data and fine-tune your model.Some suggestions:- Mine hard negatives following this [example](https://github.com/FlagOpen/FlagEmbedding/tree/master/examples/finetune#hard-negatives), which can improve the retrieval performance.- In general, larger hyper-parameter `per_device_train_batch_size` brings better performance. You can expand it by enabling `--fp16`, `--deepspeed df_config.json` (df_config.json can refer to [ds_config.json](https://github.com/FlagOpen/FlagEmbedding/blob/master/examples/finetune/ds_config.json), `--gradient_checkpointing`, etc.- If you pre-train bge on your data, the pre-trained model cannot be directly used to calculate similarity, and it must be fine-tuned with contrastive learning before computing similarity.- If the accuracy of the fine-tuned model is still not high, it is recommended to use/fine-tune the cross-encoder model (bge-reranker) to re-rank top-k results. Hard negatives also are needed to fine-tune reranker.<details><summary>2. The similarity score between two dissimilar sentences is higher than 0.5</summary>33 unmodified lines### Usage for Embedding ModelHere are some examples of using `bge` models with[FlagEmbedding](#using-flagembedding), [Sentence-Transformers](#using-sentence-transformers), [Langchain](#using-langchain), or [Huggingface Transformers](#using-huggingface-transformers).#### Using FlagEmbedding225 unmodified lines### BAAI EmbeddingWe pre-train the models using [retromae](https://github.com/staoxiao/RetroMAE) and train them on large-scale pair data using contrastive learning.**You can fine-tune the embedding model on your data following our [examples](https://github.com/FlagOpen/FlagEmbedding/tree/master/examples/finetune).**We also provide a [pre-train example](https://github.com/FlagOpen/FlagEmbedding/tree/master/examples/pretrain).Note that the goal of pre-training is to reconstruct the text, and the pre-trained model cannot be used for similarity calculation directly, it needs to be fine-tuned.For more training details for bge see [baai_general_embedding](https://github.com/FlagOpen/FlagEmbedding/blob/master/FlagEmbedding/baai_general_embedding/README.md).4 unmodified linesTherefore, it can be used to re-rank the top-k documents returned by embedding model.We train the cross-encoder on a multilingual pair data,The data format is the same as embedding model, so you can fine-tune it easily following our [example](https://github.com/FlagOpen/FlagEmbedding/tree/master/examples/reranker).For more details please refer to [./FlagEmbedding/reranker/README.md](https://github.com/FlagOpen/FlagEmbedding/tree/master/FlagEmbedding/reranker)### Our Contributors:<a href="https://github.com/FlagOpen/FlagEmbedding/graphs/contributors"><img src="https://contrib.rocks/image?repo=FlagOpen/FlagEmbedding" /></a>## ContactIf you have any question or suggestion related to this project, feel free to open an issue or pull request.13 unmodified linesarchivePrefix={arXiv},primaryClass={cs.CL}}@misc{llm_embedder,title={Retrieve Anything To Augment Large Language Models},author={Peitian Zhang and Shitao Xiao and Zheng Liu and Zhicheng Dou and Jian-Yun Nie},year={2023},eprint={2310.07554},archivePrefix={arXiv},primaryClass={cs.IR}}```## License
README.md+46-25