File size: 1,032 Bytes
f11912b
f68327f
 
 
f11912b
4f7df78
f68327f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import streamlit as st
from sklearn.metrics.pairwise import cosine_similarity
import numpy as np
from sentence_transformers import SentenceTransformer

def app():
    st.title("Text Similarity")
    
    model = SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2")
    
    with st.container():
        col1, col2 = st.columns(2)
        with col1:
            word_to_embed1 = st.text_input("Text 1", value="",)
        with col2:                                 
            word_to_embed2 = st.text_input("Text 2", value="",)
            
    if st.button("Embed"):
        with st.spinner("Embedding comparing  your inputs"):
            
        document = [word_to_embed1 ,word_to_embed2]
        #Encode paragraphs
        document_embeddings = model.encode(document, show_progress_bar=False)
        #Compute cosine similarity between labels sentences and paragraphs
        similarity_matrix = cosine_similarity(label_embeddings, document_embeddings)
        
        st.write("Text similarity:" similarity_matrix)