🚀 🇸🇦 阿拉伯语 - 英语 bge - m3
本模型是 [BAAI/bge - m3](https://huggingface.co/BAAI/bge - m3) 的精简版本,专为阿拉伯语设计,模型体积缩小了 36.2%。
其 ONNX 量化版本相较于剪枝后的模型,体积大约缩小了 75%(仅 363 MB),同时还保留了原模型约 98% 的性能。
在处理阿拉伯语任务时,这个剪枝后的模型与原模型表现相近,但内存占用要小得多。不过,由于原多语言模型词汇表中移除了阿拉伯语里不常用的标记,该模型在处理原多语言模型所支持的其他语言时,表现可能不佳。
🚀 快速开始
本模型可通过以下方式使用:
✨ 主要特性
- 专为阿拉伯语优化,在阿拉伯语任务上与原模型性能相近,但体积显著缩小。
- ONNX 量化版本体积更小,且能保留较高的性能。
📦 安装指南
使用此模型前,需安装相应的库,如 transformers
、sentence - transformers
、huggingface - hub
、optimum
等。可以使用以下命令进行安装:
pip install transformers sentence-transformers huggingface-hub optimum onnxruntime
💻 使用示例
基础用法
你可以使用 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 = [
"English: The quick brown fox jumps over the lazy dog.",
"Arabic: الثعلب البني السريع يقفز فوق الكلب الكسول."
]
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)
📄 许可证
本模型采用 MIT 许可证。