<commit_before>from pylearn2.monitor import Monitor

class DefaultTrainingAlgorithm(object):
    def __init__(self, batch_size = None , batches_per_iter = 1000 , monitoring_batches = - 1, monitoring_dataset = None):
        """
        if batch_size is None, reverts to the force_batch_size field of the model
        """

        self.batch_size, self.batches_per_iter = batch_size, batches_per_iter
        if monitoring_dataset is None:
            assert monitoring_batches == -1
        self.monitoring_dataset, self.monitoring_batches = monitoring_dataset, monitoring_batches

        self.bSetup = False
    #

    def setup(self, model):
        self.model = model

        self.monitor = Monitor.get_monitor(model)
        self.monitor.set_dataset(dataset = self.monitoring_dataset,
                                 batches = self.monitoring_batches,
                                 batch_size = self.batch_size)

        self.first = True
        self.bSetup = True


    def train(self, dataset):
        assert self.bSetup

        model = self.model


        if self.batch_size is None:
            batch_size = model.force_batch_size
        else:
            batch_size = self.batch_size
            if hasattr(model,'force_batch_size'):
                assert model.force_batch_size <= 0 or batch_size == model.force_batch_size

        if self.first:
            self.first = False<commit_msg>added monitoring to default training algorithm<commit_after>from pylearn2.monitor import Monitor
import theano.tensor as T

class DefaultTrainingAlgorithm(object):
    def __init__(self, batch_size = None , batches_per_iter = 1000 , monitoring_batches = - 1, monitoring_dataset = None):
        """
        if batch_size is None, reverts to the force_batch_size field of the model
        """

        self.batch_size, self.batches_per_iter = batch_size, batches_per_iter
        if monitoring_dataset is None:
            assert monitoring_batches == -1
        self.monitoring_dataset, self.monitoring_batches = monitoring_dataset, monitoring_batches

        self.bSetup = False
    #

    def setup(self, model):
        self.model = model

        self.monitor = Monitor.get_monitor(model)
        self.monitor.set_dataset(dataset = self.monitoring_dataset,
                                 batches = self.monitoring_batches,
                                 batch_size = self.batch_size)


        X = T.matrix()

        channels = model.get_monitoring_channels(X)

        for name in channels:
            J =    channels[name]
            self.monitor.add_channel(name = name,
                                 ipt = X,
                                 val = J)



        self.first = True
        self.bSetup = True


    def train(self, dataset):
        assert self.bSetup

        model = self.model


        if self.batch_size is None:
            batch_size = model.force_batch_size
        else:
            batch_size = self.batch_size
            if hasattr(model,'force_batch_size'):
                assert model.force_batch_size <= 0 or batch_size == model.force_batch_size

        if self.first:
            self.first = False
{'fraction_non_alphanumeric': 0.07020872865275142, 'fraction_numerical': 0.005060088551549652, 'mean_word_length': 1.9896030245746692, 'pattern_counts': {'":': 0, '<': 5, '<?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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7045008', 'n_tokens_mistral': 882, 'n_tokens_neox': 832, 'n_words': 204}