中英日韩四个语种,以及中英日韩四个语种的跨语种能力(Multilingual and Crosslingual capability in English, Chinese, Japanese and Korean);
RAG优化,适配更多真实业务场景(RAG adaptation for more domains, including Education, Law, Finance, Medical, Literature, FAQ, Textbook, Wikipedia, etc.);
BCEmbedding适配长文本做rerank(Handle long passages reranking more than 512 limit in BCEmbedding);
RerankerModel可以提供 “平滑”的“绝对”相关性分数,“平滑”对排序友好,“绝对”分数用于过滤低质量passage,低质量passage过滤阈值推荐0.35或0.4。(RerankerModel provides "smooth" (for reranking) and "meaningful" (for filtering bad passages with a threshold of 0.35 or 0.4) similarity score, which help you figure out how relavent the query and passages are!)
最佳实践(Best practice) :embedding召回top50-100片段,reranker对这50-100片段精排,最后取top5-10片段。(1. Get top 50-100 passages with bce-embedding-base_v1 for "recall"; 2. Rerank passages with bce-reranker-base_v1 and get top 5-10 for "precision" finally. )
Bilingual and Crosslingual Embedding (BCEmbedding), developed by NetEase Youdao, encompasses EmbeddingModel and RerankerModel. The EmbeddingModel specializes in generating semantic vectors, playing a crucial role in semantic search and question-answering, and the RerankerModel excels at refining search results and ranking tasks.
BCEmbedding serves as the cornerstone of Youdao's Retrieval Augmented Generation (RAG) implmentation, notably QAnything [github], an open-source implementation widely integrated in various Youdao products like Youdao Speed Reading and Youdao Translation.
Distinguished for its bilingual and crosslingual proficiency, BCEmbedding excels in bridging Chinese and English linguistic gaps, which achieves
Existing embedding models often encounter performance challenges in bilingual and crosslingual scenarios, particularly in Chinese, English and their crosslingual tasks. BCEmbedding, leveraging the strength of Youdao's translation engine, excels in delivering superior performance across monolingual, bilingual, and crosslingual settings.
EmbeddingModel supports Chinese (ch) and English (en) (more languages support will come soon), while RerankerModel supports Chinese (ch), English (en), Japanese (ja) and Korean (ko).
Bilingual and Crosslingual Proficiency: Powered by Youdao's translation engine, excelling in Chinese, English and their crosslingual retrieval task, with upcoming support for additional languages.
RAG-Optimized: Tailored for diverse RAG tasks including translation, summarization, and question answering, ensuring accurate query understanding. See RAG Evaluations in LlamaIndex.
Efficient and Precise Retrieval: Dual-encoder for efficient retrieval of EmbeddingModel in first stage, and cross-encoder of RerankerModel for enhanced precision and deeper semantic analysis in second stage.
Broad Domain Adaptability: Trained on diverse datasets for superior performance across various fields.
User-Friendly Design: Instruction-free, versatile use for multiple tasks without specifying query instruction for each task.
Meaningful Reranking Scores: RerankerModel provides relevant scores to improve result quality and optimize large language model performance.
Proven in Production: Successfully implemented and validated in Youdao's products.
In RerankerModel.rerank method, we provide an advanced preproccess that we use in production for making sentence_pairs, when "passages" are very long.
2. Based on transformers
For EmbeddingModel:
python
1from transformers import AutoModel, AutoTokenizer
23# list of sentences4sentences =['sentence_0','sentence_1',...]56# init model and tokenizer7tokenizer = AutoTokenizer.from_pretrained('maidalun1020/bce-embedding-base_v1')8model = AutoModel.from_pretrained('maidalun1020/bce-embedding-base_v1')910device ='cuda'# if no GPU, set "cpu"11model.to(device)1213# get inputs14inputs = tokenizer(sentences, padding=True, truncation=True, max_length=512, return_tensors="pt")15inputs_on_device ={k: v.to(self.device)for k, v in inputs.items()}1617# get embeddings18outputs = model(**inputs_on_device, return_dict=True)19embeddings = outputs.last_hidden_state[:,0]# cls pooler20embeddings = embeddings / embeddings.norm(dim=1, keepdim=True)# normalize
For RerankerModel:
python
1import torch
2from transformers import AutoTokenizer, AutoModelForSequenceClassification
34# init model and tokenizer5tokenizer = AutoTokenizer.from_pretrained('maidalun1020/bce-reranker-base_v1')6model = AutoModelForSequenceClassification.from_pretrained('maidalun1020/bce-reranker-base_v1')78device ='cuda'# if no GPU, set "cpu"9model.to(device)1011# get inputs12inputs = tokenizer(sentence_pairs, padding=True, truncation=True, max_length=512, return_tensors="pt")13inputs_on_device ={k: v.to(device)for k, v in inputs.items()}1415# calculate scores16scores = model(**inputs_on_device, return_dict=True).logits.view(-1,).float()17scores = torch.sigmoid(scores)
3. Based on sentence_transformers
For EmbeddingModel:
python
1from sentence_transformers import SentenceTransformer
23# list of sentences4sentences =['sentence_0','sentence_1',...]56# init embedding model7## New update for sentence-trnasformers. So clean up your "`SENTENCE_TRANSFORMERS_HOME`/maidalun1020_bce-embedding-base_v1" or "~/.cache/torch/sentence_transformers/maidalun1020_bce-embedding-base_v1" first for downloading new version.8model = SentenceTransformer("maidalun1020/bce-embedding-base_v1")910# extract embeddings11embeddings = model.encode(sentences, normalize_embeddings=True)
Just run following cmd to evaluate your_embedding_model (e.g. maidalun1020/bce-embedding-base_v1) in bilingual and crosslingual settings (e.g. ["en", "zh", "en-zh", "zh-en"]).
Run following cmd to evaluate your_reranker_model (e.g. "maidalun1020/bce-reranker-base_v1") in bilingual and crosslingual settings (e.g. ["en", "zh", "en-zh", "zh-en"]).
LlamaIndex is a famous data framework for LLM-based applications, particularly in RAG. Recently, the LlamaIndex Blog has evaluated the popular embedding and reranker models in RAG pipeline and attract great attention. Now, we follow its pipeline to evaluate our BCEmbedding.
Hit rate calculates the fraction of queries where the correct answer is found within the top-k retrieved documents. In simpler terms, it's about how often our system gets it right within the top few guesses. The larger, the better.
Mean Reciprocal Rank (MRR):
For each query, MRR evaluates the system's accuracy by looking at the rank of the highest-placed relevant document. Specifically, it's the average of the reciprocals of these ranks across all the queries. So, if the first relevant document is the top result, the reciprocal rank is 1; if it's second, the reciprocal rank is 1/2, and so on. The larger, the better.
In order to compare our BCEmbedding with other embedding and reranker models fairly, we provide a one-click script to reproduce results of the LlamaIndex Blog, including our BCEmbedding:
The evaluation of LlamaIndex Blog is monolingual, small amount of data, and specific domain (just including "llama2" paper). In order to evaluate the broad domain adaptability, bilingual and crosslingual capability, we follow the blog to build a multiple domains evaluation dataset (includding "Computer Science", "Physics", "Biology", "Economics", "Math", and "Quantitative Finance"), named CrosslingualMultiDomainsDataset, by OpenAI gpt-4-1106-preview for high quality.
For users who prefer a hassle-free experience without the need to download and configure the model on their own systems, BCEmbedding is readily accessible through Youdao's API. This option offers a streamlined and efficient way to integrate BCEmbedding into your projects, bypassing the complexities of manual setup and maintenance. Detailed instructions and comprehensive API documentation are available at Youdao BCEmbedding API. Here, you'll find all the necessary guidance to easily implement BCEmbedding across a variety of use cases, ensuring a smooth and effective integration for optimal results.