def _prepare(self): """ Prepares for evaluation. Builds the model with reuse=True, mode=EVAL and preprocesses data file(s). Furthermore, if the decay_type of optimizer is "loss_decay", creates the controller variables/operations. """ features_file = self._dataset["features_file"] labels_file = self._dataset["labels_file"] vocab_source = self._dataset["vocab_source"] vocab_target = self._dataset["vocab_target"] text_inputter = ParallelTextInputter( LineReader(data=features_file, preprocessing_fn=lambda x: vocab_source.convert_to_idlist(x)), LineReader(data=labels_file, preprocessing_fn=lambda x: vocab_target.convert_to_idlist(x)), vocab_source.pad_id, vocab_target.pad_id, batch_size=self._batch_size, batch_tokens_size=None, shuffle_every_epoch=None, bucketing=True) estimator_spec = model_fn( model_configs=self._model_configs, mode=ModeKeys.EVAL, vocab_source=vocab_source, vocab_target=vocab_target, name=self._model_name, reuse=True, verbose=False) self._eval_feeding_data = text_inputter.make_feeding_data( input_fields=estimator_spec.input_fields, in_memory=True) self._loss_op = estimator_spec.loss # for learning decay decay self._half_lr = False self._start_decay_at = 0 if self._model_configs["optimizer_params"]["optimizer.lr_decay"]["decay_type"] == "loss_decay": self._half_lr = True lr_tensor_dict = get_dict_from_collection(Constants.LEARNING_RATE_VAR_NAME) self._learning_rate = lr_tensor_dict[Constants.LEARNING_RATE_VAR_NAME] self._max_patience = self._model_configs["optimizer_params"]["optimizer.lr_decay"]["patience"] self._start_decay_at = self._model_configs["optimizer_params"]["optimizer.lr_decay"]["start_decay_at"] assert self._start_decay_at >= self._start_at, ( "start_decay_at in optimizer.lr_decay should be no less than start_at in LossMetricSpec.") self._half_lr_op = lr_tensor_dict[Constants.LR_AUTO_HALF_OP_NAME] self._bad_count = 0 self._min_loss = 10000.
def _prepare(self): """ Prepares for evaluation. Builds the model with reuse=True, mode=EVAL and preprocesses data file(s). Furthermore, if the decay_type of optimizer is "loss_decay", creates the controller variables/operations. """ text_inputter = ParallelTextInputter( dataset=self._dataset, features_field_name="eval_features_file", labels_field_name="eval_labels_file", batch_size=self._batch_size, batch_tokens_size=None, shuffle_every_epoch=None, bucketing=True) estimator_spec = model_fn(model_configs=self._model_configs, mode=ModeKeys.EVAL, dataset=self._dataset, name=self._model_name, reuse=True, verbose=False) self._eval_feeding_data = text_inputter.make_feeding_data( input_fields=estimator_spec.input_fields, in_memory=True) self._loss_op = estimator_spec.loss # for learning decay decay self._half_lr = False self._start_decay_at = 0 if self._model_configs["optimizer_params"]["optimizer.lr_decay"][ "decay_type"] == "loss_decay": self._half_lr = True lr_tensor_dict = get_dict_from_collection( Constants.LEARNING_RATE_VAR_NAME) self._learning_rate = lr_tensor_dict[ Constants.LEARNING_RATE_VAR_NAME] self._max_patience = self._model_configs["optimizer_params"][ "optimizer.lr_decay"]["patience"] self._start_decay_at = self._model_configs["optimizer_params"][ "optimizer.lr_decay"]["start_decay_at"] assert self._start_decay_at >= self._start_at, ( "start_decay_at in optimizer.lr_decay should be no less than start_at in LossMetricSpec." ) div_factor = lr_tensor_dict[Constants.LR_ANNEAL_DIV_FACTOR_NAME] self._half_lr_op = div_factor.assign(div_factor * 2.) self._bad_count = 0 self._min_loss = 10000.
def _prepare(self): """ Prepares for evaluation. Builds the model with reuse=True, mode=EVAL and preprocesses data file(s). Furthermore, if the decay_type of optimizer is "loss_decay", creates the controller variables/operations. """ text_inputter = ParallelTextInputter( dataset=self._dataset, features_field_name="eval_features_file", labels_field_name="eval_labels_file", batch_size=self._batch_size, batch_tokens_size=None, shuffle_every_epoch=None, bucketing=True) estimator_spec = model_fn( model_configs=self._model_configs, mode=ModeKeys.EVAL, dataset=self._dataset, name=self._model_name, reuse=True, verbose=False) self._eval_feeding_data = text_inputter.make_feeding_data( input_fields=estimator_spec.input_fields, in_memory=True) self._loss_op = estimator_spec.loss # for learning decay decay self._half_lr = False self._start_decay_at = 0 if self._model_configs["optimizer_params"]["optimizer.lr_decay"]["decay_type"] == "loss_decay": self._half_lr = True lr_tensor_dict = get_dict_from_collection(Constants.LEARNING_RATE_VAR_NAME) self._learning_rate = lr_tensor_dict[Constants.LEARNING_RATE_VAR_NAME] self._max_patience = self._model_configs["optimizer_params"]["optimizer.lr_decay"]["patience"] self._start_decay_at = self._model_configs["optimizer_params"]["optimizer.lr_decay"]["start_decay_at"] assert self._start_decay_at >= self._start_at, ( "start_decay_at in optimizer.lr_decay should be no less than start_at in LossMetricSpec.") div_factor = lr_tensor_dict[Constants.LR_ANNEAL_DIV_FACTOR_NAME] self._half_lr_op = div_factor.assign(div_factor * 2.) self._bad_count = 0 self._min_loss = 10000.