Bge Reranker V2 M3

Multilingual reranker

The Bge Reranker V2 M3 model is a lightweight reranker designed for efficient deployment and fast inference. It's capable of handling multilingual inputs and provides relevance scores for query-passage pairs. Unlike traditional embedding models, this reranker directly outputs similarity scores, which can be mapped to a float value between 0 and 1 using a sigmoid function. With its strong multilingual capabilities and ease of use, this model is suitable for a variety of applications, from simple text analysis to more complex tasks like question answering and information retrieval. It's also worth noting that this model is part of a larger family of rerankers, each with its own strengths and weaknesses, so you can choose the one that best fits your specific needs.

BAAI apache-2.0 Updated 10 months ago

Table of Contents

Model Overview

The BAAI Reranker model is a powerful tool for natural language processing tasks. It’s designed to take in a question and a document as input and output a similarity score, which can be mapped to a float value between 0 and 1 using a sigmoid function.

Capabilities

The BAAI Reranker models are capable of ranking the relevance of a query to a passage. They can output a similarity score, which can be mapped to a float value between 0 and 1 using a sigmoid function.

Primary Tasks

  • Relevance Ranking: The models can rank the relevance of a query to a passage, making them suitable for applications such as search engines, question answering, and text classification.
  • Multilingual Support: The models support multiple languages, including Chinese and English, making them a great choice for applications that require multilingual support.

Strengths

  • Lightweight: The models are lightweight and easy to deploy, making them suitable for applications that require fast inference.
  • Fast Inference: The models have fast inference speeds, making them suitable for applications that require real-time responses.
  • Multilingual Capabilities: The models have strong multilingual capabilities, making them a great choice for applications that require support for multiple languages.

Unique Features

  • Layerwise Output: The BAAI/bge-reranker-v2-minicpm-layerwise model allows for layerwise output, which can be useful for applications that require more control over the output.
  • Fine-tuning: The models can be fine-tuned for specific tasks, making them more accurate and effective for specific applications.

Model Variants

The BAAI Reranker model comes in several variants, each with its own strengths:

ModelLanguageLayerwise
BAAI/bge-reranker-baseChinese and English-
BAAI/bge-reranker-largeChinese and English-
BAAI/bge-reranker-v2-m3Multilingual-
BAAI/bge-reranker-v2-gemmaMultilingual-
BAAI/bge-reranker-v2-minicpm-layerwiseMultilingual8-40

Performance

The BAAI Reranker model has shown remarkable performance in various tasks, especially when it comes to speed, accuracy, and efficiency. Let’s dive into the details!

Speed

The model’s speed is quite impressive, making it suitable for large-scale applications. With the ability to process multiple queries and passages simultaneously, it can handle a high volume of data efficiently.

Accuracy

The model’s accuracy is also noteworthy, with high relevance scores indicating a strong correlation between the query and passage. This is particularly evident in the example where the model correctly identifies the relevance of a passage to a query.

Efficiency

The model’s efficiency is another key aspect of its performance. With the option to use use_fp16=True or use_bf16=True, the model can be fine-tuned to achieve faster computation with a slight performance degradation. This makes it an excellent choice for applications where speed is crucial.

Limitations

The BAAI Reranker model is a powerful tool, but it’s not perfect. Let’s take a closer look at some of its limitations.

Limited Context Understanding

The BAAI Reranker model can struggle to understand the context of a query or passage, especially when it comes to nuances like idioms, sarcasm, or figurative language. This can lead to misinterpretation or incorrect scoring.

Lack of Domain-Specific Knowledge

While the BAAI Reranker model has been trained on a vast amount of text data, it may not have the same level of domain-specific knowledge as a human expert. This can be a limitation in certain fields like medicine, law, or finance, where specialized knowledge is crucial.

Multilingual Challenges

Although the BAAI Reranker model supports multiple languages, it may not perform equally well across all languages. This can be due to differences in language structure, vocabulary, or cultural nuances.

Dependence on Training Data

The BAAI Reranker model is only as good as the data it was trained on. If the training data contains biases or inaccuracies, the model may learn to replicate these flaws.

Limited Ability to Handle Ambiguity

The BAAI Reranker model can struggle with ambiguous queries or passages, where the meaning is unclear or open to interpretation. In such cases, the model may not be able to provide accurate scoring.

Potential for Overfitting

Like any machine learning model, the BAAI Reranker model can be prone to overfitting, where it becomes too specialized to the training data and fails to generalize well to new, unseen data.

Examples
Compute the relevance score between the query 'what is panda?' and the passage 'The giant panda (Ailuropoda melanoleuca), sometimes called a panda bear or simply panda, is a bear species endemic to China.' 0.9948403768236574
What is the relevance score between the query 'what is panda?' and the passage 'hi'? 0.00027803096387751553
Compute the relevance score between the query 'what is panda?' and the passage 'The giant panda (Ailuropoda melanoleuca), sometimes called a panda bear or simply panda, is a bear species endemic to China.' using the BAAI/bge-reranker-v2-minicpm-layerwise model and selecting the 28th layer for output. 0.9979348957672119

Format

Reranker uses a unique architecture that directly outputs similarity scores between a query and a document, unlike embedding models that produce embeddings. You can input a query and a passage to the reranker and get a relevance score, which can be mapped to a float value between 0 and 1 using the sigmoid function.

Supported Data Formats

The reranker supports the following data formats:

  • Query and Passage: You can input a query and a passage as a pair, and the reranker will output a relevance score.
  • JSON File: For fine-tuning, the reranker accepts a JSON file where each line is a dictionary containing a query, positive texts, negative texts, and a prompt.

Special Requirements

  • Input Length: The maximum input length for the query and passage is 512 tokens.
  • Layer Selection: For LLM-based layerwise rerankers, you can select which layers to use for computing the score by adjusting the cutoff_layers parameter.

Code Examples

  • Using FlagEmbedding:
from FlagEmbedding import FlagReranker
reranker = FlagReranker('BAAI/bge-reranker-v2-m3', use_fp16=True)
score = reranker.compute_score(['query', 'passage'])
print(score)
  • Using Huggingface Transformers:
import torch
from transformers import AutoModelForSequenceClassification, AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained('BAAI/bge-reranker-v2-m3')
model = AutoModelForSequenceClassification.from_pretrained('BAAI/bge-reranker-v2-m3')
model.eval()
pairs = [['what is panda?', 'hi'], ['what is panda?', 'The giant panda (Ailuropoda melanoleuca), sometimes called a panda bear or simply panda, is a bear species endemic to China.']]
with torch.no_grad():
    inputs = tokenizer(pairs, padding=True, truncation=True, return_tensors='pt', max_length=512)
    scores = model(**inputs, return_dict=True).logits.view(-1, ).float()
    print(scores)
Dataloop's AI Development Platform
Build end-to-end workflows

Build end-to-end workflows

Dataloop is a complete AI development stack, allowing you to make data, elements, models and human feedback work together easily.

  • Use one centralized tool for every step of the AI development process.
  • Import data from external blob storage, internal file system storage or public datasets.
  • Connect to external applications using a REST API & a Python SDK.
Save, share, reuse

Save, share, reuse

Every single pipeline can be cloned, edited and reused by other data professionals in the organization. Never build the same thing twice.

  • Use existing, pre-created pipelines for RAG, RLHF, RLAF, Active Learning & more.
  • Deploy multi-modal pipelines with one click across multiple cloud resources.
  • Use versions for your pipelines to make sure the deployed pipeline is the stable one.
Easily manage pipelines

Easily manage pipelines

Spend less time dealing with the logistics of owning multiple data pipelines, and get back to building great AI applications.

  • Easy visualization of the data flow through the pipeline.
  • Identify & troubleshoot issues with clear, node-based error messages.
  • Use scalable AI infrastructure that can grow to support massive amounts of data.