colabbear/bge-reranker-v2-m3-ko-bnb-4bit
dragonkue/bge-reranker-v2-m3-ko (Quantized)
Description
This model is a quantized version of the original model `dragonkue/bge-reranker-v2-m3-ko`.
It's quantized using the BitsAndBytes library to 4-bit using the bnb-my-repo space.
Quantization Details
- Quantization Type: int4
- bnb_4bit_quant_type: nf4
- bnb_4bit_use_double_quant: True
- bnb_4bit_compute_dtype: bfloat16
- bnb_4bit_quant_storage: uint8
📄 Original Model Information
<img src="https://cdn-uploads.huggingface.co/production/uploads/642b0c2fecec03b4464a1d9b/IxcqY5qbGNuGpqDciIcOI.webp" width="600">
Reranker (Cross-Encoder)
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 Details
- Base model : BAAI/bge-reranker-v2-m3
- The multilingual model has been optimized for Korean.
Usage with Transformers
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
model = AutoModelForSequenceClassification.from_pretrained('dragonkue/bge-reranker-v2-m3-ko')
tokenizer = AutoTokenizer.from_pretrained('dragonkue/bge-reranker-v2-m3-ko')
features = tokenizer([['몇 년도에 지방세외수입법이 시행됐을까?', '실무교육을 통해 ‘지방세외수입법’에 대한 자치단체의 관심을 제고하고 자치단체의 차질 없는 업무 추진을 지원하였다. 이러한 준비과정을 거쳐 2014년 8월 7일부터 ‘지방세외수입법’이 시행되었다.'],
['몇 년도에 지방세외수입법이 시행됐을까?', '식품의약품안전처는 21일 국내 제약기업 유바이오로직스가 개발 중인 신종 코로나바이러스 감염증(코로나19) 백신 후보물질 ‘유코백-19’의 임상시험 계획을 지난 20일 승인했다고 밝혔다.']], padding=True, truncation=True, return_tensors="pt")
model.eval()
with torch.no_grad():
logits = model(**features).logits
scores = torch.sigmoid(logits)
print(scores)
# [9.9997962e-01 5.0702977e-07]Usage with SentenceTransformers
First install the Sentence Transformers library:
pip install -U sentence-transformersfrom sentence_transformers import CrossEncoder
model = CrossEncoder('dragonkue/bge-reranker-v2-m3-ko', default_activation_function=torch.nn.Sigmoid())
scores = model.predict([['몇 년도에 지방세외수입법이 시행됐을까?', '실무교육을 통해 ‘지방세외수입법’에 대한 자치단체의 관심을 제고하고 자치단체의 차질 없는 업무 추진을 지원하였다. 이러한 준비과정을 거쳐 2014년 8월 7일부터 ‘지방세외수입법’이 시행되었다.'],
['몇 년도에 지방세외수입법이 시행됐을까?', '식품의약품안전처는 21일 국내 제약기업 유바이오로직스가 개발 중인 신종 코로나바이러스 감염증(코로나19) 백신 후보물질 ‘유코백-19’의 임상시험 계획을 지난 20일 승인했다고 밝혔다.']])
print(scores)
# [9.9997962e-01 5.0702977e-07]Usage with FlagEmbedding
First install the FlagEmbedding library:
pip install -U FlagEmbeddingfrom FlagEmbedding import FlagReranker
reranker = FlagReranker('dragonkue/bge-reranker-v2-m3-ko')
scores = reranker.compute_score([['몇 년도에 지방세외수입법이 시행됐을까?', '실무교육을 통해 ‘지방세외수입법’에 대한 자치단체의 관심을 제고하고 자치단체의 차질 없는 업무 추진을 지원하였다. 이러한 준비과정을 거쳐 2014년 8월 7일부터 ‘지방세외수입법’이 시행되었다.'],
['몇 년도에 지방세외수입법이 시행됐을까?', '식품의약품안전처는 21일 국내 제약기업 유바이오로직스가 개발 중인 신종 코로나바이러스 감염증(코로나19) 백신 후보물질 ‘유코백-19’의 임상시험 계획을 지난 20일 승인했다고 밝혔다.']], normalize=True)
print(scores)
# [9.9997962e-01 5.0702977e-07]Fine-tune
Refer to https://github.com/FlagOpen/FlagEmbedding
Evaluation
Bi-encoder and Cross-encoder
Bi-Encoders convert texts into fixed-size vectors and efficiently calculate similarities between them. They are fast and ideal for tasks like semantic search and classification, making them suitable for processing large datasets quickly.
Cross-Encoders directly compare pairs of texts to compute similarity scores, providing more accurate results. While they are slower due to needing to process each pair, they excel in re-ranking top results and are important in Advanced RAG techniques for enhancing text generation.
Korean Embedding Benchmark with AutoRAG
(https://github.com/Marker-Inc-Korea/AutoRAG-example-korean-embedding-benchmark)
This is a Korean embedding benchmark for the financial sector.
Top-k 1
Bi-Encoder (Sentence Transformer)
Cross-Encoder (Reranker)
Top-k 3
Bi-Encoder (Sentence Transformer)
Cross-Encoder (Reranker)
