🚀 SA-BERT-V1:沙特方言词嵌入模型
SA-BERT-V1 是一款专门为沙特方言设计的词嵌入模型,基于预训练模型进行微调,能够有效处理沙特方言相关的语义相似性、聚类、检索和分类等任务。
📚 详细文档
模型信息
属性 |
详情 |
微调模型 ID |
Omartificial-Intelligence-Space/SA-BERT-V1 |
许可证 |
Apache 2.0 |
适用范围 |
沙特方言 |
模型类型 |
句子嵌入(采用均值池化的 BERT 编码器) |
架构 |
12 层 Transformer,768 维隐藏状态 |
嵌入大小 |
768 |
预训练模型 |
UBC-NLP/MARBERTv2 |
微调数据 |
超过 50 万条涵盖不同主题和地区变体(希贾兹、内志等)的沙特方言句子 |
支持语言 |
阿拉伯语(沙特方言) |
预期任务 |
语义相似性、聚类、检索、下游分类 |
模型优势
SA-BERT-V1 在沙特方言理解方面表现卓越,在 44 个专业类别中,内部与跨类别相似度差距达到 +0.0022,平均余弦相似度得分达到 0.98,为阿拉伯方言句子嵌入树立了新的标准。
- 相似度差距:SA-BERT-V1 呈现出正向的内部与跨类别差距和较高的绝对相似度,证明了针对沙特方言进行微调的有效性。
- 内部与跨类别相似度:两者均接近 0.98,且存在轻微的正向差距(+0.0023),这意味着同一主题的嵌入向量更为接近。
- 性能表现:在沙特方言聚类任务中表现出色,非常适合检索或分组任务。
评估信息
评估是在一个包含 1280 条沙特方言句子、涵盖 44 个不同类别的测试集上进行的(例如问候语、天气、法律与正义等)。数据集由该项目创建并发布,用于评估词嵌入模型,通过从数据集中采样类别内和跨类别对来计算以下指标:
- 平均类别内/跨类别余弦相似度
- 前 5 个最相似/最不相似的对
- 每个类别的平均相似度
测试样本访问
沙特方言测试样本
💻 使用示例
基础用法
import torch
from transformers import AutoTokenizer, AutoModel
MODEL_ID = "Omartificial-Intelligence-Space/SA-BERT-V1"
DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID , token= "PASS_READ_TOKEN_HERE")
model = AutoModel.from_pretrained(MODEL_ID , token = "PASS_READ_TOKEN_HERE").to(DEVICE).eval()
def embed_sentence(text: str) -> torch.Tensor:
"""
Tokenizes `text`, feeds it through SA-BERT-V1, and returns
a 768-dimensional mean-pooled sentence embedding.
"""
enc = tokenizer(
text,
truncation=True,
padding="max_length",
max_length=256,
return_tensors="pt"
).to(DEVICE)
with torch.no_grad():
outputs = model(**enc).last_hidden_state
mask = enc["attention_mask"].unsqueeze(-1)
summed = (outputs * mask).sum(dim=1)
counts = mask.sum(dim=1).clamp(min=1e-9)
embedding = summed / counts
return embedding.squeeze(0)
if __name__ == "__main__":
sentences = [
"شتبي من البقالة؟",
"كيف حالك؟",
"وش رايك في الموضوع هذا؟"
]
for s in sentences:
vec = embed_sentence(s)
print(f"Sentence: {s}\nEmbedding shape: {vec.shape}\n")
📄 许可证
本模型采用 Apache 2.0 许可证。
📖 引用
如果您在研究或应用中使用了 MarBERTv2-SA,请引用以下文献:
@misc{nacar2025SABERTV1,
title={SA-BERT-V1: Fine-Tuned Saudi-Dialect Embeddings},
author={Nacar, Omer & Sibaee, Serry},
year={2025},
publisher={Omartificial-Intelligence-Space},
howpublished={\url{https://huggingface.co/Omartificial-Intelligence-Space/SA-BERT-V1}},
}
@inproceedings{abdul-mageed-etal-2021-arbert,
title = "{ARBERT} {\&} {MARBERT}: Deep Bidirectional Transformers for {A}rabic",
author = "Abdul-Mageed, Muhammad and Elmadany, AbdelRahim and Nagoudi, El Moatez Billah",
booktitle = "Proceedings of the 59th Annual Meeting of the Association for Computational Linguistics and the 11th International Joint Conference on Natural Language Processing (Volume 1: Long Papers)",
year = "2021",
publisher = "Association for Computational Linguistics",
pages = "7088--7105",
}