<commit_before># -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function

from polyaxon_client.exceptions import PolyaxonClientException

try:
    from fastai.callbacks import TrackerCallback
except ImportError:
    raise PolyaxonClientException('Fastai is required to use PolyaxonFastai')


class PolyaxonFastai(TrackerCallback):

    def __init__(self, learn, experiment, monitor='val_loss', mode='auto'):
        super().__init__(learn, monitor=monitor, mode=mode)
        self.experiment = experiment

    def on_epoch_end(self, epoch, smooth_loss, last_metrics, **kwargs):
        metrics = {
            name: stat for name, stat in
            list(zip(self.learn.recorder.names, [epoch, smooth_loss] + last_metrics))[1:]
        }

        self.experiment.log_metrics(**metrics)<commit_msg>Make fastai callback python2 compatible<commit_after># -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function

from polyaxon_client.exceptions import PolyaxonClientException

try:
    from fastai.callbacks import TrackerCallback
except ImportError:
    raise PolyaxonClientException('Fastai is required to use PolyaxonFastai')


class PolyaxonFastai(TrackerCallback):

    def __init__(self, learn, experiment, monitor='val_loss', mode='auto'):
        super(PolyaxonFastai, self).__init__(learn, monitor=monitor, mode=mode)
        self.experiment = experiment

    def on_epoch_end(self, epoch, smooth_loss, last_metrics, **kwargs):
        metrics = {
            name: stat for name, stat in
            list(zip(self.learn.recorder.names, [epoch, smooth_loss] + last_metrics))[1:]
        }

        self.experiment.log_metrics(**metrics)
{'fraction_non_alphanumeric': 0.09917840375586855, 'fraction_numerical': 0.0029342723004694834, 'mean_word_length': 4.074404761904762, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2128466', 'n_tokens_mistral': 495, 'n_tokens_neox': 474, 'n_words': 120}