Views
No views yet
@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}
}pip install -U sentence-transformers1from sentence_transformers import SentenceTransformer
2sentences = ["This is an example sentence", "Each sentence is converted"]
3
4model = SentenceTransformer('{MODEL_NAME}')
5embeddings = model.encode(sentences)
6print(embeddings)1from transformers import AutoTokenizer, AutoModel
2import torch
3
4
5def cls_pooling(model_output, attention_mask):
6 return model_output[0][:,0]
7
8
9# Sentences we want sentence embeddings for
10sentences = ['This is an example sentence', 'Each sentence is converted']
11
12# Load model from HuggingFace Hub
13tokenizer = AutoTokenizer.from_pretrained('{MODEL_NAME}')
14model = AutoModel.from_pretrained('{MODEL_NAME}')
15
16# Tokenize sentences
17encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
18
19# Compute token embeddings
20with torch.no_grad():
21 model_output = model(**encoded_input)
22
23# Perform pooling. In this case, cls pooling.
24sentence_embeddings = cls_pooling(model_output, encoded_input['attention_mask'])
25
26print("Sentence embeddings:")
27print(sentence_embeddings)