Views
No views yet
pip install -U FlagEmbedding1from FlagEmbedding import FlagReranker
2
3
4reranker = FlagReranker('upskyy/ko-reranker-8k', use_fp16=True) # Setting use_fp16 to True speeds up computation with a slight performance degradation
5
6score = reranker.compute_score(['query', 'passage'])
7print(score) # -8.3828125
8
9# You can map the scores into 0-1 by set "normalize=True", which will apply sigmoid function to the score
10score = reranker.compute_score(['query', 'passage'], normalize=True)
11print(score) # 0.000228713314721116
12
13scores = 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.']])
14print(scores) # [-11.2265625, 8.6875]
15
16# You can map the scores into 0-1 by set "normalize=True", which will apply sigmoid function to the score
17scores = 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)
18print(scores) # [1.3315579521758342e-05, 0.9998313472460109]1import torch
2from transformers import AutoModelForSequenceClassification, AutoTokenizer
3
4
5tokenizer = AutoTokenizer.from_pretrained('upskyy/ko-reranker-8k')
6model = AutoModelForSequenceClassification.from_pretrained('upskyy/ko-reranker-8k')
7model.eval()
8
9pairs = [['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.']]
10with torch.no_grad():
11 inputs = tokenizer(pairs, padding=True, truncation=True, return_tensors='pt', max_length=512)
12 scores = model(**inputs, return_dict=True).logits.view(-1, ).float()
13 print(scores)1@misc{li2023making,
2 title={Making Large Language Models A Better Foundation For Dense Retrieval},
3 author={Chaofan Li and Zheng Liu and Shitao Xiao and Yingxia Shao},
4 year={2023},
5 eprint={2312.15503},
6 archivePrefix={arXiv},
7 primaryClass={cs.CL}
8}
9@misc{chen2024bge,
10 title={BGE M3-Embedding: Multi-Lingual, Multi-Functionality, Multi-Granularity Text Embeddings Through Self-Knowledge Distillation},
11 author={Jianlv Chen and Shitao Xiao and Peitian Zhang and Kun Luo and Defu Lian and Zheng Liu},
12 year={2024},
13 eprint={2402.03216},
14 archivePrefix={arXiv},
15 primaryClass={cs.CL}
16}