File size: 2,127 Bytes
f611e6b
98740a5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f611e6b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""import gradio as gr
from sentence_transformers import SentenceTransformer, util

i18n_model = SentenceTransformer('distiluse-base-multilingual-cased-v2')

def inference(s1:str, s2:str):
    score = util.cos_sim(i18n_model.encode(s1), i18n_model.encode(s2)).item()
    return f'{score:.3f}'

gr.Interface(
    inference,
    [ gr.Textbox(label="Sentence 1"), gr.Textbox(label="Sentence 2")  ],
    [ gr.components.Label(label="Similarity score") ],
    title="Similarity score between 2 sentences",
    description="In this demo do provide 2 sentences bellow. They can even be in distinct languages. Powered by S-BERT multilingual model : https://www.sbert.net.",
    examples=[['The sentences are mapped such that sentences with similar meanings are close in vector space.', 'Les phrases sont mappées de manière à ce que les phrases ayant des significations similaires soient proches dans l\'espace vectoriel.'],
              ['You do not need to specify the input language.', 'You can use any language.']],
    live=True,
    allow_flagging="never"
).launch(debug=True, enable_queue=True)"""
import streamlit as st
from sentence_transformers import SentenceTransformer, util

i18n_model = SentenceTransformer('distiluse-base-multilingual-cased-v2')

#def inference(s1:str, s2:str):
#    score = util.cos_sim(i18n_model.encode(s1), i18n_model.encode(s2)).item()
#    return f'{score:.3f}'

txt1 = st.text_area('Text1','Account issues	Create, download, and send white-label reports to your customers to keep them posted on how their campaigns are going.	Watch a short video review of the Dedicated SEO Dashboard	')
list1 = txt1.split("	")
txt2 = st.text_area('Text2','Проблеми з обліковим записом	Створюйте, завантажуйте та надсилайте своїм клієнтам звіти з білою етикеткою, щоб вони були в курсі того, як проходять їхні кампанії.	')
list2 = txt2.split("	")




i = 1
while i < 1000:
    st.write(util.cos_sim(i18n_model.encode(list1[i]), i18n_model.encode(list2[i])).item())
    i += 1