Hellisotherpeople commited on
Commit
9848e77
1 Parent(s): 02b1aaf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -3
app.py CHANGED
@@ -123,7 +123,7 @@ if task == "Clustering":
123
  ('cluster', KMeans(n_clusters = n_clusters, n_init = n_init, max_iter = max_iter)),
124
  ])
125
 
126
- @st.cache
127
  def fit_text_clf(X, y):
128
  text_clf.fit(X, y)
129
  return text_clf
@@ -154,10 +154,16 @@ form_explainer.form_submit_button("Submit")
154
 
155
  te = TextExplainer(random_state=42, char_based=char_based, n_samples = number_samples, position_dependent=position_dep)
156
 
 
 
 
 
 
157
  input_choice = st.checkbox("Check this if you want to enter your own example to explain", value = False)
158
  if input_choice == False:
159
  record_to_explain = st.number_input("Enter the index of the document from the original dataset to interpret", value = 30)
160
- te.fit(df[column_name][record_to_explain], text_clf.predict_proba)
 
161
  if task == "Classification":
162
  st.write("Ground truth label")
163
  st.write(df[labels_column_name][record_to_explain])
@@ -172,7 +178,8 @@ if input_choice == False:
172
  st.write(model_prediction)
173
  else:
174
  record_to_explain = st.text_area("Enter the example document to explain", value = text_example)
175
- te.fit(record_to_explain, text_clf.predict_proba)
 
176
  if task == "Classification":
177
  st.write("Model prediction")
178
  model_prediction = text_clf.predict([record_to_explain])
 
123
  ('cluster', KMeans(n_clusters = n_clusters, n_init = n_init, max_iter = max_iter)),
124
  ])
125
 
126
+ @st.cache(allow_output_mutation=True)
127
  def fit_text_clf(X, y):
128
  text_clf.fit(X, y)
129
  return text_clf
 
154
 
155
  te = TextExplainer(random_state=42, char_based=char_based, n_samples = number_samples, position_dependent=position_dep)
156
 
157
+ @st.cache(allow_output_mutation=True)
158
+ def fit_text_explainer(X, predict_proba):
159
+ te.fit(X, predict_proba)
160
+ return te
161
+
162
  input_choice = st.checkbox("Check this if you want to enter your own example to explain", value = False)
163
  if input_choice == False:
164
  record_to_explain = st.number_input("Enter the index of the document from the original dataset to interpret", value = 30)
165
+ #te.fit(df[column_name][record_to_explain], text_clf.predict_proba)
166
+ fit_text_explainer(df[column_name][record_to_explain], text_clf.predict_proba)
167
  if task == "Classification":
168
  st.write("Ground truth label")
169
  st.write(df[labels_column_name][record_to_explain])
 
178
  st.write(model_prediction)
179
  else:
180
  record_to_explain = st.text_area("Enter the example document to explain", value = text_example)
181
+ #te.fit(record_to_explain, text_clf.predict_proba)
182
+ fit_text_explainer(record_to_explain, text_clf.predict_proba)
183
  if task == "Classification":
184
  st.write("Model prediction")
185
  model_prediction = text_clf.predict([record_to_explain])