Views
No views yet
git clone https://github.com/FlagOpen/FlagEmbedding.git
cd ./FlagEmbedding/research/Matroyshka_reranker1from rank_model import MatroyshkaReranker
2
3compress_ratio = 2 # config your compress ratio
4compress_layers = [8, 16] # cofig your layers to compress
5cutoff_layers = [20, 24] # config your layers to output
6
7reranker = MatroyshkaReranker(
8 model_name_or_path='BAAI/Matroyshka-ReRanker-passage',
9 peft_path=[
10 './models/Matroyshka-ReRanker-passage/compensate/layer/full'
11 ]
12 use_fp16=True,
13 cache_dir='./model_cache',
14 compress_ratio=compress_ratio,
15 compress_layers=compress_layers,
16 cutoff_layers=cutoff_layers
17)
18
19score = reranker.compute_score(['query', 'passage'])
20print(score)
21
22scores = 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.']])
23print(scores)1@inproceedings{liu2025fitting,
2 title={Fitting Into Any Shape: A Flexible LLM-Based Re-Ranker With Configurable Depth and Width},
3 author={Liu, Zheng and Li, Chaofan and Xiao, Shitao and Li, Chaozhuo and Zhang, Chen Jason and Liao, Hao and Lian, Defu and Shao, Yingxia},
4 booktitle={Proceedings of the ACM on Web Conference 2025},
5 pages={3942--3951},
6 year={2025}
7}