Elo ratings, originally designed for assessing the relative skills of chess players, can be effectively utilized to compare different machine learning models (including LLMs - Large Language Models) based on human judgment of their performance. Implementing a blind comparison of LLMs through user scoring and subsequent Elo rating calculation involves several steps. Below is a simplified blueprint for how you could set this up:
1. Prepare the data for comparison
You have a JSON line file with entries containing "model_name," "prompt," and "response". The first step is to process this file to pair responses to the same prompt from different models for comparison.
Example entry format (before pairing):
{"model_name": "ModelA", "prompt": "What is the weather today?", "response": "It's sunny."}
{"model_name": "ModelB", "prompt": "What is the weather today?", "response": "Sunny with a slight chance of rain."}
2. Create Comparison Pairs
For each prompt, you'll need to create pairs of responses from different models to be evaluated. Make sure each pair is shuffled to avoid bias (so it’s not always Model A vs. Model B in the same order).
3. Collect User Scores
Present each pair to users in a blinded manner (not showing which model produced which response) and ask them to rate the pair as "A win", "B win", "Both OK", or "Both fail". You can set this up as a simple web interface where users read the prompt and the two responses, then click a button corresponding to their judgment.
4. Calculate Elo Scores
Elo ratings can be adapted to rate models based on the user feedback. Initially, assign each model an identical Elo rating, say 1500.
For each judgment:
- If there is a winner ("A win" or "B win"), update the Elo scores for both models involved. The winner's score goes up, and the loser's score goes down.
- For "Both OK" or "Both fail", you might choose not to adjust the scores, or adjust them less significantly than in decisive outcomes.
The score adjustments are based on the expectation of winning vs. the actual result:
- Expected score (E) for a model is calculated as
1 / (1 + 10^((rating_opponent - rating_model) / 400)).
- Score (S) is determined by the match outcome: 1 for a win, 0.5 for a draw ("Both OK" or "Both fail"), and 0 for a loss.
- New rating =
old rating + K * (S - E), where K is a factor that determines the maximum change possible from a single game (often set between 20 and 40).
Implementation (Psuedocode)
def update_elo(winner_rating, loser_rating, k=32):
"""Calculate new Elo ratings after a match. Assumes winner beats loser."""
expected_winner = 1 / (1 + 10**((loser_rating - winner_rating) / 400))
expected_loser = 1 - expected_winner
new_winner_rating = winner_rating + k * (1 - expected_winner)
new_loser_rating = loser_rating + k * (0 - expected_loser)
return new_winner_rating, new_loser_rating
# Initial ratings
ratings = {'ModelA': 1500, 'ModelB': 1500, ...}
# After collecting judgments
for each judgment in judgments:
if judgment is "A win" or "B win":
# Assuming first model is A, and second is B
if judgment is "A win":
ratings['ModelA'], ratings['ModelB'] = update_elo(ratings['ModelA'], ratings['ModelB'])
else:
ratings['ModelB'], ratings['ModelA'] = update_elo(ratings['ModelB'], ratings['ModelA'])
# Implement logic for "Both OK" or "Both fail" if adjusting scores for those scenarios
Adjust the implementation as necessary to fit the specifics of how you're collecting data, the structure of your JSON entries, and how you want to handle ties and non-decisive outcomes. Remember, the key to a valid comparison is ensuring that users' judgments are based on blinded data to prevent any bias toward or against specific models.