🚀 MalayalamSBERT
MalayalamSBERT是一个基于马拉雅拉姆语的模型,它在NLI数据集上对MalayalamBERT模型(l3cube - pune/malayalam - bert)进行了训练。该模型作为MahaNLP项目的一部分发布,能有效处理句子相似度任务,为马拉雅拉姆语的语义理解提供支持。
🚀 快速开始
本模型可以通过两种方式使用,分别是借助sentence - transformers
库和HuggingFace Transformers
库。下面为你详细介绍使用方法。
📦 安装指南
若要使用sentence - transformers
库来调用本模型,你需要先安装它:
pip install -U sentence-transformers
💻 使用示例
基础用法
使用sentence - transformers库
from sentence_transformers import SentenceTransformer
sentences = ["This is an example sentence", "Each sentence is converted"]
model = SentenceTransformer('{MODEL_NAME}')
embeddings = model.encode(sentences)
print(embeddings)
使用HuggingFace Transformers库
from transformers import AutoTokenizer, AutoModel
import torch
def mean_pooling(model_output, attention_mask):
token_embeddings = model_output[0]
input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
sentences = ['This is an example sentence', 'Each sentence is converted']
tokenizer = AutoTokenizer.from_pretrained('{MODEL_NAME}')
model = AutoModel.from_pretrained('{MODEL_NAME}')
encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
with torch.no_grad():
model_output = model(**encoded_input)
sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
print("Sentence embeddings:")
print(sentence_embeddings)
📚 详细文档
- 本模型作为MahaNLP项目的一部分发布,项目链接:https://github.com/l3cube - pune/MarathiNLP
- 支持主要印度语言和跨语言能力的多语言版本模型: indic - sentence - bert - nli
- 一个更好的句子相似度模型(本模型的微调版本):https://huggingface.co/l3cube - pune/malayalam - sentence - similarity - sbert
- 关于数据集、模型和基线结果的更多详细信息可在我们的论文中找到。
引用信息
@article{deode2023l3cube,
title={L3Cube-IndicSBERT: A simple approach for learning cross-lingual sentence representations using multilingual BERT},
author={Deode, Samruddhi and Gadre, Janhavi and Kajale, Aditi and Joshi, Ananya and Joshi, Raviraj},
journal={arXiv preprint arXiv:2304.11434},
year={2023}
}
@article{joshi2022l3cubemahasbert,
title={L3Cube-MahaSBERT and HindSBERT: Sentence BERT Models and Benchmarking BERT Sentence Representations for Hindi and Marathi},
author={Joshi, Ananya and Kajale, Aditi and Gadre, Janhavi and Deode, Samruddhi and Joshi, Raviraj},
journal={arXiv preprint arXiv:2211.11187},
year={2022}
}
相关论文链接
其他单语言印度句子BERT模型
其他单语言相似度模型
📄 许可证
本模型采用CC - BY - 4.0许可证。