Text Ranking
Transformers
ONNX
Safetensors
Transformers.js
sentence-transformers
English
deberta-v2
text-classification
reranker
text-embeddings-inference
Instructions to use mixedbread-ai/mxbai-rerank-large-v1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use mixedbread-ai/mxbai-rerank-large-v1 with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("mixedbread-ai/mxbai-rerank-large-v1") model = AutoModelForSequenceClassification.from_pretrained("mixedbread-ai/mxbai-rerank-large-v1", device_map="auto") - Transformers.js
How to use mixedbread-ai/mxbai-rerank-large-v1 with Transformers.js:
// npm i @huggingface/transformers import { AutoTokenizer, AutoModelForSequenceClassification } from '@huggingface/transformers'; const tokenizer = await AutoTokenizer.from_pretrained('mixedbread-ai/mxbai-rerank-large-v1'); const model = await AutoModelForSequenceClassification.from_pretrained('mixedbread-ai/mxbai-rerank-large-v1'); const query = 'Which planet is known as the Red Planet?'; const documents = [ 'Mars, known for its reddish appearance, is often referred to as the Red Planet.', 'Venus is often called the twin of Earth because of its similar size and proximity.', ]; const inputs = tokenizer(new Array(documents.length).fill(query), { text_pair: documents, padding: true, truncation: true }); const { logits } = await model(inputs); console.log(logits.sigmoid().tolist()); // one relevance score per document - sentence-transformers
How to use mixedbread-ai/mxbai-rerank-large-v1 with sentence-transformers:
from sentence_transformers import CrossEncoder model = CrossEncoder("mixedbread-ai/mxbai-rerank-large-v1") query = "Which planet is known as the Red Planet?" passages = [ "Venus is often called Earth's twin because of its similar size and proximity.", "Mars, known for its reddish appearance, is often referred to as the Red Planet.", "Jupiter, the largest planet in our solar system, has a prominent red spot.", "Saturn, famous for its rings, is sometimes mistaken for the Red Planet." ] scores = model.predict([(query, passage) for passage in passages]) print(scores) - Notebooks
- Google Colab
- Kaggle
Deployment using TEI
#7
by WolfAssi285 - opened
Is the reranker deployable using TEI? If not, what is the best way to deploy it?
This reranker is not compatible with TEI, but you could deploy it to Inference Endpoints using this link
Then you can make calls like so:
import requests
API_URL = "YOUR_URL"
headers = {
"Accept" : "application/json",
"Authorization": "Bearer hf_token",
"Content-Type": "application/json"
}
def query(payload):
response = requests.post(API_URL, headers=headers, json=payload)
return response.json()
q = "Who wrote 'To Kill a Mockingbird'?"
documents = [
"'To Kill a Mockingbird' is a novel by Harper Lee published in 1960. It was immediately successful, winning the Pulitzer Prize, and has become a classic of modern American literature.",
"The novel 'Moby-Dick' was written by Herman Melville and first published in 1851. It is considered a masterpiece of American literature and deals with complex themes of obsession, revenge, and the conflict between good and evil.",
"Harper Lee, an American novelist widely known for her novel 'To Kill a Mockingbird', was born in 1926 in Monroeville, Alabama. She received the Pulitzer Prize for Fiction in 1961.",
"Jane Austen was an English novelist known primarily for her six major novels, which interpret, critique and comment upon the British landed gentry at the end of the 18th century.",
"The 'Harry Potter' series, which consists of seven fantasy novels written by British author J.K. Rowling, is among the most popular and critically acclaimed books of the modern era.",
"'The Great Gatsby', a novel written by American author F. Scott Fitzgerald, was published in 1925. The story is set in the Jazz Age and follows the life of millionaire Jay Gatsby and his pursuit of Daisy Buchanan."
]
outputs = []
for d in documents:
output = query({
"inputs": q + "[SEP]" + d,
"parameters": {}
})
outputs.append(output)
# outputs
# [[{'label': 'LABEL_0', 'score': 0.9980194568634033}],
# [{'label': 'LABEL_0', 'score': 0.02262076362967491}],
# [{'label': 'LABEL_0', 'score': 0.9969398975372314}],
# [{'label': 'LABEL_0', 'score': 0.02526130899786949}],
# [{'label': 'LABEL_0', 'score': 0.006077906116843224}],
# [{'label': 'LABEL_0', 'score': 0.029478583484888077}]]
P.s. that link is user-specific (you should replace nbroad with your own user if you want to try it), and you must also have connected your Inference Endpoints to your HF Account. You'll be prompted to do that if you click "Go" on anything here: https://ui.endpoints.huggingface.co/catalog