<commit_before># Copyright 2016 <NAME>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

import os

import numpy as np
import matplotlib.pyplot as plt

from keras.callbacks import Callback
import keras.backend as K

from beras.util import tile


class VisualiseGAN(Callback):
    def __init__(self, nb_samples, output_dir, show=False, preprocess=None):
        self.nb_samples = nb_samples
        self.output_dir = output_dir
        self.show = show
        self.preprocess = preprocess
        if self.preprocess is None:
            self.preprocess = lambda x: x
        os.makedirs(self.output_dir, exist_ok=True)

    def should_visualise(self, i):
        return i % 50 == 0 or \
            (i < 1000 and i % 20 == 0) or \
            (i < 100 and i % 5 == 0) or \
            i < 15

    def on_train_begin(self, logs={}):
        z_shape = self.model.z_shape
        z_shape = (self.nb_samples, ) + z_shape[1:]
        self.z = np.random.uniform(-1, 1, z_shape)

    def on_epoch_end(self, epoch, logs={}):
        epoch = epoch + 1
        if self.should_visualise(epoch):
            fake = self.model.generate({'z': self.z})
            fake = self.preprocess(fake)
            tiled_fakes = tile(fake)
            plt.imshow(tiled_fakes[0], cmap='gray')
            plt.grid(False)
            fname = os.path.join(self.output_dir, "{:05d}.png".format(epoch))
            plt.savefig(fname, dpi=200)
            if self.show:
                plt.show()
            plt.clf()


class SaveModels(Callback):
    def __init__(self, models, output_dir=None, every_epoch=50,
                 overwrite=True):<commit_msg>VisualiseGAN: add call method to<commit_after># Copyright 2016 <NAME>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

import os

import numpy as np
import matplotlib.pyplot as plt

from keras.callbacks import Callback
import keras.backend as K

from beras.util import tile


class VisualiseGAN(Callback):
    def __init__(self, nb_samples, output_dir, show=False, preprocess=None):
        self.nb_samples = nb_samples
        self.output_dir = output_dir
        self.show = show
        self.preprocess = preprocess
        if self.preprocess is None:
            self.preprocess = lambda x: x
        os.makedirs(self.output_dir, exist_ok=True)

    def should_visualise(self, i):
        return i % 50 == 0 or \
            (i < 1000 and i % 20 == 0) or \
            (i < 100 and i % 5 == 0) or \
            i < 15

    def on_train_begin(self, logs={}):
        z_shape = self.model.z_shape
        z_shape = (self.nb_samples, ) + z_shape[1:]
        self.z = np.random.uniform(-1, 1, z_shape)

    def __call__(self):
        fake = self.model.generate({'z': self.z})
        fake = self.preprocess(fake)
        tiled_fakes = tile(fake)
        plt.imshow(tiled_fakes[0], cmap='gray')
        plt.grid(False)
        if self.show:
            plt.show()

    def on_epoch_end(self, epoch, logs={}):
        epoch = epoch + 1
        if self.should_visualise(epoch):
            self()
            fname = os.path.join(self.output_dir, "{:05d}.png".format(epoch))
            plt.savefig(fname, dpi=200)
            plt.clf()


class SaveModels(Callback):
    def __init__(self, models, output_dir=None, every_epoch=50,
                 overwrite=True):
{'fraction_non_alphanumeric': 0.10165539752856144, 'fraction_numerical': 0.01725343903007694, 'mean_word_length': 2.5135135135135136, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5479015', 'n_tokens_mistral': 1377, 'n_tokens_neox': 1311, 'n_words': 410}