convolutional_attention/token_naming_data.py
def __get_data_in_forward_format(self, names, code, name_cx_size):
        """
        Get the data in a "forward" model format.
        :param data:
        :param name_cx_size:
        :return:
        """
        assert len(names) == len(code), (len(names), len(code), code.shape)
        # Keep only identifiers in code
        #code = self.keep_identifiers_only(code)

        name_targets = []
        name_contexts = []
        original_names_ids = []
        id_xs = []
        id_ys = []

        k = 0
        for i, name in enumerate(names):
            for j in xrange(1, len(name)):  # First element should always be predictable (ie sentence start)
                name_targets.append(self.name_dictionary.get_id_or_unk(name[j]))
                original_names_ids.append(i)
                context = name[:j]
                if len(context) < name_cx_size:
                    context = [self.NONE] * (name_cx_size - len(context)) + context
                else:
                    context = context[-name_cx_size:]
                assert len(context) == name_cx_size, (len(context), name_cx_size,)
                name_contexts.append([self.name_dictionary.get_id_or_unk(t) for t in context])
                for code_token in set(code[i]):
                    token_id = self.all_tokens_dictionary.get_id_or_none(code_token)
                    if token_id is not None:
                        id_xs.append(k)
                        id_ys.append(token_id)
                k += 1

        code_features = sp.csr_matrix((np.ones(len(id_xs)), (id_xs, id_ys)), shape=(k, len(self.all_tokens_dictionary)), dtype=np.int32)
        name_targets = np.array(name_targets, dtype=np.int32)
        name_contexts = np.array(name_contexts, dtype=np.int32)
        original_names_ids = np.array(original_names_ids, dtype=np.int32)
        return name_targets, name_contexts, code_features, original_names_ids

        Get the data in a "forward" model format.
        :param data:
        :param name_cx_size:
        :return:
        
Get the data in a "forward" model format.
Get the data in a " forward " model format .
def __get_data_in_forward_format(self, names, code, name_cx_size):
        assert len(names) == len(code), (len(names), len(code), code.shape)
        name_targets = []
        name_contexts = []
        original_names_ids = []
        id_xs = []
        id_ys = []
        k = 0
        for i, name in enumerate(names):
            for j in xrange(1, len(name)):  
                name_targets.append(self.name_dictionary.get_id_or_unk(name[j]))
                original_names_ids.append(i)
                context = name[:j]
                if len(context) < name_cx_size:
                    context = [self.NONE] * (name_cx_size - len(context)) + context
                else:
                    context = context[-name_cx_size:]
                assert len(context) == name_cx_size, (len(context), name_cx_size,)
                name_contexts.append([self.name_dictionary.get_id_or_unk(t) for t in context])
                for code_token in set(code[i]):
                    token_id = self.all_tokens_dictionary.get_id_or_none(code_token)
                    if token_id is not None:
                        id_xs.append(k)
                        id_ys.append(token_id)
                k += 1
        code_features = sp.csr_matrix((np.ones(len(id_xs)), (id_xs, id_ys)), shape=(k, len(self.all_tokens_dictionary)), dtype=np.int32)
        name_targets = np.array(name_targets, dtype=np.int32)
        name_contexts = np.array(name_contexts, dtype=np.int32)
        original_names_ids = np.array(original_names_ids, dtype=np.int32)
        return name_targets, name_contexts, code_features, original_names_ids
def __get_data_in_forward_format ( self , names , code , name_cx_size ) : assert len ( names ) == len ( code ) , ( len ( names ) , len ( code ) , code . shape ) name_targets = [ ] name_contexts = [ ] original_names_ids = [ ] id_xs = [ ] id_ys = [ ] k = 0 for i , name in enumerate ( names ) : for j in xrange ( 1 , len ( name ) ) : name_targets . append ( self . name_dictionary . get_id_or_unk ( name [ j ] ) ) original_names_ids . append ( i ) context = name [ : j ] if len ( context ) < name_cx_size : context = [ self . NONE ] * ( name_cx_size - len ( context ) ) + context else : context = context [ - name_cx_size : ] assert len ( context ) == name_cx_size , ( len ( context ) , name_cx_size , ) name_contexts . append ( [ self . name_dictionary . get_id_or_unk ( t ) for t in context ] ) for code_token in set ( code [ i ] ) : token_id = self . all_tokens_dictionary . get_id_or_none ( code_token ) if token_id is not None : id_xs . append ( k ) id_ys . append ( token_id ) k += 1 code_features = sp . csr_matrix ( ( np . ones ( len ( id_xs ) ) , ( id_xs , id_ys ) ) , shape = ( k , len ( self . all_tokens_dictionary ) ) , dtype = np . int32 ) name_targets = np . array ( name_targets , dtype = np . int32 ) name_contexts = np . array ( name_contexts , dtype = np . int32 ) original_names_ids = np . array ( original_names_ids , dtype = np . int32 ) return name_targets , name_contexts , code_features , original_names_ids
Get the data in a "forward" model format.
Get the data in a " forward " model format .
"""
        Get the data in a "forward" model format.
        :param data:
        :param name_cx_size:
        :return:
        """ # Keep only identifiers in code #code = self.keep_identifiers_only(code) # First element should always be predictable (ie sentence start)
None
self
names
code
name_cx_size
None
data
None