(all_predictions, all_labels, all_uid, args)
| 91 | |
| 92 | |
| 93 | def write_predictions(all_predictions, all_labels, all_uid, args): |
| 94 | all_correct = 0 |
| 95 | count = 0 |
| 96 | for dataset in all_predictions: |
| 97 | preds = all_predictions[dataset] |
| 98 | preds = np.argmax(preds, -1) |
| 99 | if args.eval: |
| 100 | correct = (preds == all_labels[dataset]).sum() |
| 101 | num = len(all_labels[dataset]) |
| 102 | accuracy = correct / num |
| 103 | count += num |
| 104 | all_correct += correct |
| 105 | accuracy = (preds == all_labels[dataset]).mean() |
| 106 | print(accuracy) |
| 107 | if not os.path.exists(os.path.join(args.outdir, dataset)): |
| 108 | os.makedirs(os.path.join(args.outdir, dataset)) |
| 109 | outpath = os.path.join( |
| 110 | args.outdir, dataset, os.path.splitext( |
| 111 | args.prediction_name)[0] + '.tsv') |
| 112 | with open(outpath, 'w') as f: |
| 113 | f.write('id\tlabel\n') |
| 114 | f.write('\n'.join(str(uid) + '\t' + str(args.labels[p]) |
| 115 | for uid, p in zip(all_uid[dataset], preds.tolist()))) |
| 116 | if args.eval: |
| 117 | print(all_correct / count) |
| 118 | |
| 119 | |
| 120 | def ensemble_predictions(args): |
no test coverage detected