bert_max_doc_str_max_str_pos_clean_doc_noise_doc/run_doc_qa.py
def run_epoch(model, session, data_container, learning_rate, opt_op, mode,
              model_saver=None, verbose=True, eval_func=None):
    """Runs one epoch over the data."""
    start_time = time.time()
    iter_count = 1

    process_sample_cnt = 0

    # Starts a new epoch.
    data_container.start_epoch()

    total_loss = 0.0

    for feature_dict in data_container.extract_batches(mode):

        fetched_dict = model.one_step(session, feature_dict, opt_op)
        total_loss += fetched_dict['loss_to_opt']

        iter_count += 1

        process_sample_cnt += feature_dict['num_sample']

        if (iter_count) % 1000 == 0:
            if verbose:
                tf.logging.info(
                    'iter {:d}:, {:.3f} examples per second'.format(
                        iter_count,
                        process_sample_cnt / (time.time() - start_time)
                    )
                )
                tf.logging.info(
                    'loss {:.3f}'.format(fetched_dict['loss_to_opt'])
                )

            if model_saver:
                global_step = session.run(tf.train.get_global_step())
                model_saver.save(
                    session,
                    os.path.join(FLAGS.output_dir, 'model.ckpt'),
                    global_step=global_step
                )

    tf.logging.info(
        'time for one epoch: {:.3f} secs'.format(time.time() - start_time)
    )
    tf.logging.info('iters over {0} num of samples'.format(process_sample_cnt))

    eval_metric = {'total_loss': total_loss}
    output_dict = {}

    return total_loss, eval_metric, output_dict
Runs one epoch over the data.
Runs one epoch over the data.
Runs one epoch over the data .
def run_epoch(model, session, data_container, learning_rate, opt_op, mode,
              model_saver=None, verbose=True, eval_func=None):
    start_time = time.time()
    iter_count = 1
    process_sample_cnt = 0
    data_container.start_epoch()
    total_loss = 0.0
    for feature_dict in data_container.extract_batches(mode):
        fetched_dict = model.one_step(session, feature_dict, opt_op)
        total_loss += fetched_dict['loss_to_opt']
        iter_count += 1
        process_sample_cnt += feature_dict['num_sample']
        if (iter_count) % 1000 == 0:
            if verbose:
                tf.logging.info(
                    'iter {:d}:, {:.3f} examples per second'.format(
                        iter_count,
                        process_sample_cnt / (time.time() - start_time)
                    )
                )
                tf.logging.info(
                    'loss {:.3f}'.format(fetched_dict['loss_to_opt'])
                )
            if model_saver:
                global_step = session.run(tf.train.get_global_step())
                model_saver.save(
                    session,
                    os.path.join(FLAGS.output_dir, 'model.ckpt'),
                    global_step=global_step
                )
    tf.logging.info(
        'time for one epoch: {:.3f} secs'.format(time.time() - start_time)
    )
    tf.logging.info('iters over {0} num of samples'.format(process_sample_cnt))
    eval_metric = {'total_loss': total_loss}
    output_dict = {}
    return total_loss, eval_metric, output_dict
def run_epoch ( model , session , data_container , learning_rate , opt_op , mode , model_saver = None , verbose = True , eval_func = None ) : start_time = time . time ( ) iter_count = 1 process_sample_cnt = 0 data_container . start_epoch ( ) total_loss = 0.0 for feature_dict in data_container . extract_batches ( mode ) : fetched_dict = model . one_step ( session , feature_dict , opt_op ) total_loss += fetched_dict [ 'loss_to_opt' ] iter_count += 1 process_sample_cnt += feature_dict [ 'num_sample' ] if ( iter_count ) % 1000 == 0 : if verbose : tf . logging . info ( 'iter {:d}:, {:.3f} examples per second' . format ( iter_count , process_sample_cnt / ( time . time ( ) - start_time ) ) ) tf . logging . info ( 'loss {:.3f}' . format ( fetched_dict [ 'loss_to_opt' ] ) ) if model_saver : global_step = session . run ( tf . train . get_global_step ( ) ) model_saver . save ( session , os . path . join ( FLAGS . output_dir , 'model.ckpt' ) , global_step = global_step ) tf . logging . info ( 'time for one epoch: {:.3f} secs' . format ( time . time ( ) - start_time ) ) tf . logging . info ( 'iters over {0} num of samples' . format ( process_sample_cnt ) ) eval_metric = { 'total_loss' : total_loss } output_dict = { } return total_loss , eval_metric , output_dict
Runs one epoch over the data.
Runs one epoch over the data .
"""Runs one epoch over the data.""" # Starts a new epoch.
model
session
data_container
learning_rate
opt_op
mode
model_saver
verbose
eval_func