🚀 🇸🇦 阿拉伯語 - 英語 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 許可證。