| import json |
| |
| |
| import sys |
| |
| |
| |
| def eval_codesymbols(inp_path): |
| with open(inp_path,'r') as f: |
| lines = f.readlines() |
| lines = [json.loads(x) for x in lines] |
| print("len(lines):",len(lines)) |
|
|
| rst = {} |
| for i,l in enumerate(lines): |
| this_rst = {"true": [], "false": [], "acc": 0.0} |
| ground_output = l['output'] |
| preds = l["out_str"] |
| metadata = l['metadata'] |
| symbol_dict = metadata['symbol_dict'] |
| symbol2location = {e['symbol']: e['location'] for e in symbol_dict} |
| for e in ground_output: |
| if e in preds: |
| this_rst["true"].append((e, symbol2location[e])) |
| else: |
| this_rst["false"].append((e, symbol2location[e])) |
| acc = len(this_rst["true"]) / (len(this_rst["true"]) + len(this_rst["false"])) |
| this_rst["acc"] = acc |
| rst[i] = this_rst |
| total_acc = sum([rst[i]["acc"] for i in rst]) / len(rst) |
| print(f"total acc: {total_acc}") |
| all_true = [rst[i]['true'] for i in range(len(rst))] |
| all_true = [e for ee in all_true for e in ee] |
| all_true_location = [e[1] for e in all_true] |
|
|
| all_false = [rst[i]['false'] for i in range(len(rst))] |
| all_false = [e for ee in all_false for e in ee] |
| all_false_location = [e[1] for e in all_false] |
| |
| |
|
|
| print(max(all_true_location), min(all_true_location), max(all_false_location), min(all_false_location)) |
|
|
| |
| |
| for i in range(20): |
| this_true = [e for e in all_true_location if e >= i*1000 and e < (i+1)*1000] |
| this_false = [e for e in all_false_location if e >= i*1000 and e < (i+1)*1000] |
| if len(this_true) + len(this_false) == 0: |
| this_acc = 0 |
| else: |
| this_acc = len(this_true) / (len(this_true) + len(this_false)) |
| print(f"range {i*1000}-{(i+1)*1000} acc: {this_acc} true: {len(this_true)} false: {len(this_false)}") |
|
|
|
|
| if __name__ == "__main__": |
| args = sys.argv |
| inp_path = args[1] |
| eval_codesymbols(inp_path) |