<reponame>iganichev/scratch
import time
import numpy as np
import reader

def run_epoch(session, m, data, eval_op, max_steps=None, verbose=False):
    """Runs the model on the given data."""
    epoch_size = ((len(data) // m.batch_size) - 1) // m.num_steps
    start_time = time.time()
    costs = 0.0
    iters = 0
    num_batch_steps_completed = 0

    for step, (x, y) in enumerate(reader.ptb_iterator(data, m.batch_size, m.num_steps)):
        # y is just x shifted by 1. Each datapoint in x and y is just a 1D
        # array of word ids.
        cost, state, _ = session.run([m.cost, m.final_state, eval_op],
                                     {m.input_data: x,
                                      m.targets: y})
        costs += cost
        iters += m.num_steps
        num_batch_steps_completed += 1

        #if verbose and step % (epoch_size // 10) == 10:
        print("%.3f perplexity: %.3f speed: %.0f wps" %
              (step * 1.0 / epoch_size, np.exp(costs / iters),
               iters * m.batch_size / (time.time() - start_time)))

        if iters > max_steps:
            break

    return (costs / iters)




import time
import numpy as np
import reader

def run_epoch(session, m, data, eval_op, max_steps=None, verbose=False):
    """Runs the model on the given data."""
    epoch_size = ((len(data) // m.batch_size) - 1) // m.num_steps
    start_time = time.time()
    costs = 0.0
    iters = 0
    num_batch_steps_completed = 0

    for step, (x, y) in enumerate(reader.ptb_iterator(data, m.batch_size, m.num_steps)):
        # y is just x shifted by 1. Each datapoint in x and y is just a 1D
        # array of word ids.
        cost, state, _ = session.run([m.cost, m.final_state, eval_op],
                                     {m.input_data: x,
                                      m.targets: y})
        costs += cost
        iters += m.num_steps
        num_batch_steps_completed += 1

        #if verbose and step % (epoch_size // 10) == 10:
        print("%.3f perplexity: %.3f speed: %.0f wps" %
              (step * 1.0 / epoch_size, np.exp(costs / iters),
               iters * m.batch_size / (time.time() - start_time)))

        if iters > max_steps:
            break

    return (costs / iters)
Runs the model on the given data. # y is just x shifted by 1. Each datapoint in x and y is just a 1D # array of word ids. #if verbose and step % (epoch_size // 10) == 10: