Exemplo n.º 1
0
 def testAscendingValTol0(self):
     g = tf.Graph()
     with g.as_default():
         output = 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)
Exemplo n.º 2
0
 def testTfEventAscendingValTol0(self):
     g = tf.Graph()
     with g.as_default():
         output = 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)
Exemplo n.º 3
0
 def testNoFile(self):
     g = tf.Graph()
     with g.as_default():
         output = 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)
Exemplo n.º 4
0
 def testTolNon0(self):
     g = tf.Graph()
     with g.as_default():
         output = 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)
Exemplo n.º 5
0
 def testTol0(self):
     g = tf.Graph()
     with g.as_default():
         output = ops.best_step(self._HistFile())
     with self.session(graph=g):
         best_step, last_step = self.evaluate(output)
         self.assertEqual(best_step, 42122)
         self.assertEqual(last_step, 42792)
Exemplo n.º 6
0
 def _CreateLayerVariables(self):
     p = self.params
     wp = py_utils.WeightParams(shape=[],
                                init=py_utils.WeightInit.Constant(1.0),
                                collections=['DevBasedSchedule_vars'],
                                dtype=tf.float32)
     self.CreateVariable('cur_factor', wp, trainable=False)
     wp = py_utils.WeightParams(shape=[],
                                init=py_utils.WeightInit.Constant(0),
                                collections=['DevBasedSchedule_vars'],
                                dtype=tf.int64)
     self.CreateVariable('ref_step', wp, trainable=False)
     self._best_step = ops.best_step(self._metric_history.hist_file,
                                     p.tolerance)
Exemplo n.º 7
0
  def __init__(self, params):
    super().__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 = ops.best_step(self._metric_history.hist_file,
                                      p.tolerance)
Exemplo n.º 8
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 = 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
Exemplo n.º 9
0
 def BestStep():
   return ops.best_step(self.metric_history.hist_file,
                        self.params.tolerance,
                        self.metric_history.minimize,
                        self.metric_history.metric)