Spaces:
Runtime error
Runtime error
emiliosheinz
commited on
Commit
•
4c9ba47
1
Parent(s):
acf0ee9
remove app def
Browse files
app.py
CHANGED
@@ -5,26 +5,24 @@ from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
|
5 |
tokenizer = AutoTokenizer.from_pretrained("distilbert-base-multilingual-cased")
|
6 |
model = AutoModelForSequenceClassification.from_pretrained("distilbert-base-multilingual-cased")
|
7 |
|
8 |
-
#
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
#
|
14 |
-
|
15 |
-
sentence2 = st.text_input("Enter the second sentence:")
|
16 |
|
17 |
-
#
|
18 |
-
|
19 |
-
# tokenize the sentences and get the output logits for the sentence pair classification task
|
20 |
-
inputs = tokenizer(sentence1, sentence2, padding=True, truncation=True, max_length=250, return_tensors="pt")
|
21 |
-
outputs = model(**inputs).logits
|
22 |
-
|
23 |
-
# calculate the softmax probabilities for the two classes (similar or dissimilar)
|
24 |
-
probs = outputs.softmax(dim=1)
|
25 |
-
|
26 |
-
# the probability of the sentences being similar is the second element of the output array
|
27 |
-
similarity_score = probs[0][1].item()
|
28 |
-
|
29 |
-
# display the similarity score to the user
|
30 |
-
st.write("Similarity score:", similarity_score)
|
|
|
5 |
tokenizer = AutoTokenizer.from_pretrained("distilbert-base-multilingual-cased")
|
6 |
model = AutoModelForSequenceClassification.from_pretrained("distilbert-base-multilingual-cased")
|
7 |
|
8 |
+
# set the app title
|
9 |
+
st.title("Sentence Similarity Checker")
|
10 |
+
|
11 |
+
# get the input sentences from the user
|
12 |
+
sentence1 = st.text_input("Enter the first sentence:")
|
13 |
+
sentence2 = st.text_input("Enter the second sentence:")
|
14 |
+
|
15 |
+
# check if both sentences are not empty
|
16 |
+
if sentence1 and sentence2:
|
17 |
+
# tokenize the sentences and get the output logits for the sentence pair classification task
|
18 |
+
inputs = tokenizer(sentence1, sentence2, padding=True, truncation=True, max_length=250, return_tensors="pt")
|
19 |
+
outputs = model(**inputs).logits
|
20 |
+
|
21 |
+
# calculate the softmax probabilities for the two classes (similar or dissimilar)
|
22 |
+
probs = outputs.softmax(dim=1)
|
23 |
|
24 |
+
# the probability of the sentences being similar is the second element of the output array
|
25 |
+
similarity_score = probs[0][1].item()
|
|
|
26 |
|
27 |
+
# display the similarity score to the user
|
28 |
+
st.write("Similarity score:", similarity_score)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|