alt.freeweights.embed / bge-reranker-v2-minicpm-layerwise
From: BAAI <huggingface.co/BAAI>Newsgroups: alt.freeweights.embedSubject:

bge-reranker-v2-minicpm-layerwise

Date: 2026-11-14Commit: 47b5332Signed: 2DC28CC7B26A283B ✓

Text classification model with 2.7B parameters. Safetensors weights, 10.9 GB in all. Published by BAAI under Apache-2.0.

2.7B params10.9GBbge-reranker-v2-minicpm-layerwisesafetensorspermissive
FactsParams2.7BSize10.9 GBFormatssafetensorsTasktext classificationLicenseApache-2.0From sourcepermissive
$ fw get BAAI/bge-reranker-v2-minicpm-layerwise
# manifest sha256 ffc29ee28431… · 10.9 GB · 19 files
$ fw verify ./bge-reranker-v2-minicpm-layerwise BAAI/bge-reranker-v2-minicpm-layerwise
From sourceHosted (signed)BAAI/bge-reranker-v2-minicpm-layerwiseLast check: 2026-11-14 21:08 UTC

Get help: custom fine-tune or private deploy. We review your setup before we quote.

Works with

Runs with

Ranked by fit to this model (safetensors), then by GitHub stars.

Overview

Size
10.9 GB
Weights
10.9 GB (safetensors)
Parameters
2.7B
Formats
safetensors
Task
text classification
License
Apache-2.0 (permissive)
Files
19, each with a sha256
Publisher
BAAI
Added
2026-11-14
Section
alt.freeweights.embed
Lineage

Original release from the publisher.

Where these bytes come from
Publisher at the pinned commit→You

Sources are tried in order. A file counts only when its size and sha256 match the manifest. Sources are checked when you ask for them, not on a timer.

Sources
BadgeHostLast checkResult
From sourcehuggingface.co2026-11-14 21:08 UTCpassed

Model card

From the publisher at commit 47b5332. Shown as plain text with links; images open at the publisher.

Reranker#

More details please refer to our Github: FlagEmbedding.

Different from embedding model, reranker uses question and document as input and directly output similarity instead of embedding. You can get a relevance score by inputting query and passage to the reranker. And the score can be mapped to a float value in [0,1] by sigmoid function.

Model List#

ModelBase modelLanguagelayerwisefeature
BAAI/bge-reranker-basexlm-roberta-baseChinese and English-Lightweight reranker model, easy to deploy, with fast inference.
BAAI/bge-reranker-largexlm-roberta-largeChinese and English-Lightweight reranker model, easy to deploy, with fast inference.
BAAI/bge-reranker-v2-m3bge-m3Multilingual-Lightweight reranker model, possesses strong multilingual capabilities, easy to deploy, with fast inference.
BAAI/bge-reranker-v2-gemmagemma-2bMultilingual-Suitable for multilingual contexts, performs well in both English proficiency and multilingual capabilities.
BAAI/bge-reranker-v2-minicpm-layerwiseMiniCPM-2B-dpo-bf16Multilingual8-40Suitable for multilingual contexts, performs well in both English and Chinese proficiency, allows freedom to select layers for output, facilitating accelerated inference.

You can select the model according your senario and resource.

Usage#

Using FlagEmbedding#
pip install -U FlagEmbedding
For normal reranker (bge-reranker-base / bge-reranker-large / bge-reranker-v2-m3 )#

Get relevance scores (higher scores indicate more relevance):

from FlagEmbedding import FlagReranker
reranker = FlagReranker('BAAI/bge-reranker-v2-m3', use_fp16=True) # Setting use_fp16 to True speeds up computation with a slight performance degradation

score = reranker.compute_score(['query', 'passage'])
print(score) # -5.65234375

# You can map the scores into 0-1 by set "normalize=True", which will apply sigmoid function to the score
score = reranker.compute_score(['query', 'passage'], normalize=True)
print(score) # 0.003497010252573502

scores = reranker.compute_score([['what is panda?', 'hi'], ['what is panda?', 'The giant panda (Ailuropoda melanoleuca), sometimes called a panda bear or simply panda, is a bear species endemic to China.']])
print(scores) # [-8.1875, 5.26171875]

# You can map the scores into 0-1 by set "normalize=True", which will apply sigmoid function to the score
scores = reranker.compute_score([['what is panda?', 'hi'], ['what is panda?', 'The giant panda (Ailuropoda melanoleuca), sometimes called a panda bear or simply panda, is a bear species endemic to China.']], normalize=True)
print(scores) # [0.00027803096387751553, 0.9948403768236574]
For LLM-based reranker#
from FlagEmbedding import FlagLLMReranker
reranker = FlagLLMReranker('BAAI/bge-reranker-v2-gemma', use_fp16=True) # Setting use_fp16 to True speeds up computation with a slight performance degradation
# reranker = FlagLLMReranker('BAAI/bge-reranker-v2-gemma', use_bf16=True) # You can also set use_bf16=True to speed up computation with a slight performance degradation

score = reranker.compute_score(['query', 'passage'])
print(score)

scores = reranker.compute_score([['what is panda?', 'hi'], ['what is panda?', 'The giant panda (Ailuropoda melanoleuca), sometimes called a panda bear or simply panda, is a bear species endemic to China.']])
print(scores)
For LLM-based layerwise reranker#
from FlagEmbedding import LayerWiseFlagLLMReranker
reranker = LayerWiseFlagLLMReranker('BAAI/bge-reranker-v2-minicpm-layerwise', use_fp16=True) # Setting use_fp16 to True speeds up computation with a slight performance degradation
# reranker = LayerWiseFlagLLMReranker('BAAI/bge-reranker-v2-minicpm-layerwise', use_bf16=True) # You can also set use_bf16=True to speed up computation with a slight performance degradation

score = reranker.compute_score(['query', 'passage'], cutoff_layers=[28]) # Adjusting 'cutoff_layers' to pick which layers are used for computing the score.
print(score)

scores = reranker.compute_score([['what is panda?', 'hi'], ['what is panda?', 'The giant panda (Ailuropoda melanoleuca), sometimes called a panda bear or simply panda, is a bear species endemic to China.']], cutoff_layers=[28])
print(scores)
Using Huggingface transformers#
For normal reranker (bge-reranker-base / bge-reranker-large / bge-reranker-v2-m3 )#

Get relevance scores (higher scores indicate more relevance):

import torch
from transformers import AutoModelForSequenceClassification, AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained('BAAI/bge-reranker-v2-m3')
model = AutoModelForSequenceClassification.from_pretrained('BAAI/bge-reranker-v2-m3')
model.eval()

pairs = [['what is panda?', 'hi'], ['what is panda?', 'The giant panda (Ailuropoda melanoleuca), sometimes called a panda bear or simply panda, is a bear species endemic to China.']]
with torch.no_grad():
    inputs = tokenizer(pairs, padding=True, truncation=True, return_tensors='pt', max_length=512)
    scores = model(**inputs, return_dict=True).logits.view(-1, ).float()
    print(scores)
For LLM-based reranker#
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer

def get_inputs(pairs, tokenizer, prompt=None, max_length=1024):
    if prompt is None:
        prompt = "Given a query A and a passage B, determine whether the passage contains an answer to the query by providing a prediction of either 'Yes' or 'No'."
    sep = "\n"
    prompt_inputs = tokenizer(prompt,
                              return_tensors=None,
                              add_special_tokens=False)['input_ids']
    sep_inputs = tokenizer(sep,
                           return_tensors=None,
                           add_special_tokens=False)['input_ids']
    inputs = []
    for query, passage in pairs:
        query_inputs = tokenizer(f'A: {query}',
                                 return_tensors=None,
                                 add_special_tokens=False,
                                 max_length=max_length * 3 // 4,
                                 truncation=True)
        passage_inputs = tokenizer(f'B: {passage}',
                                   return_tensors=None,
                                   add_special_tokens=False,
                                   max_length=max_length,
                                   truncation=True)
        item = tokenizer.prepare_for_model(
            [tokenizer.bos_token_id] + query_inputs['input_ids'],
            sep_inputs + passage_inputs['input_ids'],
            truncation='only_second',
            max_length=max_length,
            padding=False,
            return_attention_mask=False,
            return_token_type_ids=False,
            add_special_tokens=False
        )
        item['input_ids'] = item['input_ids'] + sep_inputs + prompt_inputs
        item['attention_mask'] = [1] * len(item['input_ids'])
        inputs.append(item)
    return tokenizer.pad(
            inputs,
            padding=True,
            max_length=max_length + len(sep_inputs) + len(prompt_inputs),
            pad_to_multiple_of=8,
            return_tensors='pt',
    )

tokenizer = AutoTokenizer.from_pretrained('BAAI/bge-reranker-v2-gemma')
model = AutoModelForCausalLM.from_pretrained('BAAI/bge-reranker-v2-gemma')
yes_loc = tokenizer('Yes', add_special_tokens=False)['input_ids'][0]
model.eval()

pairs = [['what is panda?', 'hi'], ['what is panda?', 'The giant panda (Ailuropoda melanoleuca), sometimes called a panda bear or simply panda, is a bear species endemic to China.']]
with torch.no_grad():
    inputs = get_inputs(pairs, tokenizer)
    scores = model(**inputs, return_dict=True).logits[:, -1, yes_loc].view(-1, ).float()
    print(scores)
For LLM-based layerwise reranker#
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer

def get_inputs(pairs, tokenizer, prompt=None, max_length=1024):
    if prompt is None:
        prompt = "Given a query A and a passage B, determine whether the passage contains an answer to the query by providing a prediction of either 'Yes' or 'No'."
    sep = "\n"
    prompt_inputs = tokenizer(prompt,
                              return_tensors=None,
                              add_special_tokens=False)['input_ids']
    sep_inputs = tokenizer(sep,
                           return_tensors=None,
                           add_special_tokens=False)['input_ids']
    inputs = []
    for query, passage in pairs:
        query_inputs = tokenizer(f'A: {query}',
                                 return_tensors=None,
                                 add_special_tokens=False,
                                 max_length=max_length * 3 // 4,
                                 truncation=True)
        passage_inputs = tokenizer(f'B: {passage}',
                                   return_tensors=None,
                                   add_special_tokens=False,
                                   max_length=max_length,
                                   truncation=True)
        item = tokenizer.prepare_for_model(
            [tokenizer.bos_token_id] + query_inputs['input_ids'],
            sep_inputs + passage_inputs['input_ids'],
            truncation='only_second',
            max_length=max_length,
            padding=False,
            return_attention_mask=False,
            return_token_type_ids=False,
            add_special_tokens=False
        )
        item['input_ids'] = item['input_ids'] + sep_inputs + prompt_inputs
        item['attention_mask'] = [1] * len(item['input_ids'])
        inputs.append(item)
    return tokenizer.pad(
            inputs,
            padding=True,
            max_length=max_length + len(sep_inputs) + len(prompt_inputs),
            pad_to_multiple_of=8,
            return_tensors='pt',
    )

tokenizer = AutoTokenizer.from_pretrained('BAAI/bge-reranker-v2-minicpm-layerwise', trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained('BAAI/bge-reranker-v2-minicpm-layerwise', trust_remote_code=True, torch_dtype=torch.bfloat16)
model = model.to('cuda')
model.eval()

pairs = [['what is panda?', 'hi'], ['what is panda?', 'The giant panda (Ailuropoda melanoleuca), sometimes called a panda bear or simply panda, is a bear species endemic to China.']]
with torch.no_grad():
    inputs = get_inputs(pairs, tokenizer).to(model.device)
    all_scores = model(**inputs, return_dict=True, cutoff_layers=[28])
    all_scores = [scores[:, -1].view(-1, ).float() for scores in all_scores[0]]
    print(all_scores)

Fine-tune#

Data Format#

Train data should be a json file, where each line is a dict like this:

{"query": str, "pos": List[str], "neg":List[str], "prompt": str}

query is the query, and pos is a list of positive texts, neg is a list of negative texts, prompt indicates the relationship between query and texts. If you have no negative texts for a query, you can random sample some from the entire corpus as the negatives.

See toy_finetune_data.jsonl for a toy data file.

Train#

You can fine-tune the reranker with the following code:

For llm-based reranker

torchrun --nproc_per_node {number of gpus} \
-m FlagEmbedding.llm_reranker.finetune_for_instruction.run \
--output_dir {path to save model} \
--model_name_or_path google/gemma-2b \
--train_data ./toy_finetune_data.jsonl \
--learning_rate 2e-4 \
--num_train_epochs 1 \
--per_device_train_batch_size 1 \
--gradient_accumulation_steps 16 \
--dataloader_drop_last True \
--query_max_len 512 \
--passage_max_len 512 \
--train_group_size 16 \
--logging_steps 1 \
--save_steps 2000 \
--save_total_limit 50 \
--ddp_find_unused_parameters False \
--gradient_checkpointing \
--deepspeed stage1.json \
--warmup_ratio 0.1 \
--bf16 \
--use_lora True \
--lora_rank 32 \
--lora_alpha 64 \
--use_flash_attn True \
--target_modules q_proj k_proj v_proj o_proj

For llm-based layerwise reranker

torchrun --nproc_per_node {number of gpus} \
-m FlagEmbedding.llm_reranker.finetune_for_layerwise.run \
--output_dir {path to save model} \
--model_name_or_path openbmb/MiniCPM-2B-dpo-bf16 \
--train_data ./toy_finetune_data.jsonl \
--learning_rate 2e-4 \
--num_train_epochs 1 \
--per_device_train_batch_size 1 \
--gradient_accumulation_steps 16 \
--dataloader_drop_last True \
--query_max_len 512 \
--passage_max_len 512 \
--train_group_size 16 \
--logging_steps 1 \
--save_steps 2000 \
--save_total_limit 50 \
--ddp_find_unused_parameters False \
--gradient_checkpointing \
--deepspeed stage1.json \
--warmup_ratio 0.1 \
--bf16 \
--use_lora True \
--lora_rank 32 \
--lora_alpha 64 \
--use_flash_attn True \
--target_modules q_proj k_proj v_proj o_proj \
--start_layer 8 \
--head_multi True \
--head_type simple \
--lora_extra_parameters linear_head

Our rerankers are initialized from google/gemma-2b (for llm-based reranker) and openbmb/MiniCPM-2B-dpo-bf16 (for llm-based layerwise reranker), and we train it on a mixture of multilingual datasets:

Evaluation#

  • llama-index.

Image: image-20240317193909373

  • BEIR.

rereank the top 100 results from bge-en-v1.5 large.

Image: image-20240317174633333

rereank the top 100 results from e5 mistral 7b instruct.

Image: image-20240317172949713

  • CMTEB-retrieval.

It rereank the top 100 results from bge-zh-v1.5 large.

Image: image-20240317173026235

  • miracl (multi-language).

It rereank the top 100 results from bge-m3.

Image: image-20240317173117639

Citation#

If you find this repository useful, please consider giving a star and citation

@misc{li2023making,
      title={Making Large Language Models A Better Foundation For Dense Retrieval}, 
      author={Chaofan Li and Zheng Liu and Shitao Xiao and Yingxia Shao},
      year={2023},
      eprint={2312.15503},
      archivePrefix={arXiv},
      primaryClass={cs.CL}
}
@misc{chen2024bge,
      title={BGE M3-Embedding: Multi-Lingual, Multi-Functionality, Multi-Granularity Text Embeddings Through Self-Knowledge Distillation}, 
      author={Jianlv Chen and Shitao Xiao and Peitian Zhang and Kun Luo and Defu Lian and Zheng Liu},
      year={2024},
      eprint={2402.03216},
      archivePrefix={arXiv},
      primaryClass={cs.CL}
}

Files

19 files · 10.9 GBWeights 10.9 GB (safetensors). Sizes and sha256 from the signed manifest.
Hide all 19 files with their sha256
FileSizesha256
.gitattributes1.52 KB11ad7efa24975ee4b0c3c3a38ed18737f0658a5f75a0a96787b576a78a023361
README.md17.2 KB9fc24ad706c6aa1ff8cdaf0b36c6dc328367371282d79beef7c9c61f90a26d1e
assets/BEIR-bge-en-v1.5.png56.4 KBc1e57bfc0bb87408ac0d5084acce36a26914a2ea19f2f9f3560e71be9d4daef6
assets/BEIR-e5-mistral.png40.2 KB5119f2d1b364f79eaa2954bd5efb4a7e56364ee8748571964d800f85683280c4
assets/CMTEB-retrieval-bge-zh-v1.5.png51.5 KBce02a58c566da5f733b6928cc968865e4d472c8a276546bfce5d0f4452050ed4
assets/llama-index.png106 KB62c4fbdeeb44296da80bdd2f0a7a6b5e44f3492072af84fdf3ed99d01a53e596
assets/miracl-bge-m3.png52.0 KB98f40bf0ba104f3efa52ef76da1434fb776834cdc732e6b29d2550672ea2df1b
config.json1.18 KB1d0bc85dc75d4400fdfb04360777700e47514f24213192d8839d1b12f115d016
configuration_minicpm_reranker.py9.97 KBc99d026cce2e4253aaea859c49f55f1a38645496535d74db63aa8d2a66d0bae0
generation_config.json140 Bc94220480deccef26f27b2fd238458691fd8057a2bb92240b44cf13da67243a5
model-00001-of-00003.safetensors4.99 GBe2bd6342e253cce7debf1efd1b5813011fd79cce0c6528fd8d6d7d2b20f549ee
model-00002-of-00003.safetensors4.98 GB568f1cc88ffbc58516066cf49dcc8aca39a6e6dae1b771a771b58a1bdcfda154
model-00003-of-00003.safetensors935 MB4a8921a5c38d777e6cd6ccf5e92015c18ef50d5d31f65d7ba8a3a64280a894a2
model.safetensors.index.json32.2 KB4516cb8b99e0b84b3b12e669e2595b116f8f377b123a25c36362324156b9a83c
modeling_minicpm_reranker.py72.5 KBdbe978b271e0e05ba79dfd9e53811f7b2320cfd20b820954e2cde3bc3ff9473c
special_tokens_map.json552 B4859e5dbde90e059988a0a2136d8df3f2773d4d2fc4c4543690028f0b2166e7f
tokenizer.json6.20 MB42f73d01995bd71c88647b13ac696b36d84d5126d0c7cbaef6f8d872d5c97dff
tokenizer.model1.99 MBc9aafcd7da1f5611dab6be545db74d5552a2ccc9c2a12c72ea7be63aac4a25d7
tokenizer_config.json1.14 KBed90231596fa3476f3df3b90e115152ce465bac2ba15d3ada9925d43be1acda3
VersionsEach time the pinned upstream commit or file list changed in this repo. Newest first.
Upstream commitDateContents
47b5332b29 pinned now manifest updated, same commit2026-11-14 21:08 UTC19 files · 10.9 GB
47b5332b292026-11-14 21:08 UTC19 files · 10.9 GB

Use it

$ fw get BAAI/bge-reranker-v2-minicpm-layerwise
# manifest sha256 ffc29ee28431… · 10.9 GB · 19 files
$ fw verify ./bge-reranker-v2-minicpm-layerwise BAAI/bge-reranker-v2-minicpm-layerwise
fw.pyChecks the signature and every sha256, tries each source in order, resumes.
$ python3 fw.py get https://freeweights.allternit.com/manifests/BAAI/bge-reranker-v2-minicpm-layerwise.json --dir ./bge-reranker-v2-minicpm-layerwise $ python3 fw.py verify ./bge-reranker-v2-minicpm-layerwise ./BAAI__bge-reranker-v2-minicpm-layerwise.json
hfThe Hugging Face CLI with one setting. Same repo id.
$ HF_ENDPOINT=https://freeweights.allternit.com hf download BAAI/bge-reranker-v2-minicpm-layerwise --revision 47b5332b296c4d8cb6ee2c60502cc62a0d708881 --local-dir ./bge-reranker-v2-minicpm-layerwise

License

Name
Apache License 2.0
Id
Apache-2.0
Class
Permissive
Redistribution
yes
Listing
Hosted (signed)
Decided
License as declared by the publisher. No person read it. 2026-11-14
Text in
README.md
Text sha256
9fc24ad706c6aa1ff8cdaf0b36c6dc328367371282d79beef7c9c61f90a26d1e
Terms gate
No extra terms beyond the license.

Read the license text

Licenses are checked against the license table. A custom license passes only after a person reads it.

Provenance

From: BAAI <huggingface.co/BAAI>Newsgroups: alt.freeweights.embedSubject: bge-reranker-v2-minicpm-layerwiseDate: 2026-11-14Commit: 47b5332Signed: 2DC28CC7B26A283B ✓
Upstream
BAAI/bge-reranker-v2-minicpm-layerwise
Pinned commit
47b5332b296c4d8cb6ee2c60502cc62a0d708881
Manifest
bge-reranker-v2-minicpm-layerwise.json · .minisig
Manifest sha256
ffc29ee28431cf75198f8635a8844131e0c6a4b9d5fff824b198a70083792fc8
Signature
minisign, Ed25519, key 2DC28CC7B26A283B
Created
2026-11-14 21:08 UTC
Generator
freeweights-manifest/0.1.0
Takedowns
None.

How to verify

$ curl -O https://freeweights.allternit.com/manifests/BAAI/bge-reranker-v2-minicpm-layerwise.json $ curl -O https://freeweights.allternit.com/manifests/BAAI/bge-reranker-v2-minicpm-layerwise.json.minisig $ minisign -Vm bge-reranker-v2-minicpm-layerwise.json -P RWQ7KGqyx4zCLXtUFOqvfv8L3g+8fpKJ1FsuxPyOYMF+4KufbUxKq1Oq $ shasum -a 256 <file> # compare with the Files tab

A manifest whose signature fails must be rejected. A file whose size or sha256 does not match must be discarded. Verify a download

Model tree

No related models in this catalog.Nothing here lists this model as its parent, and it names no parent.
Get it
Download
$ HF_ENDPOINT=https://freeweights.allternit.com hf download BAAI/bge-reranker-v2-minicpm-layerwise
Open in Freeweights Studio

Pull, verify and run it in the Allternit app on Desktop, web or phone.

Signed manifest
minisign, key 2DC28CC7B26A283B. bge-reranker-v2-minicpm-layerwise.json. Provenance. Takedown history: none.
From: sentence-transformers <huggingface.co/sentence-transformers>Subject: all-MiniLM-L6-v1
From: unsloth <huggingface.co/unsloth>Subject: all-MiniLM-L6-v2
From: mlx-community <huggingface.co/mlx-community>Subject: all-MiniLM-L6-v2-4bit
From: sentence-transformers <huggingface.co/sentence-transformers>Subject: all-mpnet-base-v1
From: sentence-transformers <huggingface.co/sentence-transformers>Subject: allenai-specter
From: sentence-transformers <huggingface.co/sentence-transformers>Subject: bert-base-nli-max-tokens