AlexTransformer commited on
Commit
284767f
Β·
verified Β·
1 Parent(s): a4efd86

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -9
app.py CHANGED
@@ -121,8 +121,12 @@ def compare_models(text, top_k=5):
121
  }
122
 
123
  # Create a properly structured dataframe
124
- # Use display tokens from the first model for the Token column
125
- df_data = {"Token": results["ERNIE-4.5-PT"]["display_tokens"]}
 
 
 
 
126
 
127
  # Add columns for each model
128
  for model_name in ["ERNIE-4.5-PT", "ERNIE-4.5-Base-PT"]:
@@ -141,7 +145,7 @@ def compare_models(text, top_k=5):
141
  # Add bars for both models
142
  fig_confidence.add_trace(go.Bar(
143
  name='ERNIE-4.5-PT',
144
- x=results["ERNIE-4.5-PT"]["display_tokens"],
145
  y=results["ERNIE-4.5-PT"]["confidence_values"],
146
  marker_color='royalblue',
147
  text=[format_prob(x) for x in results["ERNIE-4.5-PT"]["confidence_values"]],
@@ -151,7 +155,7 @@ def compare_models(text, top_k=5):
151
 
152
  fig_confidence.add_trace(go.Bar(
153
  name='ERNIE-4.5-Base-PT',
154
- x=results["ERNIE-4.5-Base-PT"]["display_tokens"],
155
  y=results["ERNIE-4.5-Base-PT"]["confidence_values"],
156
  marker_color='lightseagreen',
157
  text=[format_prob(x) for x in results["ERNIE-4.5-Base-PT"]["confidence_values"]],
@@ -184,23 +188,23 @@ def compare_models(text, top_k=5):
184
 
185
  fig_logprob.add_trace(go.Scatter(
186
  name='ERNIE-4.5-PT',
187
- x=results["ERNIE-4.5-PT"]["display_tokens"],
188
  y=pt_logprobs,
189
  mode='lines+markers',
190
  line=dict(color='royalblue', width=3),
191
  marker=dict(size=8),
192
- text=[f"LogProb: {x}<br>Token: {t}" for x, t in zip(pt_logprobs, results["ERNIE-4.5-PT"]["display_tokens"])],
193
  hoverinfo='text'
194
  ))
195
 
196
  fig_logprob.add_trace(go.Scatter(
197
  name='ERNIE-4.5-Base-PT',
198
- x=results["ERNIE-4.5-Base-PT"]["display_tokens"],
199
  y=base_logprobs,
200
  mode='lines+markers',
201
  line=dict(color='lightseagreen', width=3),
202
  marker=dict(size=8),
203
- text=[f"LogProb: {x}<br>Token: {t}" for x, t in zip(base_logprobs, results["ERNIE-4.5-Base-PT"]["display_tokens"])],
204
  hoverinfo='text'
205
  ))
206
 
@@ -290,7 +294,8 @@ def compare_models(text, top_k=5):
290
  f"- **LogProb**: How confident the model is in predicting each token (closer to 0 is better)\n"
291
  f"- **Confidence**: Probability percentage for each token prediction\n"
292
  f"- **Level**: Visual indicator of confidence (πŸŸ’πŸŸ‘πŸ”΄)\n"
293
- f"- **Top-k**: What other tokens the model considered likely"
 
294
  )
295
 
296
  return comparison_df, summary, fig_confidence, fig_logprob, fig_summary
@@ -412,6 +417,8 @@ with gr.Blocks(css=css, title="ERNIE Model Comparison Tool") as demo:
412
  **Model Differences**:
413
  - **ERNIE-4.5-PT**: Instruction-tuned model, better at following complex instructions
414
  - **ERNIE-4.5-Base-PT**: Base model, better at general language patterns
 
 
415
  """
416
  )
417
 
 
121
  }
122
 
123
  # Create a properly structured dataframe
124
+ # The issue is that display_tokens has one more element than tokens
125
+ # We need to align them properly
126
+
127
+ # For the Token column, we'll use the display_tokens but only for the tokens that have predictions
128
+ # The first token in display_tokens doesn't have a prediction (since it's the first token)
129
+ df_data = {"Token": results["ERNIE-4.5-PT"]["display_tokens"][1:]}
130
 
131
  # Add columns for each model
132
  for model_name in ["ERNIE-4.5-PT", "ERNIE-4.5-Base-PT"]:
 
145
  # Add bars for both models
146
  fig_confidence.add_trace(go.Bar(
147
  name='ERNIE-4.5-PT',
148
+ x=results["ERNIE-4.5-PT"]["display_tokens"][1:],
149
  y=results["ERNIE-4.5-PT"]["confidence_values"],
150
  marker_color='royalblue',
151
  text=[format_prob(x) for x in results["ERNIE-4.5-PT"]["confidence_values"]],
 
155
 
156
  fig_confidence.add_trace(go.Bar(
157
  name='ERNIE-4.5-Base-PT',
158
+ x=results["ERNIE-4.5-Base-PT"]["display_tokens"][1:],
159
  y=results["ERNIE-4.5-Base-PT"]["confidence_values"],
160
  marker_color='lightseagreen',
161
  text=[format_prob(x) for x in results["ERNIE-4.5-Base-PT"]["confidence_values"]],
 
188
 
189
  fig_logprob.add_trace(go.Scatter(
190
  name='ERNIE-4.5-PT',
191
+ x=results["ERNIE-4.5-PT"]["display_tokens"][1:],
192
  y=pt_logprobs,
193
  mode='lines+markers',
194
  line=dict(color='royalblue', width=3),
195
  marker=dict(size=8),
196
+ text=[f"LogProb: {x}<br>Token: {t}" for x, t in zip(pt_logprobs, results["ERNIE-4.5-PT"]["display_tokens"][1:])],
197
  hoverinfo='text'
198
  ))
199
 
200
  fig_logprob.add_trace(go.Scatter(
201
  name='ERNIE-4.5-Base-PT',
202
+ x=results["ERNIE-4.5-Base-PT"]["display_tokens"][1:],
203
  y=base_logprobs,
204
  mode='lines+markers',
205
  line=dict(color='lightseagreen', width=3),
206
  marker=dict(size=8),
207
+ text=[f"LogProb: {x}<br>Token: {t}" for x, t in zip(base_logprobs, results["ERNIE-4.5-Base-PT"]["display_tokens"][1:])],
208
  hoverinfo='text'
209
  ))
210
 
 
294
  f"- **LogProb**: How confident the model is in predicting each token (closer to 0 is better)\n"
295
  f"- **Confidence**: Probability percentage for each token prediction\n"
296
  f"- **Level**: Visual indicator of confidence (πŸŸ’πŸŸ‘πŸ”΄)\n"
297
+ f"- **Top-k**: What other tokens the model considered likely\n\n"
298
+ f"**Note**: The first token of your input doesn't have a prediction because there's no preceding context to predict from."
299
  )
300
 
301
  return comparison_df, summary, fig_confidence, fig_logprob, fig_summary
 
417
  **Model Differences**:
418
  - **ERNIE-4.5-PT**: Instruction-tuned model, better at following complex instructions
419
  - **ERNIE-4.5-Base-PT**: Base model, better at general language patterns
420
+
421
+ **Note**: The first token of your input doesn't have a prediction because there's no preceding context to predict from.
422
  """
423
  )
424