<commit_before>from keras import backend as K
from keras.engine.topology import Layer
from keras import initializations
import numpy as np
import tensorflow as tf

class DiffForest(Layer):
    def __init__(self, output_classes, n_trees=5, n_depth=3, d_init=None, l_init=None, name='diff_forest', **kwargs):
        self.output_classes = output_classes
        self.n_trees = n_trees
        self.n_depth = n_depth

        def uniform(scale):
          return lambda shape, name=None: initializations.uniform(shape, scale=scale, name=name)

        #Not clear if these are generally good initializations
        #Or if they are just good for MNIST

        if d_init is None:
          self.d_init = uniform(1)
        else:
          self.d_init = initializations.get(init)

        if l_init is None:
          self.l_init = uniform(2)
        else:
          self.l_init = initializations.get(init)

        super(DiffForest, self).__init__(**kwargs)

    def build(self, input_shape):
        input_dim = input_shape[1]

        #Per tree
        N_DECISION = (2 ** (self.n_depth)) - 1  # Number of decision nodes
        N_LEAF  = 2 ** (self.n_depth + 1)  # Number of leaf nodes

        self.w_d_ensemble = []
        self.w_l_ensemble = []
        for i in xrange(self.n_trees):
            self.w_d_ensemble.append(self.d_init((input_dim, N_DECISION)))
            self.w_l_ensemble.append(self.l_init((N_LEAF, self.output_classes)))

        self.trainable_weights = self.w_d_ensemble + self.w_l_ensemble

    def call(self, x, mask=None):
        N_DECISION = (2 ** (self.n_depth)) - 1  # Number of decision nodes
        N_LEAF  = 2 ** (self.n_depth + 1)  # Number of leaf nodes

        flat_decision_p_e = []
        leaf_p_e = []
        for w_d, w_l in zip(self.w_d_ensemble, self.w_l_ensemble):

            #Move sigmoid into output space 0-1
            decision_p = (K.sigmoid((K.dot(x, w_d))) + 1) /2
            leaf_p = K.softmax(w_l)

            decision_p_comp = 1 - decision_p

            decision_p_pack = K.concatenate([decision_p, decision_p_comp])
<commit_msg>Fix my silliness<commit_after>from keras import backend as K
from keras.engine.topology import Layer
from keras import initializations
import numpy as np
import tensorflow as tf

class DiffForest(Layer):
    def __init__(self, output_classes, n_trees=5, n_depth=3, d_init=None, l_init=None, name='diff_forest', **kwargs):
        self.output_classes = output_classes
        self.n_trees = n_trees
        self.n_depth = n_depth

        def uniform(scale):
          return lambda shape, name=None: initializations.uniform(shape, scale=scale, name=name)

        #Not clear if these are generally good initializations
        #Or if they are just good for MNIST

        if d_init is None:
          self.d_init = uniform(1)
        else:
          self.d_init = initializations.get(init)

        if l_init is None:
          self.l_init = uniform(2)
        else:
          self.l_init = initializations.get(init)

        super(DiffForest, self).__init__(**kwargs)

    def build(self, input_shape):
        input_dim = input_shape[1]

        #Per tree
        N_DECISION = (2 ** (self.n_depth)) - 1  # Number of decision nodes
        N_LEAF  = 2 ** (self.n_depth + 1)  # Number of leaf nodes

        self.w_d_ensemble = []
        self.w_l_ensemble = []
        for i in xrange(self.n_trees):
            self.w_d_ensemble.append(self.d_init((input_dim, N_DECISION)))
            self.w_l_ensemble.append(self.l_init((N_LEAF, self.output_classes)))

        self.trainable_weights = self.w_d_ensemble + self.w_l_ensemble

    def call(self, x, mask=None):
        N_DECISION = (2 ** (self.n_depth)) - 1  # Number of decision nodes
        N_LEAF  = 2 ** (self.n_depth + 1)  # Number of leaf nodes

        flat_decision_p_e = []
        leaf_p_e = []
        for w_d, w_l in zip(self.w_d_ensemble, self.w_l_ensemble):

            decision_p = K.sigmoid((K.dot(x, w_d)))
            leaf_p = K.softmax(w_l)

            decision_p_comp = 1 - decision_p

            decision_p_pack = K.concatenate([decision_p, decision_p_comp])

{'fraction_non_alphanumeric': 0.09932170542635659, 'fraction_numerical': 0.007751937984496124, 'mean_word_length': 2.4581239530988275, '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': '470508', 'n_tokens_mistral': 1452, 'n_tokens_neox': 1382, 'n_words': 328}