MCPcopy Create free account
hub / github.com/PaddlePaddle/Research / predict

Function predict

NLP/ACL2019-KTNET/reading_comprehension/src/run_record.py:245–284  ·  view source on GitHub ↗
(test_exe, test_program, test_pyreader, fetch_list, processor, eval_concept_settings, eval_output_name='eval_result.json')

Source from the content-addressed store, hash-verified

243
244
245def predict(test_exe, test_program, test_pyreader, fetch_list, processor, eval_concept_settings, eval_output_name='eval_result.json'):
246 if not os.path.exists(args.checkpoints):
247 os.makedirs(args.checkpoints)
248 output_prediction_file = os.path.join(args.checkpoints, "predictions.json")
249 output_nbest_file = os.path.join(args.checkpoints, "nbest_predictions.json")
250 output_null_log_odds_file = os.path.join(args.checkpoints, "null_odds.json")
251 output_evaluation_result_file = os.path.join(args.checkpoints, eval_output_name)
252
253 test_pyreader.start()
254 all_results = []
255 time_begin = time.time()
256 while True:
257 try:
258 np_unique_ids, np_start_logits, np_end_logits, np_num_seqs = test_exe.run(
259 fetch_list=fetch_list, program=test_program)
260 for idx in range(np_unique_ids.shape[0]):
261 if len(all_results) % 1000 == 0:
262 logger.info("Processing example: %d" % len(all_results))
263 unique_id = int(np_unique_ids[idx])
264 start_logits = [float(x) for x in np_start_logits[idx].flat]
265 end_logits = [float(x) for x in np_end_logits[idx].flat]
266 all_results.append(
267 RawResult(
268 unique_id=unique_id,
269 start_logits=start_logits,
270 end_logits=end_logits))
271 except fluid.core.EOFException:
272 test_pyreader.reset()
273 break
274 time_end = time.time()
275
276 features = processor.get_features(
277 processor.predict_examples, is_training=False, **eval_concept_settings)
278 eval_result = write_predictions(processor.predict_examples, features, all_results,
279 args.n_best_size, args.max_answer_length,
280 args.do_lower_case, output_prediction_file,
281 output_nbest_file, output_null_log_odds_file,
282 args.version_2_with_negative,
283 args.null_score_diff_threshold, args.verbose, args.predict_file, output_evaluation_result_file)
284 return eval_result
285
286def read_concept_embedding(embedding_path):
287 fin = open(embedding_path, encoding='utf-8')

Callers 1

trainFunction · 0.70

Calls 6

write_predictionsFunction · 0.90
startMethod · 0.45
runMethod · 0.45
appendMethod · 0.45
resetMethod · 0.45
get_featuresMethod · 0.45

Tested by

no test coverage detected