Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -70,16 +70,10 @@ def replace_encoding(tokens):
|
|
70 |
for token in tokens[1:-1]]
|
71 |
|
72 |
def predict(text):
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
explanations_toxicity = exp(text, target=3)
|
78 |
-
|
79 |
-
#explanations_formality = bench.explain(text, target=0)
|
80 |
-
#explanations_sentiment = bench.explain(text, target=1)
|
81 |
-
#explanations_politeness = bench.explain(text, target=2)
|
82 |
-
#explanations_toxicity = bench.explain(text, target=3)
|
83 |
|
84 |
greeting_pattern = r"^(Halló|Hæ|Sæl|Góðan dag|Kær kveðja|Daginn|Kvöldið|Ágætis|Elsku)"
|
85 |
|
@@ -95,7 +89,6 @@ def predict(text):
|
|
95 |
|
96 |
response = f"INPUT:<br>{modified_input}<br><br>MY PREDICTION:<br>{prediction_output}<br>{influential_keywords}<br>{greeting_feedback}"
|
97 |
|
98 |
-
# Include influential words in the response
|
99 |
explanation_lists = [explanations_toxicity, explanations_formality, explanations_sentiment, explanations_politeness]
|
100 |
labels = ['Toxicity', 'Formality', 'Sentiment', 'Politeness']
|
101 |
|
@@ -109,20 +102,9 @@ def predict(text):
|
|
109 |
formatted_output = ' '.join([f"{token} ({score})" for token, score in token_score_pairs])
|
110 |
response += f"{label}: {formatted_output}<br>"
|
111 |
|
112 |
-
#response += "<br>TOP 2 MOST INFLUENTIAL WORDS FOR EACH LABEL:<br>"
|
113 |
-
#for i, explanations in enumerate(explanation_lists):
|
114 |
-
# label = labels[i]
|
115 |
-
# response += f"{label}:<br>"
|
116 |
-
# for explanation in explanations:
|
117 |
-
# if explanation.explainer == 'Partition SHAP':
|
118 |
-
# sorted_scores = sorted(enumerate(explanation.scores), key=lambda x: abs(x[1]), reverse=True)[:2]
|
119 |
-
# tokens = replace_encoding(explanation.tokens)
|
120 |
-
# tokens = [tokens[idx] for idx, _ in sorted_scores]
|
121 |
-
# formatted_output = ' '.join(tokens)
|
122 |
-
# response += f"{formatted_output}<br>"
|
123 |
-
|
124 |
return response
|
125 |
|
|
|
126 |
description_html = """
|
127 |
<center>
|
128 |
<img src='http://www.ru.is/media/HR_logo_vinstri_transparent.png' width='250' height='auto'>
|
|
|
70 |
for token in tokens[1:-1]]
|
71 |
|
72 |
def predict(text):
|
73 |
+
explanations_formality = [bench.explain(text, target=0)]
|
74 |
+
explanations_sentiment = [bench.explain(text, target=1)]
|
75 |
+
explanations_politeness = [bench.explain(text, target=2)]
|
76 |
+
explanations_toxicity = [bench.explain(text, target=3)]
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
|
78 |
greeting_pattern = r"^(Halló|Hæ|Sæl|Góðan dag|Kær kveðja|Daginn|Kvöldið|Ágætis|Elsku)"
|
79 |
|
|
|
89 |
|
90 |
response = f"INPUT:<br>{modified_input}<br><br>MY PREDICTION:<br>{prediction_output}<br>{influential_keywords}<br>{greeting_feedback}"
|
91 |
|
|
|
92 |
explanation_lists = [explanations_toxicity, explanations_formality, explanations_sentiment, explanations_politeness]
|
93 |
labels = ['Toxicity', 'Formality', 'Sentiment', 'Politeness']
|
94 |
|
|
|
102 |
formatted_output = ' '.join([f"{token} ({score})" for token, score in token_score_pairs])
|
103 |
response += f"{label}: {formatted_output}<br>"
|
104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
return response
|
106 |
|
107 |
+
|
108 |
description_html = """
|
109 |
<center>
|
110 |
<img src='http://www.ru.is/media/HR_logo_vinstri_transparent.png' width='250' height='auto'>
|