bge reranker base

BAAI

Introduction

The BGE Reranker Base model, developed by the Beijing Academy of Artificial Intelligence, is a cross-encoder model designed for reranking tasks, supporting English and Chinese languages. It leverages the sentence-transformers library and is compatible with frameworks like PyTorch and ONNX.

Architecture

The model employs a cross-encoder architecture, which uses full attention on the input question-document pairs. This approach provides higher accuracy compared to bi-encoder models, at the cost of increased computational resources. The cross-encoder architecture is particularly effective for reranking tasks, making it suitable for refining the top-k documents retrieved by simpler models.

Training

The BGE Reranker Base model is pretrained using large-scale multilingual pair data and optimized with cross-entropy loss. While pretraining focuses on reconstructing text, the model requires fine-tuning to perform effectively on specific reranking tasks. Fine-tuning can be performed using contrastive learning approaches on target datasets.

Guide: Running Locally

To run the BGE Reranker Base model locally, follow these steps:

  1. Install Dependencies:

    pip install -U FlagEmbedding sentence-transformers transformers
    
  2. Load the Model:

    from transformers import AutoModelForSequenceClassification, AutoTokenizer
    tokenizer = AutoTokenizer.from_pretrained('BAAI/bge-reranker-base')
    model = AutoModelForSequenceClassification.from_pretrained('BAAI/bge-reranker-base')
    
  3. Prepare Input Data:

    pairs = [['query', 'document']]
    inputs = tokenizer(pairs, padding=True, truncation=True, return_tensors='pt')
    
  4. Compute Scores:

    import torch
    with torch.no_grad():
        scores = model(**inputs, return_dict=True).logits.view(-1, ).float()
    print(scores)
    
  5. Cloud GPUs: For intensive computations, consider using cloud services like AWS, GCP, or Azure that provide access to GPU instances.

License

The BGE Reranker Base model and its related resources are licensed under the MIT License, allowing for free commercial use. For more details, refer to FlagEmbedding's MIT License.

More Related APIs in Text Classification