Spaces:
Running
Running
Update leaderboard.py
Browse files- leaderboard.py +55 -25
leaderboard.py
CHANGED
@@ -70,7 +70,11 @@ def initialize_elo_ratings():
|
|
70 |
|
71 |
# Replay all battles to update ELO ratings
|
72 |
for model, data in leaderboard.items():
|
|
|
|
|
73 |
for opponent, results in data['opponents'].items():
|
|
|
|
|
74 |
for _ in range(results['wins']):
|
75 |
update_elo_ratings(model, opponent)
|
76 |
for _ in range(results['losses']):
|
@@ -212,28 +216,57 @@ def calculate_elo_impact(model):
|
|
212 |
leaderboard = load_leaderboard()
|
213 |
initial_rating = 1000 + (get_model_size(model) * 100)
|
214 |
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
|
|
227 |
|
228 |
return round(positive_impact), round(negative_impact), round(initial_rating)
|
229 |
|
230 |
def get_elo_leaderboard():
|
231 |
ensure_elo_ratings_initialized()
|
232 |
leaderboard = load_leaderboard()
|
233 |
-
sorted_ratings = sorted(elo_ratings.items(), key=lambda x: x[1], reverse=True)
|
234 |
|
235 |
-
|
236 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
237 |
|
238 |
explanation_elo = f"""
|
239 |
<p style="font-size: 16px; margin-bottom: 20px;">
|
@@ -276,24 +309,21 @@ def get_elo_leaderboard():
|
|
276 |
<th>Negative Impact</th>
|
277 |
<th>Total Battles</th>
|
278 |
<th>Initial Rating</th>
|
279 |
-
|
280 |
</tr>
|
281 |
"""
|
282 |
|
283 |
-
for index,
|
284 |
-
total_battles = leaderboard[model]['wins'] + leaderboard[model]['losses']
|
285 |
rank_display = {1: "π₯", 2: "π₯", 3: "π₯"}.get(index, f"{index}")
|
286 |
-
positive_impact, negative_impact, initial_rating = calculate_elo_impact(model)
|
287 |
|
288 |
leaderboard_html += f"""
|
289 |
<tr>
|
290 |
<td class='rank-column'>{rank_display}</td>
|
291 |
-
<td>{get_human_readable_name(model)}</td>
|
292 |
-
<td><strong>{round(
|
293 |
-
<td>{positive_impact}</td>
|
294 |
-
<td>{negative_impact}</td>
|
295 |
-
<td>{total_battles}</td>
|
296 |
-
<td>{initial_rating}</td>
|
297 |
</tr>
|
298 |
"""
|
299 |
|
|
|
70 |
|
71 |
# Replay all battles to update ELO ratings
|
72 |
for model, data in leaderboard.items():
|
73 |
+
if model not in elo_ratings:
|
74 |
+
elo_ratings[model] = 1000 + (get_model_size(model) * 100)
|
75 |
for opponent, results in data['opponents'].items():
|
76 |
+
if opponent not in elo_ratings:
|
77 |
+
elo_ratings[opponent] = 1000 + (get_model_size(opponent) * 100)
|
78 |
for _ in range(results['wins']):
|
79 |
update_elo_ratings(model, opponent)
|
80 |
for _ in range(results['losses']):
|
|
|
216 |
leaderboard = load_leaderboard()
|
217 |
initial_rating = 1000 + (get_model_size(model) * 100)
|
218 |
|
219 |
+
if model in leaderboard:
|
220 |
+
for opponent, results in leaderboard[model]['opponents'].items():
|
221 |
+
model_size = get_model_size(model)
|
222 |
+
opponent_size = get_model_size(opponent)
|
223 |
+
max_size = max(get_model_size(m) for m, _ in arena_config.APPROVED_MODELS)
|
224 |
+
|
225 |
+
size_difference = (opponent_size - model_size) / max_size
|
226 |
+
|
227 |
+
win_impact = 1 + max(0, size_difference)
|
228 |
+
loss_impact = 1 + max(0, -size_difference)
|
229 |
+
|
230 |
+
positive_impact += results['wins'] * win_impact
|
231 |
+
negative_impact += results['losses'] * loss_impact
|
232 |
|
233 |
return round(positive_impact), round(negative_impact), round(initial_rating)
|
234 |
|
235 |
def get_elo_leaderboard():
|
236 |
ensure_elo_ratings_initialized()
|
237 |
leaderboard = load_leaderboard()
|
|
|
238 |
|
239 |
+
# Create a list of all models, including those from APPROVED_MODELS that might not be in the leaderboard yet
|
240 |
+
all_models = set(dict(arena_config.APPROVED_MODELS).keys()) | set(leaderboard.keys())
|
241 |
+
|
242 |
+
elo_data = []
|
243 |
+
for model in all_models:
|
244 |
+
initial_rating = 1000 + (get_model_size(model) * 100)
|
245 |
+
current_rating = elo_ratings.get(model, initial_rating)
|
246 |
+
|
247 |
+
# Calculate battle data only if the model exists in the leaderboard
|
248 |
+
if model in leaderboard:
|
249 |
+
wins = leaderboard[model].get('wins', 0)
|
250 |
+
losses = leaderboard[model].get('losses', 0)
|
251 |
+
total_battles = wins + losses
|
252 |
+
positive_impact, negative_impact, _ = calculate_elo_impact(model)
|
253 |
+
else:
|
254 |
+
wins = losses = total_battles = positive_impact = negative_impact = 0
|
255 |
+
|
256 |
+
elo_data.append({
|
257 |
+
'model': model,
|
258 |
+
'current_rating': current_rating,
|
259 |
+
'initial_rating': initial_rating,
|
260 |
+
'total_battles': total_battles,
|
261 |
+
'positive_impact': positive_impact,
|
262 |
+
'negative_impact': negative_impact
|
263 |
+
})
|
264 |
+
|
265 |
+
# Sort the data by current rating
|
266 |
+
sorted_elo_data = sorted(elo_data, key=lambda x: x['current_rating'], reverse=True)
|
267 |
+
|
268 |
+
min_initial_rating = min(data['initial_rating'] for data in elo_data)
|
269 |
+
max_initial_rating = max(data['initial_rating'] for data in elo_data)
|
270 |
|
271 |
explanation_elo = f"""
|
272 |
<p style="font-size: 16px; margin-bottom: 20px;">
|
|
|
309 |
<th>Negative Impact</th>
|
310 |
<th>Total Battles</th>
|
311 |
<th>Initial Rating</th>
|
|
|
312 |
</tr>
|
313 |
"""
|
314 |
|
315 |
+
for index, data in enumerate(sorted_elo_data, start=1):
|
|
|
316 |
rank_display = {1: "π₯", 2: "π₯", 3: "π₯"}.get(index, f"{index}")
|
|
|
317 |
|
318 |
leaderboard_html += f"""
|
319 |
<tr>
|
320 |
<td class='rank-column'>{rank_display}</td>
|
321 |
+
<td>{get_human_readable_name(data['model'])}</td>
|
322 |
+
<td><strong>{round(data['current_rating'])}</strong></td>
|
323 |
+
<td>{data['positive_impact']}</td>
|
324 |
+
<td>{data['negative_impact']}</td>
|
325 |
+
<td>{data['total_battles']}</td>
|
326 |
+
<td>{round(data['initial_rating'])}</td>
|
327 |
</tr>
|
328 |
"""
|
329 |
|