license: apache-2.0
pipeline_tag: text-ranking
tags:
- transformers
- sentence-transformers
- text-embeddings-inference
language:
- ko
- multilingual
library_name: sentence-transformers
upskyy/ko-reranker-8k
ko-reranker-8k是基于BAAI/bge-reranker-v2-m3模型,使用韩语数据进行微调后的版本。
使用方法
使用FlagEmbedding库
pip install -U FlagEmbedding
获取相关性分数(分数越高表示相关性越强):
from FlagEmbedding import FlagReranker
reranker = FlagReranker('upskyy/ko-reranker-8k', use_fp16=True)
score = reranker.compute_score(['查询语句', '文本段落'])
print(score)
score = reranker.compute_score(['查询语句', '文本段落'], normalize=True)
print(score)
scores = reranker.compute_score([['熊猫是什么?', '嗨'], ['熊猫是什么?', '大熊猫(学名:Ailuropoda melanoleuca),有时被称为熊猫熊或简称熊猫,是中国特有的熊科动物。']])
print(scores)
scores = reranker.compute_score([['熊猫是什么?', '嗨'], ['熊猫是什么?', '大熊猫(学名:Ailuropoda melanoleuca),有时被称为熊猫熊或简称熊猫,是中国特有的熊科动物。']], normalize=True)
print(scores)
使用Huggingface transformers库
获取相关性分数:
import torch
from transformers import AutoModelForSequenceClassification, AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained('upskyy/ko-reranker-8k')
model = AutoModelForSequenceClassification.from_pretrained('upskyy/ko-reranker-8k')
model.eval()
pairs = [['熊猫是什么?', '嗨'], ['熊猫是什么?', '大熊猫(学名:Ailuropoda melanoleuca),有时被称为熊猫熊或简称熊猫,是中国特有的熊科动物。']]
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)
引用文献
@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}
}
参考文献