<commit_before>from six.moves import xrange

import tensorflow as tf

from .var_layer import VarLayer
from ..tf import sparse_identity, sparse_tensor_diag_matmul


def conv(features, adj, weights):
    n = adj.dense_shape[0]

    adj = tf.sparse_add(adj, sparse_identity(n))
    degree = tf.sparse_reduce_sum(adj, axis=1)
    degree = tf.cast(degree, tf.float32)
    degree = tf.pow(degree, -0.5)

    adj = sparse_tensor_diag_matmul(adj, degree, transpose=True)
    adj = sparse_tensor_diag_matmul(adj, degree, transpose=False)

    output = tf.sparse_tensor_dense_matmul(adj, features)
    return tf.matmul(output, weights)


class GCNN(VarLayer):
    def __init__(self, in_channels, out_channels, adjs, **kwargs):
        self.adjs = adjs

        super(GCNN, self).__init__(
            weight_shape=[in_channels, out_channels],
            bias_shape=[out_channels],
            **kwargs)

    def _call(self, inputs):
        batch_size = len(inputs)
        outputs = []

        for i in xrange(batch_size):
            output = conv(inputs[i], self.adjs[i], self.vars['weights'])

            if self.bias:
                output = tf.nn.bias_add(output, self.vars['bias'])
<commit_msg>fixed gcnn implementation<commit_after>from six.moves import xrange

import tensorflow as tf

from .var_layer import VarLayer
from ..tf import sparse_identity, sparse_tensor_diag_matmul


def conv(features, adj, weights):
    n = adj.dense_shape[0]

    degree = tf.sparse_reduce_sum(adj, axis=1) + 1
    degree = tf.cast(degree, tf.float32)
    degree = tf.pow(degree, -0.5)

    adj = sparse_tensor_diag_matmul(adj, degree, transpose=True)
    adj = sparse_tensor_diag_matmul(adj, degree, transpose=False)

    output = tf.sparse_tensor_dense_matmul(adj, features)

    features = tf.transpose(features)
    features = tf.multiply(tf.multiply(degree, features), degree)
    features = tf.transpose(features)
    output = output + features

    return tf.matmul(output, weights)


class GCNN(VarLayer):
    def __init__(self, in_channels, out_channels, adjs, **kwargs):
        self.adjs = adjs

        super(GCNN, self).__init__(
            weight_shape=[in_channels, out_channels],
            bias_shape=[out_channels],
            **kwargs)

    def _call(self, inputs):
        batch_size = len(inputs)
        outputs = []

        for i in xrange(batch_size):
            output = conv(inputs[i], self.adjs[i], self.vars['weights'])

            if self.bias:
                output = tf.nn.bias_add(output, self.vars['bias'])

{'fraction_non_alphanumeric': 0.11255924170616113, 'fraction_numerical': 0.005134281200631911, 'mean_word_length': 3.085483870967742, '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': '4964818', 'n_tokens_mistral': 847, 'n_tokens_neox': 808, 'n_words': 179}