Chatbot Arena ranks LLMs from head-to-head human votes using Elo ratings. For models A and B with ratings and :
where is 1 for a win, 0.5 for a tie and 0 for a loss (and B is updated symmetrically).
Implement elo_ratings(matches, k=32, initial=1000), where matches is a list of (model_a, model_b, result) with result "a", "b" or "tie", processed in order. Return a dict of final ratings. Then implement leaderboard(ratings): a list of (model, rating) sorted by rating, highest first, with ties by name.