示例#1
0
    def call(self, inputs, mask=None):
        '''Logic borrowed from: https://github.com/fchollet/keras/blob/master/keras/layers/core.py
        '''
        dotproduct_op = get_dotproduct_op(sparse_features=self.sparse_features)
        if (self.sparse_features):
            inputs = sparse_dropout(inputs, keep_prob=1 - self.dropout_rate, noise_shape=(self.num_elements,))
        else:
            inputs = tf.nn.dropout(inputs, keep_prob=1 - self.dropout_rate)
        output = dotproduct_op(inputs, self.kernel)

        output = tf.add(output, self.bias)
        if self.activation is not None:
            output = self.activation(output)
        return output
示例#2
0
    def call(self, inputs, mask=None):
        '''Logic borrowed from: https://github.com/fchollet/keras/blob/master/keras/layers/core.py
        '''
        dotproduct = get_dotproduct(sparse_features=self.sparse_features)
        sparse_dotproduct = get_dotproduct(sparse_features=True)

        if (self.sparse_features):
            inputs = sparse_dropout(inputs,
                                    keep_prob=1 - self.dropout_rate,
                                    noise_shape=(self.num_elements, ))
        else:
            inputs = tf.nn.dropout(inputs, keep_prob=1 - self.dropout_rate)

        supports = []
        for i in range(len(self.supports)):
            supports.append(
                sparse_dotproduct(self.supports[i],
                                  dotproduct(inputs, self.support_kernels[i])))
        output = tf.add_n(supports)
        output = tf.add(output, self.bias)
        if self.activation is not None:
            output = self.activation(output)
        return output