How to Use the Polish Reranker Large RankNet Model

Category :

The Polish reranker large RankNet model is a powerful tool designed for text classification and information retrieval, particularly focusing on the Polish language. This blog will guide you through the usage of this model, ensuring that you can implement it effectively. Whether you’re a beginner or an expert, these straightforward instructions will enable you to harness the model’s full capabilities.

Overview of the Model

This model is trained using the RankNet loss, an innovative technique that pays attention to the relative order of document relevance in response to a query. It leverages a robust dataset comprising:

  • Polish MS MARCO training set with 800k queries
  • Translation of the ELI5 dataset containing over 500k queries
  • A pool of Polish medical Q&A with approximately 100k queries

The combination of these elements yields a reranker that performs significantly well, achieving an impressive **NDCG@10 score of 62.65** in the Rerankers category of the Polish Information Retrieval Benchmark.

How to Use the Model

Follow the steps below to implement the model using Sentence-Transformers or Huggingface Transformers.

Usage with Sentence-Transformers

Here’s how to use the model with Sentence-Transformers:

from sentence_transformers import CrossEncoder
import torch

query = "Jak dożyć 100 lat?"
answers = [
    "Trzeba zdrowo się odżywiać i uprawiać sport.",
    "Trzeba pić alkohol, imprezować i jeździć szybkimi autami.",
    "Gdy trwała kampania politycy zapewniali, że rozprawią się z zakazem niedzielnego handlu."
]

model = CrossEncoder("sdadaspolish-reranker-large-ranknet", default_activation_function=torch.nn.Identity(), max_length=512, device='cuda' if torch.cuda.is_available() else 'cpu')
pairs = [[query, answer] for answer in answers]
results = model.predict(pairs)
print(results.tolist())

Usage with Huggingface Transformers

Alternatively, you can use the model with Huggingface Transformers as follows:

from transformers import AutoTokenizer, AutoModelForSequenceClassification
import numpy as np

query = "Jak dożyć 100 lat?"
answers = [
    "Trzeba zdrowo się odżywiać i uprawiać sport.",
    "Trzeba pić alkohol, imprezować i jeździć szybkimi autami.",
    "Gdy trwała kampania politycy zapewniali, że rozprawią się z zakazem niedzielnego handlu."
]

model_name = "sdadaspolish-reranker-large-ranknet"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)

texts = [f"{query} {answer}" for answer in answers]
tokens = tokenizer(texts, padding='longest', max_length=512, truncation=True, return_tensors='pt')
output = model(**tokens)
results = output.logits.detach().numpy()
results = np.squeeze(results)
print(results.tolist())

Understanding the Code

Let’s visualize the code analogy. Think of the reranker as a grading system for an exam where each student (document) answers a question (query). Instead of giving everyone an individual score (the pointwise loss), this system evaluates how they compare to each other based on their relevance. Just like in a competitive exam, where the top scorers are ranked against each other, our reranker sorts documents by their relevance scores derived from the teacher model based on previous assessments.

Troubleshooting

If you encounter issues while using the model, consider the following troubleshooting ideas:

  • Ensure that all libraries are installed and updated. You can reinstall Sentence-Transformers and Huggingface Transformers to resolve compatibility issues.
  • Check the availability of your GPU. If issues arise with CUDA, switch to CPU mode by updating the device parameter.
  • Verify that your input data (queries and answers) are in the correct format, ensuring they meet the model’s requirements.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Conclusion

With the Polish reranker large RankNet model, you have at your fingertips an advanced tool for text classification and information retrieval. Follow this guide to leverage its capabilities effectively in your projects. At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox

Latest Insights

© 2024 All Rights Reserved

×