jedick commited on
Commit
feb987c
·
1 Parent(s): 6444d2c

Use consistent casing for predictions and user labels

Browse files
Files changed (1) hide show
  1. app.py +17 -15
app.py CHANGED
@@ -53,25 +53,15 @@ def prediction_to_df(prediction=None):
53
  """
54
  if prediction is None or prediction == "":
55
  # Show an empty plot for app initialization or auto-reload
56
- prediction = {"SUPPORT": 0, "NEI": 0, "REFUTE": 0}
57
  elif "Model" in prediction:
58
  # Show full-height bars when the model is changed
59
- prediction = {"SUPPORT": 1, "NEI": 1, "REFUTE": 1}
60
  else:
61
  # Convert predictions text to dictionary
62
  prediction = eval(prediction)
63
- # Rename dictionary keys to use consistent labels across models
64
- prediction = {
65
- ("SUPPORT" if k == "entailment" else k): v for k, v in prediction.items()
66
- }
67
- prediction = {
68
- ("NEI" if k == "neutral" else k): v for k, v in prediction.items()
69
- }
70
- prediction = {
71
- ("REFUTE" if k == "contradiction" else k): v for k, v in prediction.items()
72
- }
73
  # Use custom order for labels (pipe() returns labels in descending order of softmax score)
74
- labels = ["SUPPORT", "NEI", "REFUTE"]
75
  prediction = {k: prediction[k] for k in labels}
76
  # Convert dictionary to DataFrame with one column (Probability)
77
  df = pd.DataFrame.from_dict(prediction, orient="index", columns=["Probability"])
@@ -140,7 +130,7 @@ with gr.Blocks(theme=my_theme, css=custom_css, head=font_awesome_html) as demo:
140
  x="Class",
141
  y="Probability",
142
  color="Class",
143
- color_map={"SUPPORT": "green", "NEI": "#888888", "REFUTE": "#FF8888"},
144
  inputs=prediction,
145
  y_lim=([0, 1]),
146
  visible=False,
@@ -278,6 +268,18 @@ with gr.Blocks(theme=my_theme, css=custom_css, head=font_awesome_html) as demo:
278
  d["label"]: d["score"]
279
  for d in pipe({"text": evidence, "text_pair": claim}, top_k=3)
280
  }
 
 
 
 
 
 
 
 
 
 
 
 
281
  # Return two instances of the prediction to send to different Gradio components
282
  return prediction, prediction
283
 
@@ -333,7 +335,7 @@ with gr.Blocks(theme=my_theme, css=custom_css, head=font_awesome_html) as demo:
333
  Append input/outputs and user feedback to a JSON Lines file.
334
  """
335
  # Get the first label (prediction with highest probability)
336
- prediction = {k: v for k, v in [next(iter(label.items()))]}
337
  with USER_FEEDBACK_PATH.open("a") as f:
338
  f.write(
339
  json.dumps(
 
53
  """
54
  if prediction is None or prediction == "":
55
  # Show an empty plot for app initialization or auto-reload
56
+ prediction = {"Support": 0, "NEI": 0, "Refute": 0}
57
  elif "Model" in prediction:
58
  # Show full-height bars when the model is changed
59
+ prediction = {"Support": 1, "NEI": 1, "Refute": 1}
60
  else:
61
  # Convert predictions text to dictionary
62
  prediction = eval(prediction)
 
 
 
 
 
 
 
 
 
 
63
  # Use custom order for labels (pipe() returns labels in descending order of softmax score)
64
+ labels = ["Support", "NEI", "Refute"]
65
  prediction = {k: prediction[k] for k in labels}
66
  # Convert dictionary to DataFrame with one column (Probability)
67
  df = pd.DataFrame.from_dict(prediction, orient="index", columns=["Probability"])
 
130
  x="Class",
131
  y="Probability",
132
  color="Class",
133
+ color_map={"Support": "green", "NEI": "#888888", "Refute": "#FF8888"},
134
  inputs=prediction,
135
  y_lim=([0, 1]),
136
  visible=False,
 
268
  d["label"]: d["score"]
269
  for d in pipe({"text": evidence, "text_pair": claim}, top_k=3)
270
  }
271
+ # Rename dictionary keys to use consistent labels across models
272
+ prediction = {
273
+ ("Support" if k in ["SUPPORT", "entailment"] else k): v
274
+ for k, v in prediction.items()
275
+ }
276
+ prediction = {
277
+ ("NEI" if k in ["NEI", "neutral"] else k): v for k, v in prediction.items()
278
+ }
279
+ prediction = {
280
+ ("Refute" if k in ["REFUTE", "contradiction"] else k): v
281
+ for k, v in prediction.items()
282
+ }
283
  # Return two instances of the prediction to send to different Gradio components
284
  return prediction, prediction
285
 
 
335
  Append input/outputs and user feedback to a JSON Lines file.
336
  """
337
  # Get the first label (prediction with highest probability)
338
+ prediction = next(iter(label))
339
  with USER_FEEDBACK_PATH.open("a") as f:
340
  f.write(
341
  json.dumps(