File size: 1,030 Bytes
81663e8 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | """The Task API serves names and instructions, never private verifier answers."""
import os
from functools import lru_cache
from .tasks import load_tasks
@lru_cache
def tasks(split):
if split not in {"train", "test"}:
raise ValueError("Choose train or test")
return load_tasks(os.environ.get("SMOLDATA_DATA", "prepared"), split)
def task_by_name(split, name):
return next(row for row in tasks(split) if row["name"] == name)
class TaskCatalog:
def list_splits(self):
return ["train", "test"]
def num_tasks(self, split):
return len(tasks(split))
def get_task(self, split, index):
return {
key: value for key, value in tasks(split)[index].items() if key != "folder"
}
def get_task_range(self, split, start=None, stop=None):
return [
self.get_task(split, i)
for i in range(*slice(start, stop).indices(self.num_tasks(split)))
]
def list_tasks(self, split):
return self.get_task_range(split)
|