bge reranker large

BAAI

Introduction

The BGE Reranker Large model, developed by the Beijing Academy of Artificial Intelligence (BAAI), is designed for reranking tasks, achieving high performance in multilingual contexts. It is part of the broader FlagEmbedding project, which focuses on retrieval-augmented language models.

Architecture

BAAI's BGE Reranker Large uses a cross-encoder architecture, allowing it to process pairs of questions and documents to output similarity scores directly. This method is more accurate than bi-encoders but is computationally more intensive.

Training

The training of the BGE Reranker involves using a cross-encoder with full attention over input pairs, trained on multilingual datasets. The training process includes pre-training using RetroMAE and fine-tuning with contrastive learning on large-scale pairs data. The reranker is designed to refine initial retrievals by reranking the top-k documents.

Guide: Running Locally

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

  1. Environment Setup:

    • Ensure Python and pip are installed.
    • Install necessary packages:
      pip install torch transformers
      
  2. Download and Load Model:

    • Use the Hugging Face Transformers library to load the model:
      from transformers import AutoTokenizer, AutoModelForSequenceClassification
      tokenizer = AutoTokenizer.from_pretrained('BAAI/bge-reranker-large')
      model = AutoModelForSequenceClassification.from_pretrained('BAAI/bge-reranker-large')
      
  3. Inference:

    • Prepare input pairs and compute scores:
      pairs = [['query', 'document']]
      inputs = tokenizer(pairs, padding=True, truncation=True, return_tensors='pt')
      with torch.no_grad():
          scores = model(**inputs).logits
      
  4. GPU Utilization:

    • For better performance, utilize cloud GPUs or on-premise GPUs by setting the device in PyTorch.

Cloud GPUs: Consider platforms like AWS, Google Cloud, or Azure to access powerful GPUs for faster computation.

License

The BGE Reranker and other models within the FlagEmbedding project are released under the MIT License, permitting free use for commercial purposes. The license details can be found here.

More Related APIs in Feature Extraction