đ Bangla Sentence Transformer
Sentence Transformer is a state-of-the-art natural language processing (NLP) model that can encode and transform sentences into high-dimensional embeddings. This technology enables powerful insights and applications in various fields such as text classification, information retrieval, and semantic search.
This model is fine-tuned from stsb-xlm-r-multilingual
and is now available on Hugging Face! đđ
đ Quick Start
⨠Features
- Supports multiple languages including Bengali (bn) and English (en).
- Suitable for the task of sentence similarity.
- Based on sentence-transformers technology for feature extraction.
đĻ Installation
Using this model becomes easy when you have sentence-transformers installed:
pip install -U sentence-transformers
đģ Usage Examples
Basic Usage
from sentence_transformers import SentenceTransformer
sentences = ['āĻāĻŽāĻŋ āĻāĻĒā§āϞ āĻā§āϤ⧠āĻĒāĻāύā§āĻĻ āĻāϰāĻŋāĨ¤ ', 'āĻāĻŽāĻžāϰ āĻāĻāĻāĻŋ āĻāĻĒā§āϞ āĻŽā§āĻŦāĻžāĻāϞ āĻāĻā§āĨ¤','āĻāĻĒāύāĻŋ āĻāĻŋ āĻāĻāĻžāύ⧠āĻāĻžāĻāĻžāĻāĻžāĻāĻŋ āĻĨāĻžāĻā§āύ?', 'āĻāĻļā§āĻĒāĻžāĻļā§ āĻā§āĻ āĻāĻā§āύ?']
model = SentenceTransformer('shihab17/bangla-sentence-transformer')
embeddings = model.encode(sentences)
print(embeddings)
Advanced Usage
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 = ['āĻāĻŽāĻŋ āĻāĻĒā§āϞ āĻā§āϤ⧠āĻĒāĻāύā§āĻĻ āĻāϰāĻŋāĨ¤ ', 'āĻāĻŽāĻžāϰ āĻāĻāĻāĻŋ āĻāĻĒā§āϞ āĻŽā§āĻŦāĻžāĻāϞ āĻāĻā§āĨ¤','āĻāĻĒāύāĻŋ āĻāĻŋ āĻāĻāĻžāύ⧠āĻāĻžāĻāĻžāĻāĻžāĻāĻŋ āĻĨāĻžāĻā§āύ?', 'āĻāĻļā§āĻĒāĻžāĻļā§ āĻā§āĻ āĻāĻā§āύ?']
tokenizer = AutoTokenizer.from_pretrained('shihab17/bangla-sentence-transformer')
model = AutoModel.from_pretrained('shihab17/bangla-sentence-transformer')
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)
Calculating Sentence Similarity
from sentence_transformers import SentenceTransformer
from sentence_transformers.util import pytorch_cos_sim
transformer = SentenceTransformer('shihab17/bangla-sentence-transformer')
sentences = ['āĻāĻŽāĻŋ āĻāĻĒā§āϞ āĻā§āϤ⧠āĻĒāĻāύā§āĻĻ āĻāϰāĻŋāĨ¤ ', 'āĻāĻŽāĻžāϰ āĻāĻāĻāĻŋ āĻāĻĒā§āϞ āĻŽā§āĻŦāĻžāĻāϞ āĻāĻā§āĨ¤','āĻāĻĒāύāĻŋ āĻāĻŋ āĻāĻāĻžāύ⧠āĻāĻžāĻāĻžāĻāĻžāĻāĻŋ āĻĨāĻžāĻā§āύ?', 'āĻāĻļā§āĻĒāĻžāĻļā§ āĻā§āĻ āĻāĻā§āύ?']
sentences_embeddings = transformer.encode(sentences)
for i in range(len(sentences)):
for j in range(i, len(sentences)):
sen_1 = sentences[i]
sen_2 = sentences[j]
sim_score = float(pytorch_cos_sim(sentences_embeddings[i], sentences_embeddings[j]))
print(sen_1, '----->', sen_2, sim_score)
đ Documentation
Best MSE: 2.5556
đ License
No license information provided in the original document.
đ Citation
If you use this model, please cite the following paper:
@INPROCEEDINGS{10754765,
author={Uddin, Md. Shihab and Haque, Mohd Ariful and Rifat, Rakib Hossain and Kamal, Marufa and Gupta, Kishor Datta and George, Roy},
booktitle={2024 IEEE 15th Annual Ubiquitous Computing, Electronics & Mobile Communication Conference (UEMCON)},
title={Bangla SBERT - Sentence Embedding Using Multilingual Knowledge Distillation},
year={2024},
volume={},
number={},
pages={495-500},
keywords={Sentiment analysis;Machine learning algorithms;Accuracy;Text categorization;Semantics;Transformers;Mobile communication;Information retrieval;Machine translation;Sentence Similarity;Sentence Transformer;SBERT;Knowledge Distillation;Bangla NLP},
doi={10.1109/UEMCON62879.2024.10754765}}