karalif commited on
Commit
ba54417
verified
1 Parent(s): 41e1886

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -1
app.py CHANGED
@@ -65,9 +65,36 @@ def predict(text):
65
  greeting_feedback = "OTHER FEEDBACK:<br>Heilsa冒u d贸ninn 镁inn<br>"
66
 
67
  response = f"INPUT:<br>{modified_input}<br><br>MY PREDICTION:<br>{prediction_output}<br>{influential_keywords}<br>{greeting_feedback}"
68
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  return response
70
 
 
71
  description_html = """
72
  <center>
73
  <img src='http://www.ru.is/media/HR_logo_vinstri_transparent.png' width='250' height='auto'>
 
65
  greeting_feedback = "OTHER FEEDBACK:<br>Heilsa冒u d贸ninn 镁inn<br>"
66
 
67
  response = f"INPUT:<br>{modified_input}<br><br>MY PREDICTION:<br>{prediction_output}<br>{influential_keywords}<br>{greeting_feedback}"
68
+
69
+ # Include influential words in the response
70
+ explanation_lists = [explanations_toxicity, explanations_formality, explanations_sentiment, explanations_politeness]
71
+ labels = ['Toxicity', 'Formality', 'Sentiment', 'Politeness']
72
+
73
+ response += "<br>MOST INFLUENTIAL WORDS FOR EACH LABEL:<br>"
74
+ for i, explanations in enumerate(explanation_lists):
75
+ label = labels[i]
76
+ for explanation in explanations:
77
+ if explanation.explainer == 'Partition SHAP':
78
+ tokens = replace_encoding(explanation.tokens)
79
+ token_score_pairs = zip(tokens, explanation.scores)
80
+ formatted_output = ' '.join([f"{token} ({score})" for token, score in token_score_pairs])
81
+ response += f"{label}: {formatted_output}<br>"
82
+
83
+ response += "<br>TOP 2 MOST INFLUENTIAL WORDS FOR EACH LABEL:<br>"
84
+ for i, explanations in enumerate(explanation_lists):
85
+ label = labels[i]
86
+ response += f"{label}:<br>"
87
+ for explanation in explanations:
88
+ if explanation.explainer == 'Partition SHAP':
89
+ sorted_scores = sorted(enumerate(explanation.scores), key=lambda x: abs(x[1]), reverse=True)[:2]
90
+ tokens = replace_encoding(explanation.tokens)
91
+ tokens = [tokens[idx] for idx, _ in sorted_scores]
92
+ formatted_output = ' '.join(tokens)
93
+ response += f"{formatted_output}<br>"
94
+
95
  return response
96
 
97
+
98
  description_html = """
99
  <center>
100
  <img src='http://www.ru.is/media/HR_logo_vinstri_transparent.png' width='250' height='auto'>