|
|
|
|
|
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() |
|
|