Spaces:
Runtime error
Runtime error
Commit
·
5f849fb
1
Parent(s):
a0a875f
Update app.py
Browse files
app.py
CHANGED
@@ -10,6 +10,14 @@ from numpy.linalg import norm
|
|
10 |
# compute dot product of inputs
|
11 |
# summary function - test for single gradio function interfrace
|
12 |
def gr_cosine_similarity(sentence1, sentence2):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
# Create class for data preparation
|
14 |
class SimpleDataset:
|
15 |
def __init__(self, tokenized_texts):
|
@@ -21,19 +29,10 @@ def gr_cosine_similarity(sentence1, sentence2):
|
|
21 |
def __getitem__(self, idx):
|
22 |
return {k: v[idx] for k, v in self.tokenized_texts.items()}
|
23 |
|
24 |
-
|
25 |
-
model_name = "j-hartmann/emotion-english-distilroberta-base"
|
26 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
27 |
-
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
28 |
-
trainer = Trainer(model=model)
|
29 |
-
|
30 |
-
|
31 |
# sentences in list
|
32 |
lines_s = [sentence1, sentence2]
|
33 |
-
|
34 |
-
print(sentence1, sentence2)
|
35 |
-
print(lines_s)
|
36 |
-
|
37 |
# Tokenize texts and create prediction data set
|
38 |
tokenized_texts = tokenizer(lines_s, truncation=True, padding=True)
|
39 |
pred_dataset = SimpleDataset(tokenized_texts)
|
@@ -49,7 +48,7 @@ def gr_cosine_similarity(sentence1, sentence2):
|
|
49 |
temp = (np.exp(predictions[0])/np.exp(predictions[0]).sum(-1, keepdims=True)).tolist()
|
50 |
|
51 |
|
52 |
-
|
53 |
# container
|
54 |
anger = []
|
55 |
disgust = []
|
@@ -59,7 +58,6 @@ def gr_cosine_similarity(sentence1, sentence2):
|
|
59 |
sadness = []
|
60 |
surprise = []
|
61 |
|
62 |
-
print(temp)
|
63 |
# extract scores (as many entries as exist in pred_texts)
|
64 |
for i in range(len(lines_s)):
|
65 |
anger.append(temp[i][0])
|
@@ -74,7 +72,7 @@ def gr_cosine_similarity(sentence1, sentence2):
|
|
74 |
# each include all values for both predictions
|
75 |
v1 = temp[0]
|
76 |
v2 = temp[1]
|
77 |
-
|
78 |
# compute dot product of all
|
79 |
dot_product = dot(v1, v2)
|
80 |
|
|
|
10 |
# compute dot product of inputs
|
11 |
# summary function - test for single gradio function interfrace
|
12 |
def gr_cosine_similarity(sentence1, sentence2):
|
13 |
+
|
14 |
+
# load tokenizer and model, create trainer
|
15 |
+
model_name = "j-hartmann/emotion-english-distilroberta-base"
|
16 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
17 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
18 |
+
trainer = Trainer(model=model)
|
19 |
+
|
20 |
+
|
21 |
# Create class for data preparation
|
22 |
class SimpleDataset:
|
23 |
def __init__(self, tokenized_texts):
|
|
|
29 |
def __getitem__(self, idx):
|
30 |
return {k: v[idx] for k, v in self.tokenized_texts.items()}
|
31 |
|
32 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
# sentences in list
|
34 |
lines_s = [sentence1, sentence2]
|
35 |
+
|
|
|
|
|
|
|
36 |
# Tokenize texts and create prediction data set
|
37 |
tokenized_texts = tokenizer(lines_s, truncation=True, padding=True)
|
38 |
pred_dataset = SimpleDataset(tokenized_texts)
|
|
|
48 |
temp = (np.exp(predictions[0])/np.exp(predictions[0]).sum(-1, keepdims=True)).tolist()
|
49 |
|
50 |
|
51 |
+
# work in progress
|
52 |
# container
|
53 |
anger = []
|
54 |
disgust = []
|
|
|
58 |
sadness = []
|
59 |
surprise = []
|
60 |
|
|
|
61 |
# extract scores (as many entries as exist in pred_texts)
|
62 |
for i in range(len(lines_s)):
|
63 |
anger.append(temp[i][0])
|
|
|
72 |
# each include all values for both predictions
|
73 |
v1 = temp[0]
|
74 |
v2 = temp[1]
|
75 |
+
|
76 |
# compute dot product of all
|
77 |
dot_product = dot(v1, v2)
|
78 |
|