Views
No views yet
jina-reranker-m0 is a cutting-edge multimodal, multilingual reranker for text, code, image and visual document reranking. Check out its features and benchmarks here.jinaai/jina-reranker-m0-GGUF with various quantization levels on HuggingFace.
This repo covers how to use them and how they’re built.AutoModel.from_pretrained API. In short, three steps: (1) write prompt (2) get last embedding (3) map embedding to the score.(QUERY, DOCUMENT) pair as a prompt:**Document**:\n{DOCUMENT}\n**Query**:\n{QUERY}<|box_end|>test.txt for the corret batch construction. Note how \n is NOT the instance separator, but <|box_end|><#sep#> is.llama.cpp or llama-embedding. You can change F16 to other quantizations:1llama-embedding -hf jinaai/jina-reranker-m0-GGUF:F16 \
2 --pooling last --embd-normalize -1 --embd-separator "<#sep#>" --embd-output-format json \
3 -p "**Document**:\nWe present ReaderLM-v2\n**Query**:\nslm markdown<|box_end|>"1llama-embedding -hf jinaai/jina-reranker-m0-GGUF:F16 \
2 --pooling last --embd-normalize -1 --embd-separator "<#sep#>" --embd-output-format json \
3 -f test.txt \
4 2>/dev/null >out.jsonlast_embeddings into a predefined MLP to get the relevance score.1import json
2import numpy as np
3
4# reconstruct MLP
5with np.load('mlp_weights.npz') as data:
6 W1, b1, W2, b2 = data['W1'], data['b1'], data['W2'], data['b2']
7 logit_bias = float(data['logit_bias'][0])
8
9mlp = lambda x: 1 / (1 + np.exp(-((np.maximum(0, x @ W1 + b1) @ W2 + b2) - logit_bias)))
10
11# get embeddings from file
12with open('out.json') as f:
13 data = json.load(f)
14embeddings = np.array([item['embedding'] for item in data['data']])
15
16# get relevance score
17rel_score = mlp(embeddings)jina-reranker-m0 builds on Qwen/Qwen2-VL-2B. But two quirks make it trickier:token_id=100 as a scoring token at the end of each (query, document) pair to trigger "the scoring state". This token was arbitrarily picked during m0's training, which complicates things for GGUF users familiar with string-level inputs, as it doesn’t play nice with BPE tokenizers. Our fix is that we swapped 100 with <|box_end|>: 151649 in the tokenizer before building GGUFs. So, you’ll need to append <|box_end|> to each (QUERY, DOCUMENT) pair like this:**Document**:\n{DOCUMENT}\n**Query**:\n{QUERY}<|box_end|>llama.cpp doesn’t support it well. Instead, we dump the MLP into a separate mlp_weights.npz file. This MLP is a simple two-layer setup with ReLU activation, mapping the last hidden state of <|box_end|> from 1536 dimensions to a single score. To use it in Python, load and reconstruct the MLP like this:1import numpy as np
2with np.load('mlp_weights.npz') as data:
3 W1, b1, W2, b2 = data['W1'], data['b1'], data['W2'], data['b2']
4 logit_bias = float(data['logit_bias'][0])
5
6mlp = lambda x: 1 / (1 + np.exp(-((np.maximum(0, x @ W1 + b1) @ W2 + b2) - logit_bias)))jina-reranker-m0-GGUF are calculated as mlp(last_embeddings).