Spaces:
Running
Running
File size: 1,512 Bytes
5b68c01 4df9e3a 877d19f 693d1fb 4df9e3a 877d19f 4df9e3a 877d19f 4df9e3a b498339 d183fc7 fd398d9 d183fc7 da18950 d183fc7 693d1fb b2e1c8b 693d1fb d183fc7 |
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 |
import streamlit as st # type: ignore
from PIL import Image
import os
import ast
import contextlib
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from nltk.corpus import stopwords
from sklearn.manifold import TSNE
from sentence_transformers import SentenceTransformer
from sklearn.metrics.pairwise import cosine_similarity
from translate_app import tr
title = "Sentence Similarity"
sidebar_name = "Sentence Similarity"
dataPath = st.session_state.DataPath
def run():
st.write("")
st.title(tr(title))
sentences = ["This is an example sentence", "Each sentence is converted"]
sentences[0] = st.text_area(label=tr("Saisir un élément issu de la proposition de valeur (quelque soit la langue):"), value="This is an example sentence")
sentences[1] = st.text_area(label=tr("Saisir une phrase issue de l'acte de vente (quelque soit la langue):"), value="Each sentence is converted", height=200)
st.button(label=tr("Validez"), type="primary")
model = SentenceTransformer('sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2')
embeddings = model.encode(sentences)
st.write(tr("Transformation de chaque phrase en vecteur (dimension = 384 ):"))
st.write(embeddings)
st.write("")
# Calculate cosine similarity between the two sentences
similarity = cosine_similarity([embeddings[0]], [embeddings[1]])
st.write(tr("**Cosine similarity** comprise entre 0 et 1 :"), similarity[0][0])
st.write("")
st.write("")
st.write("") |