def sample_predict(sess, model, batch_size, ckpt_file, eval_mode):
    load_model(sess, model, ckpt_file, eval_mode)
    data_size = len(model.input_data)
    (feed_dict, data_dict) = generate_feed_dict(model, data_size, batch_size)
    sess.run(model.data_pipeline.initializer, feed_dict=feed_dict)
    predict_span = []
    while True:
        try:
            infer_result = model.model.infer(sess, model.word_embedding)
            predict_span.extend(infer_result.predict)
        except tf.errors.OutOfRangeError:
            break
    predict_size = len(predict_span)
    if (data_size != predict_size):
        raise ValueError('input data size {0} and output data size {1} is not the same'.format(data_size, predict_size))
    sample_result = []
    for i in range(data_size):
        sample_id = data_dict['input_data'][i]['id']
        context = data_dict['input_context'][i]
        context_tokens = context.split(' ')
        predict_start = int(predict_span[i][0])
        predict_end = int(predict_span[i][1])
        predict = ' '.join(context_tokens[predict_start:(predict_end + 1)])
        sample_result.append({'id': sample_id, 'context': context, 'predict': {'text': predict, 'start': predict_start, 'end': predict_end}, 'answers': []})
        for answer in data_dict['input_data'][i]['answers']:
            label_start = int(answer['start'])
            label_end = int(answer['end'])
            label = ' '.join(context_tokens[label_start:(label_end + 1)])
            sample_result[(- 1)]['answers'].append({'text': label, 'start': label_start, 'end': label_end})
    return sample_result
def sample_predict(sess, model, batch_size, ckpt_file, eval_mode):
    load_model(sess, model, ckpt_file, eval_mode)
    data_size = len(model.input_data)
    (feed_dict, data_dict) = generate_feed_dict(model, data_size, batch_size)
    sess.run(model.data_pipeline.initializer, feed_dict=feed_dict)
    predict_span = []
    while True:
        try:
            infer_result = model.model.infer(sess, model.word_embedding)
            predict_span.extend(infer_result.predict)
        except tf.errors.OutOfRangeError:
            break
    predict_size = len(predict_span)
    if (data_size != predict_size):
        raise ValueError('input data size {0} and output data size {1} is not the same'.format(data_size, predict_size))
    sample_result = []
    for i in range(data_size):
        sample_id = data_dict['input_data'][i]['id']
        context = data_dict['input_context'][i]
        context_tokens = context.split(' ')
        predict_start = int(predict_span[i][0])
        predict_end = int(predict_span[i][1])
        predict = ' '.join(context_tokens[predict_start:(predict_end + 1)])
        sample_result.append({'id': sample_id, 'context': context, 'predict': {'text': predict, 'start': predict_start, 'end': predict_end}, 'answers': []})
        for answer in data_dict['input_data'][i]['answers']:
            label_start = int(answer['start'])
            label_end = int(answer['end'])
            label = ' '.join(context_tokens[label_start:(label_end + 1)])
            sample_result[(- 1)]['answers'].append({'text': label, 'start': label_start, 'end': label_end})
    return sample_result