Instructions to use jinaai/jina-reranker-m0 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use jinaai/jina-reranker-m0 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="jinaai/jina-reranker-m0", trust_remote_code=True)# Load model directly from transformers import AutoProcessor, AutoModel processor = AutoProcessor.from_pretrained("jinaai/jina-reranker-m0", trust_remote_code=True) model = AutoModel.from_pretrained("jinaai/jina-reranker-m0", trust_remote_code=True, device_map="auto") - sentence-transformers
How to use jinaai/jina-reranker-m0 with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("jinaai/jina-reranker-m0", trust_remote_code=True) sentences = [ "The weather is lovely today.", "It's so sunny outside!", "He drove to the stadium." ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [3, 3] - Notebooks
- Google Colab
- Kaggle
About infer time
Example query and documents
import time
query = "slm markdown"
documents = [
"https://raw.githubusercontent.com/jina-ai/multimodal-reranker-test/main/handelsblatt-preview.png",
# "https://raw.githubusercontent.com/jina-ai/multimodal-reranker-test/main/paper-11.png"
]
construct sentence pairs
image_pairs = [[doc[0], doc] for doc in documents]
start1 = time.time()
scores1 = model.compute_score(image_pairs, max_length=2048, batch_size=1, doc_type="image")
end1 = time.time()
start2 = time.time()
scores2 = model.compute_score(image_pairs, max_length=2048, batch_size=2, doc_type="image")
end2 = time.time()
start3 = time.time()
scores3 = model.compute_score(image_pairs, max_length=2048, batch_size=1, doc_type="image")
end3 = time.time()
print(end1-start1,end2-start2,end3-start3)
print(scores1,scores2,scores3)
Why is batch=1 the fastest inference speed? I need more throughput, do you have any recommendations? Thanks!
Yes
I would suggest using local image instead. The image downloading time should also be considered in your case I think.
I tested with local images, and the situation I described is only about model inference time.