File size: 1,395 Bytes
cf5659c |
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 |
import json
import os
from argparse import ArgumentParser
from matplotlib import pyplot as plt
def get_args():
parser = ArgumentParser()
parser.add_argument('--input-files', type=lambda s: s.split(','), required=True, help='Input files that hold all evaluation metrics')
return parser.parse_args()
def main():
args = get_args()
plots = {} # {"{EVALUATION}_{METRIC}": plt.figure}
for input_file in args.input_files:
assert os.path.basename(input_file).endswith("_agg.json")
experiment_name = os.path.basename(input_file).split("_agg.json")[0]
with open(input_file, "r") as fi:
experiment = json.load(fi)
tokens = experiment["tokens"]
for evaluation_name, evaluation in experiment["results"].items():
for metric_name, metric in evaluation.items():
key = f"{evaluation_name}_{metric_name}"
if key[-7:] == "_stderr":
continue
if key not in plots:
plot = plt.figure(len(plots))
plot = plot.add_subplot(1,1,1)
plot.set_title(key)
plots[key] = plot
plot = plots[key]
plot.plot(tokens, metric, label=experiment_name)
for plot in plots.values():
plot.legend()
plt.show()
if __name__ == "__main__":
main()
|