# Buggy code
def format_metrics(self, logs={}, factor=1):
    """Format metrics in logs into a string.

    Arguments:
        logs: dictionary of metrics and their values. Defaults to
            empty dictionary.
        factor (int): The factor we want to divide the metrics in logs
            by, useful when we are computing the logs after each batch.
            Defaults to 1.

    Returns:
        metrics_string: a string displaying metrics using the given
        formators passed in through the constructor.
    """

    metric_value_pairs = []
    for metric in self.metrics:
        if metric in logs:
            value = logs[metric] / factor
            pair = self.metrics_format.format(name=metric, value=value)
            metric_value_pairs.append(pair)
    metrics_string = self.metrics_separator.join(metric_value_pairs)
    return metrics_string


# Traceback (KeyError)
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-23-fdbb03f574a1> in <module>
48 #   class_weight=class_weights,
49     verbose=VERBOSE,
---> 50     callbacks=model_callbacks,
51 )

~/.pyenv/versions/3.7.6/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py in _method_wrapper(self, *args, **kwargs)
63   def _method_wrapper(self, *args, **kwargs):
64     if not self._in_multi_worker_mode():  # pylint: disable=protected-access
---> 65       return method(self, *args, **kwargs)
66
67     # Running inside `run_distribute_coordinator` already.

~/.pyenv/versions/3.7.6/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_batch_size, validation_freq, max_queue_size, workers, use_multiprocessing, **kwargs)
763       self.stop_training = False
764       train_function = self.make_train_function()
--> 765       callbacks.on_train_begin()
766       # Handle fault-tolerance for multi-worker.
767       # TODO(omalleyt): Fix the ordering issues that mean this has to

~/.pyenv/versions/3.7.6/lib/python3.7/site-packages/tensorflow/python/keras/callbacks.py in on_train_begin(self, logs)
445     logs = self._process_logs(logs)
446     for callback in self.callbacks:
--> 447       callback.on_train_begin(logs)
448
449   def on_train_end(self, logs=None):

~/.pyenv/versions/3.7.6/lib/python3.7/site-packages/tensorflow_addons/callbacks/tqdm_progress_bar.py in on_train_begin(self, logs)
100     def on_train_begin(self, logs=None):
101         self.num_epochs = self.params["epochs"]
--> 102         self.metrics = self.params["metrics"]
103
104         if self.show_overall_progress:

KeyError: 'metrics'

# Fixed code
def format_metrics(self, logs={}, factor=1):
    """Format metrics in logs into a string.

    Arguments:
        logs: dictionary of metrics and their values. Defaults to
            empty dictionary.
        factor (int): The factor we want to divide the metrics in logs
            by, useful when we are computing the logs after each batch.
            Defaults to 1.

    Returns:
        metrics_string: a string displaying metrics using the given
        formators passed in through the constructor.
    """

    metric_value_pairs = []
    for key, value in logs.items():
        if key in ["batch", "size"]:
            continue
        pair = self.metrics_format.format(name=key, value=value / factor)
        metric_value_pairs.append(pair)
    metrics_string = self.metrics_separator.join(metric_value_pairs)
    return metrics_string