<commit_before>import tensorflow as tf


tf.set_random_seed(777)


class CGAN:

    def __init__(self, s, batch_size=64,
                 input_height=28, input_width=28, channel=1, z_dim=100, sample_num=64, sample_size=8,
                 output_height=28, output_width=28, n_input=784, n_classes=10,
                 n_hidden_layer_1=64, n_hidden_layer_2=128, g_lr=1e-3, d_lr=1e-3, epsilon=1e-8):
        self.s = s
        self.batch_size = batch_size

        self.sample_num = sample_num
        self.sample_size = sample_size

        self.input_height = input_height
        self.input_width = input_width
        self.output_height = output_height
        self.output_width = output_width
        self.channel = channel
        self.z_dim = z_dim
        self.y_dim = n_classes

        self.n_input = n_input
        self.n_hl_1 = n_hidden_layer_1
        self.n_hl_2 = n_hidden_layer_2
        self.n_classes = n_classes

        self.eps = epsilon

        self.d_lr, self.g_lr = d_lr, g_lr

        self.build_cgan()

    def discriminator(self, x, y, reuse=None):  # simple neural networks
        with tf.variable_scope("discriminator", reuse=reuse):
            inputs = tf.concat(axis=1, values=[x, y])
            net = tf.nn.bias_add(tf.matmul(inputs, self.W['d_h1']), self.b['d_b1'])
            net = tf.nn.relu(net)
            net = tf.nn.dropout(net, 0.8)

            net = tf.nn.bias_add(tf.matmul(net, self.W['d_h2']), self.b['d_b2'])
            net = tf.nn.relu(net)
            net = tf.nn.dropout(net, 0.8 - 0.05)

            logits = tf.nn.bias_add(tf.matmul(net, self.W['d_h_out']), self.b['d_b_out'])
            prob = tf.nn.sigmoid(logits)

        return prob

    def generator(self, z, y, reuse=None):
        with tf.variable_scope("generator", reuse=reuse):
            inputs = tf.concat(axis=1, values=[z, y])
            de_net = tf.nn.bias_add(tf.matmul(inputs, self.W['g_h1']), self.b['g_b1'])
            de_net = tf.nn.relu(de_net)

            de_net = tf.nn.bias_add(tf.matmul(de_net, self.W['g_h2']), self.b['g_b2'])
            de_net = tf.nn.relu(de_net)

            logits = tf.nn.bias_add(tf.matmul(de_net, self.W['g_h_out']), self.b['g_b_out'])
            prob = tf.nn.tanh(logits)

        return prob

    def build_cgan(self):
        # x, c, z placeholder
        self.x = tf.placeholder(tf.float32, shape=[None, self.n_input], name="x-image")
        self.c = tf.placeholder(tf.float32, shape=[None, self.y_dim], name='c-condition')
        self.z = tf.placeholder(tf.float32, shape=[None, self.z_dim], name='z-noise')

        # weights
        self.W = {
            # weights for discriminator
            'd_h1': tf.get_variable('d_h1', shape=[self.n_input + self.y_dim, self.n_hl_1],
                                    initializer=tf.contrib.layers.variance_scaling_initializer()),
            'd_h2': tf.get_variable('d_h2', shape=[self.n_hl_1, self.n_hl_2],
                                    initializer=tf.contrib.layers.variance_scaling_initializer()),
            'd_h_out': tf.get_variable('d_h_out', shape=[self.n_hl_2, 1],
                                       initializer=tf.contrib.layers.variance_scaling_initializer()),
            # weights for generator
            'g_h1': tf.get_variable('g_h1', shape=[self.z_dim + self.y_dim, self.n_hl_2],
                                    initializer=tf.contrib.layers.variance_scaling_initializer()),
            'g_h2': tf.get_variable('g_h2', shape=[self.n_hl_2, self.n_hl_1],
                                    initializer=tf.contrib.layers.variance_scaling_initializer()),
            'g_h_out': tf.get_variable('g_h_out', shape=[self.n_hl_1, self.n_input],
                                       initializer=tf.contrib.layers.variance_scaling_initializer()),
        }<commit_msg>change the function to 'sigmoid'<commit_after>import tensorflow as tf


tf.set_random_seed(777)


class CGAN:

    def __init__(self, s, batch_size=64,
                 input_height=28, input_width=28, channel=1, z_dim=100, sample_num=64, sample_size=8,
                 output_height=28, output_width=28, n_input=784, n_classes=10,
                 n_hidden_layer_1=64, n_hidden_layer_2=128, g_lr=1e-3, d_lr=1e-3, epsilon=1e-8):
        self.s = s
        self.batch_size = batch_size

        self.sample_num = sample_num
        self.sample_size = sample_size

        self.input_height = input_height
        self.input_width = input_width
        self.output_height = output_height
        self.output_width = output_width
        self.channel = channel
        self.z_dim = z_dim
        self.y_dim = n_classes

        self.n_input = n_input
        self.n_hl_1 = n_hidden_layer_1
        self.n_hl_2 = n_hidden_layer_2
        self.n_classes = n_classes

        self.eps = epsilon

        self.d_lr, self.g_lr = d_lr, g_lr

        self.build_cgan()

    def discriminator(self, x, y, reuse=None):  # simple neural networks
        with tf.variable_scope("discriminator", reuse=reuse):
            inputs = tf.concat(axis=1, values=[x, y])
            net = tf.nn.bias_add(tf.matmul(inputs, self.W['d_h1']), self.b['d_b1'])
            net = tf.nn.relu(net)
            net = tf.nn.dropout(net, 0.8)

            net = tf.nn.bias_add(tf.matmul(net, self.W['d_h2']), self.b['d_b2'])
            net = tf.nn.relu(net)
            net = tf.nn.dropout(net, 0.8 - 0.05)

            logits = tf.nn.bias_add(tf.matmul(net, self.W['d_h_out']), self.b['d_b_out'])
            prob = tf.nn.sigmoid(logits)

        return prob

    def generator(self, z, y, reuse=None):
        with tf.variable_scope("generator", reuse=reuse):
            inputs = tf.concat(axis=1, values=[z, y])
            de_net = tf.nn.bias_add(tf.matmul(inputs, self.W['g_h1']), self.b['g_b1'])
            de_net = tf.nn.relu(de_net)

            de_net = tf.nn.bias_add(tf.matmul(de_net, self.W['g_h2']), self.b['g_b2'])
            de_net = tf.nn.relu(de_net)

            logits = tf.nn.bias_add(tf.matmul(de_net, self.W['g_h_out']), self.b['g_b_out'])
            prob = tf.nn.sigmoid(logits)

        return prob

    def build_cgan(self):
        # x, c, z placeholder
        self.x = tf.placeholder(tf.float32, shape=[None, self.n_input], name="x-image")
        self.c = tf.placeholder(tf.float32, shape=[None, self.y_dim], name='c-condition')
        self.z = tf.placeholder(tf.float32, shape=[None, self.z_dim], name='z-noise')

        # weights
        self.W = {
            # weights for discriminator
            'd_h1': tf.get_variable('d_h1', shape=[self.n_input + self.y_dim, self.n_hl_1],
                                    initializer=tf.contrib.layers.variance_scaling_initializer()),
            'd_h2': tf.get_variable('d_h2', shape=[self.n_hl_1, self.n_hl_2],
                                    initializer=tf.contrib.layers.variance_scaling_initializer()),
            'd_h_out': tf.get_variable('d_h_out', shape=[self.n_hl_2, 1],
                                       initializer=tf.contrib.layers.variance_scaling_initializer()),
            # weights for generator
            'g_h1': tf.get_variable('g_h1', shape=[self.z_dim + self.y_dim, self.n_hl_2],
                                    initializer=tf.contrib.layers.variance_scaling_initializer()),
            'g_h2': tf.get_variable('g_h2', shape=[self.n_hl_2, self.n_hl_1],
                                    initializer=tf.contrib.layers.variance_scaling_initializer()),
            'g_h_out': tf.get_variable('g_h_out', shape=[self.n_hl_1, self.n_input],
                                       initializer=tf.contrib.layers.variance_scaling_initializer()),
        }
{'fraction_non_alphanumeric': 0.1330718954248366, 'fraction_numerical': 0.021437908496732026, 'mean_word_length': 2.1681159420289857, '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': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '559528', 'n_tokens_mistral': 2796, 'n_tokens_neox': 2668, 'n_words': 400}