karalif commited on
Commit
fb998f7
verified
1 Parent(s): 1ee0184

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -109,11 +109,12 @@ 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
- 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
  tokens = replace_encoding(explanation.tokens)
118
  tokens = [tokens[idx] for idx, _ in sorted_scores]
119
  formatted_output = ' '.join(tokens)
 
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)