pipeline_tag: 句子相似度
language:
- 阿拉伯语
- 英语
license: mit
tags:
- 段落检索
- 句子相似度
- 剪枝版
library_name: sentence-transformers
base_model: BAAI/bge-m3
base_model_relation: 量化版
🇸🇦 阿拉伯语-英语-bge-m3模型
该模型是BAAI/bge-m3针对阿拉伯语的36.2%精简版本。
ONNX量化版比剪枝模型缩小约75%(363MB),同时保留原模型约98%的质量。
该剪枝模型在阿拉伯语任务上表现应与原模型相当,但内存占用更小。不过由于移除了原多语言模型中阿拉伯语不常用的词汇,可能对其他语言任务表现不佳。
使用方法
可通过Transformers库使用:
from transformers import AutoModel, AutoTokenizer
model_name = "sayed0am/arabic-english-bge-m3"
model = AutoModel.from_pretrained(model_name, trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True, use_fast=True)
或通过sentence-transformers库:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("sayed0am/arabic-english-bge-m3")
使用ONNX版本
from huggingface_hub import snapshot_download
snapshot_download(repo_id="sayed0am/arabic-english-bge-m3",local_dir="arabic-english-bge-m3")
from optimum.onnxruntime import ORTModelForFeatureExtraction
from transformers import AutoTokenizer
import torch
model = ORTModelForFeatureExtraction.from_pretrained("arabic-english-bge-m3", subfolder="onnx", provider="CUDAExecutionProvider")
tokenizer = AutoTokenizer.from_pretrained("arabic-english-bge-m3")
sentences = [
"英语:敏捷的棕色狐狸跳过了懒惰的狗",
"阿拉伯语:الثعلب البني السريع يقفز فوق الكلب الكسول."
]
encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt').to("cuda")
out=model(**encoded_input,return_dict=True).last_hidden_state
dense_vecs = torch.nn.functional.normalize(out[:, 0], dim=-1)