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

fix: sorting benchmark tasks by MTEB, then alphabetical #1271

Merged
merged 6 commits into from
Oct 6, 2024
Merged
Changes from 2 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
34 changes: 30 additions & 4 deletions mteb/evaluation/MTEB.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ def available_tasks(self):

@property
def available_task_types(self):
return {x.metadata_dict["type"] for x in self.tasks_cls}
# sort the task types
task_types = {x.metadata_dict["type"] for x in self.tasks_cls}
task_types = sorted(task_types)
return task_types
sathviknallamalli marked this conversation as resolved.
Show resolved Hide resolved

@property
def available_task_categories(self):
Expand Down Expand Up @@ -148,15 +151,17 @@ def _display_tasks(self, task_list, name=None):
console = Console()
if name:
console.rule(f"[bold]{name}\n", style="grey15")
for task_type in self.available_task_types:
for task_type in self.available_task_types: # iterate through sorted task_types
current_type_tasks = list(
filter(lambda x: x.metadata.type == task_type, task_list)
)
if len(current_type_tasks) == 0:
continue
else:
console.print(f"[bold]{task_type}[/]")
for task in current_type_tasks:
for (
task
) in current_type_tasks: # will be sorted as input to this function
prefix = " - "
name = f"{task.metadata.name}"
category = f", [italic grey39]{task.metadata.category}[/]"
Expand All @@ -170,7 +175,28 @@ def _display_tasks(self, task_list, name=None):

def mteb_benchmarks(self):
"""Get all benchmarks available in the MTEB."""
for benchmark in self._tasks:
from mteb.overview import MTEBTasks

# get all the MTEB specific benchmarks:
mteb_tasks = [t for t in self._tasks]
sathviknallamalli marked this conversation as resolved.
Show resolved Hide resolved

mteb_tasks, remaining_tasks = (
[t for t in self._tasks if "MTEB" in t.name],
[t for t in self._tasks if "MTEB" not in t.name],
)
sathviknallamalli marked this conversation as resolved.
Show resolved Hide resolved

mteb_tasks = sorted(mteb_tasks, key=lambda obj: obj.name.lower())
remaining_tasks = sorted(remaining_tasks, key=lambda obj: obj.name.lower())
sathviknallamalli marked this conversation as resolved.
Show resolved Hide resolved

sorted_tasks = mteb_tasks + remaining_tasks

# task ordering within each benchmark should be alphabetical
for st in sorted_tasks:
st.tasks = MTEBTasks(
sorted(st.tasks, key=lambda obj: obj.metadata.name.lower())
)

for benchmark in sorted_tasks:
sathviknallamalli marked this conversation as resolved.
Show resolved Hide resolved
name = benchmark.name
self._display_tasks(benchmark.tasks, name=name)

Expand Down
Loading