Spaces:
Runtime error
Runtime error
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) |