Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mean reciprocal rank (MRR) of leaderboard scores #3451

Merged
merged 1 commit into from
Dec 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions codalab/apps/web/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1238,9 +1238,13 @@ def sortkey(x):
for result in results:
for sdef in result['scoredefs']:
if sdef.computed:
operation = getattr(models, sdef.computed_score.operation)
try:
operation = getattr(models, sdef.computed_score.operation)
operation_name = operation.name
except:
operation_name = sdef.computed_score.operation
weights = sdef.computed_score.weights
if (operation.name == 'Avg'):
if (operation_name == 'Avg'):
try:
cnt = len(computed_deps[sdef.id])
if (cnt > 0):
Expand All @@ -1263,6 +1267,18 @@ def sortkey(x):
ranks[sdef.id] = self.rank_values(submission_ids, computed_values, sort_ascending=sdef.sorting=='asc')
except KeyError:
pass
elif (operation_name == 'MRR'):
try:
cnt = len(computed_deps[sdef.id])
if (cnt > 0):
computed_values = {}
for id in submission_ids:
# Mean reciprocal rank computation
computed_values[id] = sum([1.0/ranks[d.id][id] for d in computed_deps[sdef.id]]) / float(cnt)
values[sdef.id] = computed_values
ranks[sdef.id] = self.rank_values(submission_ids, computed_values, sort_ascending=sdef.sorting=='asc')
except KeyError:
pass

# format values
for result in results:
Expand Down Expand Up @@ -2398,7 +2414,8 @@ def save(self, *args, **kwargs):
class SubmissionComputedScore(models.Model):
scoredef = models.OneToOneField(SubmissionScoreDef, related_name='computed_score', on_delete=models.CASCADE)
operation = models.CharField(max_length=10, choices=(('Max', 'Max'),
('Avg', 'Average')))
('Avg', 'Average'),
('MRR', 'MRR')))
weights = models.CharField(max_length=200, null=True, blank=True)


Expand Down
Loading