(self)
_gen_training_data memoizes the self._X and self._Y tensors
        used for training and prediction.
_gen_training_data memoizes the self._X and self._Y tensors
        used for training and prediction.
_gen_training_data memoizes the self . _X and self . _Y tensors used for training and prediction .
def _gen_training_data(self):
        """
        _gen_training_data memoizes the self._X and self._Y tensors
        used for training and prediction.
        """
        logging.debug('Logistic: featurizing training data...')
        tic = time.clock()
        # Each row corresponds to a possible value for a given attribute
        # and given TID
        self._X = torch.zeros(self.n_samples, self.num_features)
        self._Y = torch.zeros(self.n_samples)
        # Keeps track of cells with NULL init_value to ignore in training.
        # We only train on cells when train_idx[idx] == 1.
        self._train_idx = torch.zeros(self.n_samples)

        """
        Iterate through the domain for every cell and create a sample
        to use in training. We assign Y as 1 if the value is the initial value.
        """
        sample_idx = 0
        raw_data_dict = self.ds.raw_data.df.set_index('_tid_').to_dict('index')
        # Keep track of which indices correspond to a VID so we can re-use
        # self._X in prediction.
        self.vid_to_idxs = {}
        for rec in tqdm(list(self.domain_records)):
            init_row = raw_data_dict[rec['_tid_']]
            domain_vals = rec['domain'].split('|||')

            # Generate the feature tensor for all the domain values for this
            # cell.
            feat_tensor = self._gen_feat_tensor(init_row, rec['attribute'], domain_vals)
            assert(feat_tensor.shape[0] == len(domain_vals))
            self._X[sample_idx:sample_idx+len(domain_vals)] = feat_tensor

            self.vid_to_idxs[rec['_vid_']] = (sample_idx, sample_idx+len(domain_vals))

            # If the initial value is NULL, we do not want to train on it
            # nor assign it a weak label.
            if rec['init_value'] == NULL_REPR:
                sample_idx += len(domain_vals)
                continue

            # If the init value is not NULL, then we want to use these possible
            # value samples during training.
            self._train_idx[sample_idx:sample_idx + len(domain_vals)] = 1
            # Assign the tensor corresponding to the initial value with
            # a target label of 1.
            init_idx = domain_vals.index(rec['init_value'])
            self._Y[sample_idx + init_idx] = 1

            sample_idx += len(domain_vals)

        # Convert this to a vector of indices rather than a vector mask.
        self._train_idx = (self._train_idx == 1).nonzero()[:,0]

        logging.debug('Logistic: DONE featurization in %.2fs', time.clock() - tic)
def _gen_training_data ( self ) : logging . debug ( 'Logistic: featurizing training data...' ) tic = time . clock ( ) # Each row corresponds to a possible value for a given attribute # and given TID self . _X = torch . zeros ( self . n_samples , self . num_features ) self . _Y = torch . zeros ( self . n_samples ) # Keeps track of cells with NULL init_value to ignore in training. # We only train on cells when train_idx[idx] == 1. self . _train_idx = torch . zeros ( self . n_samples ) """
        Iterate through the domain for every cell and create a sample
        to use in training. We assign Y as 1 if the value is the initial value.
        """ sample_idx = 0 raw_data_dict = self . ds . raw_data . df . set_index ( '_tid_' ) . to_dict ( 'index' ) # Keep track of which indices correspond to a VID so we can re-use # self._X in prediction. self . vid_to_idxs = { } for rec in tqdm ( list ( self . domain_records ) ) : init_row = raw_data_dict [ rec [ '_tid_' ] ] domain_vals = rec [ 'domain' ] . split ( '|||' ) # Generate the feature tensor for all the domain values for this # cell. feat_tensor = self . _gen_feat_tensor ( init_row , rec [ 'attribute' ] , domain_vals ) assert ( feat_tensor . shape [ 0 ] == len ( domain_vals ) ) self . _X [ sample_idx : sample_idx + len ( domain_vals ) ] = feat_tensor self . vid_to_idxs [ rec [ '_vid_' ] ] = ( sample_idx , sample_idx + len ( domain_vals ) ) # If the initial value is NULL, we do not want to train on it # nor assign it a weak label. if rec [ 'init_value' ] == NULL_REPR : sample_idx += len ( domain_vals ) continue # If the init value is not NULL, then we want to use these possible # value samples during training. self . _train_idx [ sample_idx : sample_idx + len ( domain_vals ) ] = 1 # Assign the tensor corresponding to the initial value with # a target label of 1. init_idx = domain_vals . index ( rec [ 'init_value' ] ) self . _Y [ sample_idx + init_idx ] = 1 sample_idx += len ( domain_vals ) # Convert this to a vector of indices rather than a vector mask. self . _train_idx = ( self . _train_idx == 1 ) . nonzero ( ) [ : , 0 ] logging . debug ( 'Logistic: DONE featurization in %.2fs' , time . clock ( ) - tic )