MCPcopy Create free account
hub / github.com/AIS-SNU/Smart-Infinity / write_predictions

Function write_predictions

DeepSpeedExample/tasks/ensemble_classifier.py:93–117  ·  view source on GitHub ↗
(all_predictions, all_labels, all_uid, args)

Source from the content-addressed store, hash-verified

91
92
93def 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
120def ensemble_predictions(args):

Callers 1

ensemble_predictionsFunction · 0.85

Calls 4

meanMethod · 0.80
makedirsMethod · 0.80
existsMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected