make_table_tasks.py 1.33 KB
Newer Older
jon-tow's avatar
jon-tow committed
1
2
3
4
"""
Usage:
   python make_table_tasks.py --output <markdown_filename>
"""
5

jon-tow's avatar
jon-tow committed
6
7
import argparse
import logging
8

Leo Gao's avatar
Leo Gao committed
9
10
from pytablewriter import MarkdownTableWriter

11
12
from lm_eval import tasks

Leo Gao's avatar
Leo Gao committed
13

jon-tow's avatar
jon-tow committed
14
15
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
Leo Gao's avatar
Leo Gao committed
16

Fabrizio Milo's avatar
Fabrizio Milo committed
17

jon-tow's avatar
jon-tow committed
18
def check(tf):
Leo Gao's avatar
Leo Gao committed
19
    if tf:
Fabrizio Milo's avatar
Fabrizio Milo committed
20
        return "✓"
Leo Gao's avatar
Leo Gao committed
21
    else:
Fabrizio Milo's avatar
Fabrizio Milo committed
22
23
        return " "

Leo Gao's avatar
Leo Gao committed
24

jon-tow's avatar
jon-tow committed
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("--output", type=str, default="task_table.md")
    args = parser.parse_args()

    writer = MarkdownTableWriter()
    writer.headers = ["Task Name", "Train", "Val", "Test", "Val/Test Docs", "Metrics"]
    values = []

    tasks = tasks.TASK_REGISTRY.items()
    tasks = sorted(tasks, key=lambda x: x[0])
    for tname, Task in tasks:
        task = Task()
        v = [
            tname,
            check(task.has_training_docs()),
            check(task.has_validation_docs()),
            check(task.has_test_docs()),
            len(
                list(
                    task.test_docs() if task.has_test_docs() else task.validation_docs()
                )
            ),
            ", ".join(task.aggregation().keys()),
        ]
        logger.info(v)
        values.append(v)
    writer.value_matrix = values
    table = writer.dumps()
54
    with open(args.output, "w", encoding="utf-8") as f:
jon-tow's avatar
jon-tow committed
55
        f.write(table)