File size: 710 Bytes
514343b
 
843aeb0
 
9983408
 
843aeb0
9983408
 
 
 
 
 
 
27c1d2e
9983408
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

import streamlit as st
from transformers import pipeline
from textblob import TextBlob
from sentence_transformers import SentenceTransformer
from sklearn.metrics.pairwise import cosine_similarity

sentences = \
    [
     "I have a bigger house than you", 
     "You have a bigger house than me"
     ]
     
sentence_embeddings = model.encode(sentences)

for sentence, embedding in zip(sentences, sentence_embeddings):
    print("Sentence:", sentence)
    print("Embedding:", embedding)
    print("")
    
print('Similarity between {} and {} is {}'.format(sentences[0],
       sentences[1],
       cosine_similarity(sentence_embeddings[0].reshape(1, -1),
       sentence_embeddings[1].reshape(1, -1))[0][0]))