ms marco Tiny B E R T L 2 v2

cross-encoder

MS-MARCO-TINYBERT-L-2-V2 Model

Introduction

The MS-MARCO-TINYBERT-L-2-V2 model is a cross-encoder designed for information retrieval tasks, specifically trained on the MS MARCO Passage Ranking task. It is suitable for encoding queries with possible passages and sorting them by relevance, aiding in tasks such as document retrieval.

Architecture

This model utilizes a cross-encoder architecture that processes pairs of sentences (e.g., query and passage) together, allowing for more context-aware scoring of relevance. It is built on the TinyBERT framework, which is optimized for performance and efficiency.

Training

The model was trained using the MS MARCO dataset, focusing on the passage ranking task. Training details and code are available through SBERT.net, which provides resources for training models on similar tasks.

Guide: Running Locally

To use the model with the Transformers library:

  1. Install Dependencies: Ensure you have the transformers and torch libraries installed.

    pip install transformers torch
    
  2. Load the Model and Tokenizer:

    from transformers import AutoTokenizer, AutoModelForSequenceClassification
    import torch
    
    model = AutoModelForSequenceClassification.from_pretrained('cross-encoder/ms-marco-TinyBERT-L-2-v2')
    tokenizer = AutoTokenizer.from_pretrained('cross-encoder/ms-marco-TinyBERT-L-2-v2')
    
  3. Prepare Input and Make Predictions:

    features = tokenizer(['How many people live in Berlin?', 'How many people live in Berlin?'],
                         ['Berlin has a population of 3,520,031 registered inhabitants.', 'New York City is famous for the Metropolitan Museum of Art.'],
                         padding=True, truncation=True, return_tensors="pt")
    
    model.eval()
    with torch.no_grad():
        scores = model(**features).logits
        print(scores)
    
  4. Using SentenceTransformers (for simpler usage):

    from sentence_transformers import CrossEncoder
    
    model = CrossEncoder('cross-encoder/ms-marco-TinyBERT-L-2-v2', max_length=512)
    scores = model.predict([('Query', 'Paragraph1'), ('Query', 'Paragraph2') , ('Query', 'Paragraph3')])
    

Cloud GPUs

For optimal performance, especially when processing large datasets, consider utilizing cloud GPUs such as NVIDIA V100 available on platforms like AWS, Google Cloud, or Azure.

License

The model is released under the Apache 2.0 license, allowing for both personal and commercial use with proper attribution.

More Related APIs in Text Classification