Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -26,11 +26,10 @@ def thefuzz(text1, text2):
|
|
| 26 |
|
| 27 |
|
| 28 |
def tfidf(text1, text2):
|
| 29 |
-
print('hello')
|
| 30 |
t1_tfidf = vectorizer.fit_transform([text1])
|
| 31 |
t2_tfidf = vectorizer.transform([text2])
|
| 32 |
cosine_sim = cosine_similarity(t1_tfidf, t2_tfidf).flatten()[0]
|
| 33 |
-
return {'cosine similarity of tf-idf vectors':cosine_sim}
|
| 34 |
|
| 35 |
|
| 36 |
def simcse(text1, text2):
|
|
@@ -39,7 +38,7 @@ def simcse(text1, text2):
|
|
| 39 |
with torch.no_grad():
|
| 40 |
embeddings = model_simcse(**inputs, output_hidden_states=True, return_dict=True).pooler_output
|
| 41 |
cosine_sim = 1 - cosine(embeddings[0], embeddings[1])
|
| 42 |
-
return {"cosine similarity of simcse embeddings":cosine_sim}
|
| 43 |
|
| 44 |
|
| 45 |
def mpnet(text1, text2):
|
|
@@ -48,7 +47,7 @@ def mpnet(text1, text2):
|
|
| 48 |
model_output = model_mpnet(**encoded_input)
|
| 49 |
sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
|
| 50 |
cosine_sim = 1 - cosine(sentence_embeddings[0], sentence_embeddings[1])
|
| 51 |
-
return {"cosine similarity of stsb-mpnet embeddings":cosine_sim}
|
| 52 |
|
| 53 |
|
| 54 |
def get_scores(text1, text2):
|
|
|
|
| 26 |
|
| 27 |
|
| 28 |
def tfidf(text1, text2):
|
|
|
|
| 29 |
t1_tfidf = vectorizer.fit_transform([text1])
|
| 30 |
t2_tfidf = vectorizer.transform([text2])
|
| 31 |
cosine_sim = cosine_similarity(t1_tfidf, t2_tfidf).flatten()[0]
|
| 32 |
+
return {'cosine similarity of tf-idf vectors':str(round(cosine_sim,2))}
|
| 33 |
|
| 34 |
|
| 35 |
def simcse(text1, text2):
|
|
|
|
| 38 |
with torch.no_grad():
|
| 39 |
embeddings = model_simcse(**inputs, output_hidden_states=True, return_dict=True).pooler_output
|
| 40 |
cosine_sim = 1 - cosine(embeddings[0], embeddings[1])
|
| 41 |
+
return {"cosine similarity of simcse embeddings":str(round(cosine_sim,2))}
|
| 42 |
|
| 43 |
|
| 44 |
def mpnet(text1, text2):
|
|
|
|
| 47 |
model_output = model_mpnet(**encoded_input)
|
| 48 |
sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
|
| 49 |
cosine_sim = 1 - cosine(sentence_embeddings[0], sentence_embeddings[1])
|
| 50 |
+
return {"cosine similarity of stsb-mpnet embeddings":str(round(cosine_sim,2))}
|
| 51 |
|
| 52 |
|
| 53 |
def get_scores(text1, text2):
|