In this video, I show you how to use SBERT (Sentence-BERT) to calculate sentence similarity in Python using the built-in similarity function.
We will:
✔ Load the SBERT model (all-MiniLM-L6-v2)
✔ Encode sentences into embeddings
✔ Calculate similarity between sentences
Code used in the video:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer('all-MiniLM-L6-v2')
sentences = [
'I love data science',
'I enjoy machine learning',
'I wanna be data analysis',
'I love playing game'
]
emb = model.encode(sentences, convert_to_tensor=True)
similarity = model.similarity(emb, emb)
print(similarity)
If you want more NLP tutorials like this, don’t forget to LIKE & SUBSCRIBE!
#datatypes #astypepython #pandasastype #roundfunction #dropduplicates #pythontutorial #datascience #pandastutorial #typeconversion #datapreprocessing #pythonprogramming #learnpython #dataanalysis #pandasdataframe #pythonforbeginners #codingtutorial #datawrangling #pythondatascience #dataquality #duplicateremoval #decimalrounding #datatypeconversionsentence #similarity #SBERT #SentenceTransformer #embeddings #NLP #Python #data science #machine learning #BERT #text similarity #AI