def _init_graph(self):
    self.graph = tf.Graph()
    with self.graph.as_default():
        tf.set_random_seed(self.random_seed)
        self.feat_index = tf.placeholder(tf.int32, shape=[None, None], name='feat_index')
        self.feat_value = tf.placeholder(tf.float32, shape=[None, None], name='feat_value')
        self.label = tf.placeholder(tf.float32, shape=[None, 1], name='label')
        self.dropout_keep_deep = tf.placeholder(tf.float32, shape=[None], name='dropout_deep_deep')
        self.train_phase = tf.placeholder(tf.bool, name='train_phase')
        self.weights = self._initialize_weights()
        self.embeddings = tf.nn.embedding_lookup(self.weights['feature_embeddings'], self.feat_index)
        feat_value = tf.reshape(self.feat_value, shape=[(- 1), self.field_size, 1])
        self.embeddings = tf.multiply(self.embeddings, feat_value)
        linear_output = []
        for i in range(self.deep_init_size):
            linear_output.append(tf.reshape(tf.reduce_sum(tf.multiply(self.embeddings, self.weights['product-linear'][i]), axis=[1, 2]), shape=((- 1), 1)))
        self.lz = tf.concat(linear_output, axis=1)
        quadratic_output = []
        if self.use_inner:
            for i in range(self.deep_init_size):
                theta = tf.multiply(self.embeddings, tf.reshape(self.weights['product-quadratic-inner'][i], (1, (- 1), 1)))
                quadratic_output.append(tf.reshape(tf.norm(tf.reduce_sum(theta, axis=1), axis=1), shape=((- 1), 1)))
        else:
            embedding_sum = tf.reduce_sum(self.embeddings, axis=1)
            p = tf.matmul(tf.expand_dims(embedding_sum, 2), tf.expand_dims(embedding_sum, 1))
            for i in range(self.deep_init_size):
                theta = tf.multiply(p, tf.expand_dims(self.weights['product-quadratic-outer'][i], 0))
                quadratic_output.append(tf.reshape(tf.reduce_sum(theta, axis=[1, 2]), shape=((- 1), 1)))
        self.lp = tf.concat(quadratic_output, axis=1)
        self.y_deep = tf.nn.relu(tf.add(tf.add(self.lz, self.lp), self.weights['product-bias']))
        self.y_deep = tf.nn.dropout(self.y_deep, self.dropout_keep_deep[0])
        for i in range(0, len(self.deep_layers)):
            self.y_deep = tf.add(tf.matmul(self.y_deep, self.weights[('layer_%d' % i)]), self.weights[('bias_%d' % i)])
            self.y_deep = self.deep_layers_activation(self.y_deep)
            self.y_deep = tf.nn.dropout(self.y_deep, self.dropout_keep_deep[(i + 1)])
        self.out = tf.add(tf.matmul(self.y_deep, self.weights['output']), self.weights['output_bias'])
        if (self.loss_type == 'logloss'):
            self.out = tf.nn.sigmoid(self.out)
            self.loss = tf.losses.log_loss(self.label, self.out)
        elif (self.loss_type == 'mse'):
            self.loss = tf.nn.l2_loss(tf.subtract(self.label, self.out))
        if (self.optimizer_type == 'adam'):
            self.optimizer = tf.train.AdamOptimizer(learning_rate=self.learning_rate, beta1=0.9, beta2=0.999, epsilon=1e-08).minimize(self.loss)
        elif (self.optimizer_type == 'adagrad'):
            self.optimizer = tf.train.AdagradOptimizer(learning_rate=self.learning_rate, initial_accumulator_value=1e-08).minimize(self.loss)
        elif (self.optimizer_type == 'gd'):
            self.optimizer = tf.train.GradientDescentOptimizer(learning_rate=self.learning_rate).minimize(self.loss)
        elif (self.optimizer_type == 'momentum'):
            self.optimizer = tf.train.MomentumOptimizer(learning_rate=self.learning_rate, momentum=0.95).minimize(self.loss)
        self.saver = tf.train.Saver()
        init = tf.global_variables_initializer()
        self.sess = tf.Session()
        self.sess.run(init)
        total_parameters = 0
        for variable in self.weights.values():
            shape = variable.get_shape()
            variable_parameters = 1
            for dim in shape:
                variable_parameters *= dim.value
            total_parameters += variable_parameters
        if (self.verbose > 0):
            print(('#params: %d' % total_parameters))
def _init_graph(self):
    self.graph = tf.Graph()
    with self.graph.as_default():
        tf.set_random_seed(self.random_seed)
        self.feat_index = tf.placeholder(tf.int32, shape=[None, None], name='feat_index')
        self.feat_value = tf.placeholder(tf.float32, shape=[None, None], name='feat_value')
        self.label = tf.placeholder(tf.float32, shape=[None, 1], name='label')
        self.dropout_keep_deep = tf.placeholder(tf.float32, shape=[None], name='dropout_deep_deep')
        self.train_phase = tf.placeholder(tf.bool, name='train_phase')
        self.weights = self._initialize_weights()
        self.embeddings = tf.nn.embedding_lookup(self.weights['feature_embeddings'], self.feat_index)
        feat_value = tf.reshape(self.feat_value, shape=[(- 1), self.field_size, 1])
        self.embeddings = tf.multiply(self.embeddings, feat_value)
        linear_output = []
        for i in range(self.deep_init_size):
            linear_output.append(tf.reshape(tf.reduce_sum(tf.multiply(self.embeddings, self.weights['product-linear'][i]), axis=[1, 2]), shape=((- 1), 1)))
        self.lz = tf.concat(linear_output, axis=1)
        quadratic_output = []
        if self.use_inner:
            for i in range(self.deep_init_size):
                theta = tf.multiply(self.embeddings, tf.reshape(self.weights['product-quadratic-inner'][i], (1, (- 1), 1)))
                quadratic_output.append(tf.reshape(tf.norm(tf.reduce_sum(theta, axis=1), axis=1), shape=((- 1), 1)))
        else:
            embedding_sum = tf.reduce_sum(self.embeddings, axis=1)
            p = tf.matmul(tf.expand_dims(embedding_sum, 2), tf.expand_dims(embedding_sum, 1))
            for i in range(self.deep_init_size):
                theta = tf.multiply(p, tf.expand_dims(self.weights['product-quadratic-outer'][i], 0))
                quadratic_output.append(tf.reshape(tf.reduce_sum(theta, axis=[1, 2]), shape=((- 1), 1)))
        self.lp = tf.concat(quadratic_output, axis=1)
        self.y_deep = tf.nn.relu(tf.add(tf.add(self.lz, self.lp), self.weights['product-bias']))
        self.y_deep = tf.nn.dropout(self.y_deep, self.dropout_keep_deep[0])
        for i in range(0, len(self.deep_layers)):
            self.y_deep = tf.add(tf.matmul(self.y_deep, self.weights[('layer_%d' % i)]), self.weights[('bias_%d' % i)])
            self.y_deep = self.deep_layers_activation(self.y_deep)
            self.y_deep = tf.nn.dropout(self.y_deep, self.dropout_keep_deep[(i + 1)])
        self.out = tf.add(tf.matmul(self.y_deep, self.weights['output']), self.weights['output_bias'])
        if (self.loss_type == 'logloss'):
            self.out = tf.nn.sigmoid(self.out)
            self.loss = tf.losses.log_loss(self.label, self.out)
        elif (self.loss_type == 'mse'):
            self.loss = tf.nn.l2_loss(tf.subtract(self.label, self.out))
        if (self.optimizer_type == 'adam'):
            self.optimizer = tf.train.AdamOptimizer(learning_rate=self.learning_rate, beta1=0.9, beta2=0.999, epsilon=1e-08).minimize(self.loss)
        elif (self.optimizer_type == 'adagrad'):
            self.optimizer = tf.train.AdagradOptimizer(learning_rate=self.learning_rate, initial_accumulator_value=1e-08).minimize(self.loss)
        elif (self.optimizer_type == 'gd'):
            self.optimizer = tf.train.GradientDescentOptimizer(learning_rate=self.learning_rate).minimize(self.loss)
        elif (self.optimizer_type == 'momentum'):
            self.optimizer = tf.train.MomentumOptimizer(learning_rate=self.learning_rate, momentum=0.95).minimize(self.loss)
        self.saver = tf.train.Saver()
        init = tf.global_variables_initializer()
        self.sess = tf.Session()
        self.sess.run(init)
        total_parameters = 0
        for variable in self.weights.values():
            shape = variable.get_shape()
            variable_parameters = 1
            for dim in shape:
                variable_parameters *= dim.value
            total_parameters += variable_parameters
        if (self.verbose > 0):
            print(('#params: %d' % total_parameters))