File size: 1,825 Bytes
6efeebe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import argparse
import json
import os
import sys

pwd = os.path.abspath(os.path.dirname(__file__))
sys.path.append(os.path.join(pwd, "../../"))

from tqdm import tqdm


def get_args():
    parser = argparse.ArgumentParser()

    parser.add_argument(
        "--eval_file",
        default=r"evaluation.jsonl",
        type=str
    )
    args = parser.parse_args()
    return args


def main():
    args = get_args()

    total = 0
    total_duration = 0
    total_accuracy = 0
    total_precision = 0
    total_recall = 0
    total_f1 = 0
    progress_bar = tqdm(desc="evaluation")
    with open(args.eval_file, "r", encoding="utf-8") as f:
        for row in f:
            row = json.loads(row)
            duration = row["duration"]
            accuracy = row["accuracy"]
            precision = row["precision"]
            recall = row["recall"]
            f1 = row["f1"]

            total += 1
            total_duration += duration
            total_accuracy += accuracy * duration
            total_precision += precision * duration
            total_recall += recall * duration
            total_f1 += f1 * duration

            average_accuracy = total_accuracy / total_duration
            average_precision = total_precision / total_duration
            average_recall = total_recall / total_duration
            average_f1 = total_f1 / total_duration

            progress_bar.update(1)
            progress_bar.set_postfix({
                "total": total,
                "accuracy": average_accuracy,
                "precision": average_precision,
                "recall": average_recall,
                "f1": average_f1,
                "total_duration": f"{round(total_duration / 60, 4)}min",
            })
    return


if __name__ == "__main__":
    main()