Example #1
0
 def testAscendingValTol0(self):
     g = tf.Graph()
     with g.as_default():
         output = py_x_ops.best_step(self._BleuFile(), 0.0, False)
     with self.session(graph=g) as sess:
         best_step, last_step = sess.run(output)
         self.assertEqual(best_step, 41500)
         self.assertEqual(last_step, 46800)
Example #2
0
 def testNoFile(self):
     g = tf.Graph()
     with g.as_default():
         output = py_x_ops.best_step('')
     with self.session(graph=g) as sess:
         best_step, last_step = sess.run(output)
         self.assertEqual(best_step, 0)
         self.assertEqual(last_step, 0)
Example #3
0
 def testTolNon0(self):
     g = tf.Graph()
     with g.as_default():
         output = py_x_ops.best_step(self._HistFile(), 0.1)
     with self.session(graph=g) as sess:
         best_step, last_step = sess.run(output)
         self.assertEqual(best_step, 37553)
         self.assertEqual(last_step, 42792)
Example #4
0
 def testTfEventAscendingValTol0(self):
   g = tf.Graph()
   with g.as_default():
     output = py_x_ops.best_step(self._TfEventFile(), 0.0, False, 'bleu/dev')
   with self.session(graph=g) as sess:
     best_step, last_step = sess.run(output)
     self.assertEqual(best_step, 102600)
     self.assertEqual(last_step, 185200)
Example #5
0
  def FProp(self, theta):
    """Creates an op to determine the best step from the metric history file.

    Args:
      theta: Not currently used.
    Returns:
      The created op.

    This uses BestStepOp rather than reading the file directly from python in
    order to ensure compatibility with DevBasedSchedule for learning-rate decay.
    It is natural to use dev-based decay and early stopping together, for
    example decaying when dev-set perplexity hasn't improved for n steps, and
    stopping when it hasn't improved for 3n steps.
    """
    del theta  # not used
    if self.params.window:
      self._node = py_x_ops.best_step(
          self.metric_history.hist_file, self.params.tolerance,
          self.metric_history.minimize, self.metric_history.metric)
    else:
      self._node = None
    return self._node
Example #6
0
    def __init__(self, params):
        super(DevBasedSchedule, self).__init__(params)

        p = self.params

        with tf.variable_scope(p.name):
            wp = py_utils.WeightParams(shape=[],
                                       init=py_utils.WeightInit.Constant(1.0),
                                       collections=['DevBasedSchedule_vars'],
                                       dtype=tf.float32)
            _, self._cur_factor, = py_utils.CreateVariable('cur_factor',
                                                           wp,
                                                           trainable=False)
            wp = py_utils.WeightParams(shape=[],
                                       init=py_utils.WeightInit.Constant(0),
                                       collections=['DevBasedSchedule_vars'],
                                       dtype=tf.int64)
            _, self._ref_step, = py_utils.CreateVariable('ref_step',
                                                         wp,
                                                         trainable=False)

            self._metric_history = early_stop.MetricHistory(p.metric_history)
            self._best_step = py_x_ops.best_step(
                self._metric_history.hist_file, p.tolerance)