🚀 MahaSBERT
MahaSBERT 是一個基於 MahaBERT 模型(l3cube - pune/marathi - bert - v2)在 NLI 數據集上訓練得到的模型。它是 MahaNLP 項目的一部分,項目鏈接:https://github.com/l3cube - pune/MarathiNLP 。此外,還有一個支持主要印度語言和跨語言能力的多語言版本模型,可查看: indic - sentence - bert - nli 。同時,一個效果更好的句子相似度模型(此模型的微調版本)可在以下鏈接查看:https://huggingface.co/l3cube - pune/marathi - sentence - similarity - sbert 。
🚀 快速開始
本模型可用於將句子和段落映射到 768 維的密集向量空間,適用於聚類或語義搜索等任務。
✨ 主要特性
- 基於 MahaBERT 模型在 NLI 數據集上訓練,具有良好的句子相似度計算能力。
- 有單語言和多語言版本可供選擇。
📦 安裝指南
若要使用此模型,需安裝 sentence - transformers:
pip install -U sentence-transformers
💻 使用示例
基礎用法(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)
若未安裝 sentence - transformers,可按以下方式使用模型:首先將輸入數據傳入 Transformer 模型,然後對上下文詞嵌入應用合適的池化操作。
from transformers import AutoTokenizer, AutoModel
import torch
def cls_pooling(model_output, attention_mask):
return model_output[0][:,0]
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 = cls_pooling(model_output, encoded_input['attention_mask'])
print("Sentence embeddings:")
print(sentence_embeddings)
📚 詳細文檔
更多關於數據集、模型和基線結果的詳細信息可查看我們的 論文 :
@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。
🔍 示例展示
以下是一些使用示例:
示例 1
- 源句子:"शेतकऱ्यांचे डोळे आकाशाकडे लागले आहेत"
- 對比句子:
- "आता शेतकऱ्यांचे डोळे आभाळाकडे लागले आहेत"
- "अन्नधान्य उत्पादनासाठी शेतकरी कष्ट करतात"
- "शहरात कचऱ्याचे ढीग दिसतात"
示例 2
- 源句子:"घटनेची माहिती मिळताच पोलिसांचा ताफा तेथे पोहोचला"
- 對比句子:
- "पोलिसांना घटनेची माहिती मिळताच त्यांचे पथक घटनास्थळी पोहोचले"
- "तेव्हा पोलिसांनी त्यांच्या तक्रारीची दखल घेतली नाही"
- "दिवसाचा उत्तरार्ध कुटुंबासोबत मौजमजेत घालवाल"
示例 3
- 源句子:"पहिल्या पाच किलोमीटर अंतरासाठी पाच रुपये दर आकारण्यात येत आहे"
- 對比句子:
- "पाच रुपयांत पाच किमी प्रवास करा"
- "दोन ठिकाणांमधले मोठे अंतर प्रवास करणे कंटाळवाणे आहे"
- "नुकत्याच झालेल्या पावसामुळे हिरवळ दिसत आहे"