def _build_callbacks(self, val_batched):
    """Build the callbacks used during training."""
    cns_model_checkpoint = util.safe_path(
        os.path.join(self._model_config.model_checkpoint, 'best_model.tf'))
    model_callbacks = [
        # Note: Order matters here, particularly that FeverMetricsCallback
        # comes before tensorboard so it can write to the log dictionary
        # and TB picks it up.
        callbacks.FeverMetricsCallback(
            validation_batched=val_batched,
            debug=self._debug,
            fever_dev_path=self._model_config.fever_dev_path,
            max_evidence=self._model_config.max_evidence,
            checkpoint_dir=self._model_config.model_checkpoint,
        ),
        # TODO(perodriguez): Determine a better thing to stop on
        tf.keras.callbacks.EarlyStopping(
            monitor='val_loss',
            min_delta=.001,
            patience=3,
            verbose=1,
            mode='min'),
        # TODO(perodriguez): Determine a better thing to save on
        # Checkpointing also needs to know about fever recall.
        tf.keras.callbacks.ModelCheckpoint(
            filepath=cns_model_checkpoint,
            save_best_only=True,
            monitor='val_loss',
            mode='min',
            verbose=1,
            # There is no support for GRU/LSTM Dropout with normal save
            save_weights_only=True,
        ),
    ]

    if self._tb_log_dir is not None:
      model_callbacks.append(
          tf.keras.callbacks.TensorBoard(log_dir=self._tb_log_dir))
    return model_callbacks
Build the callbacks used during training.
language/serene/training.py