Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -109,16 +109,16 @@ def predict(user_input_text):
|
|
109 |
|
110 |
response += "<br>TOP 2 MOST INFLUENTIAL WORDS FOR EACH LABEL:<br>"
|
111 |
for i, explanations in enumerate(explanation_lists):
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
|
123 |
return response
|
124 |
|
|
|
109 |
|
110 |
response += "<br>TOP 2 MOST INFLUENTIAL WORDS FOR EACH LABEL:<br>"
|
111 |
for i, explanations in enumerate(explanation_lists):
|
112 |
+
label = labels[i]
|
113 |
+
response += f"{label}:<br>"
|
114 |
+
for explanation in explanations:
|
115 |
+
if explanation.explainer == 'Partition SHAP':
|
116 |
+
sorted_scores = sorted(enumerate(explanation.scores), key=lambda x: abs(x[1]), reverse=True)[:2]
|
117 |
+
if sorted_scores: # Check if the list is not empty
|
118 |
+
tokens = replace_encoding(explanation.tokens)
|
119 |
+
tokens = [tokens[idx] for idx, _ in sorted_scores]
|
120 |
+
formatted_output = ' '.join(tokens)
|
121 |
+
response += f"{formatted_output}<br>"
|
122 |
|
123 |
return response
|
124 |
|