Esempio n. 1
0
 def _prepare(self):
     self.kg_train = self.model.stage == 1 and self.phase == 'train'
     if self.kg_train:
         self.data = utils.df_to_dict(self.corpus.relation_df)
         self.neg_heads = np.zeros(len(self), dtype=int)
         self.neg_tails = np.zeros(len(self), dtype=int)
     super()._prepare()
        def __init__(self, model, corpus, phase: str):
            self.model = model  # model object reference
            self.corpus = corpus  # reader object reference
            self.phase = phase
            self.data = utils.df_to_dict(corpus.data_df[phase])
            # ↑ DataFrame is not compatible with multi-thread operations
            self.buffer_dict = dict()
            self.buffer = self.model.buffer and self.phase != 'train'

            self._prepare()
Esempio n. 3
0
 def _prepare(self):
     if self.phase == 'train':
         interaction_df = pd.DataFrame({
             'head': self.data['user_id'],
             'tail': self.data['item_id'],
             'relation': np.zeros_like(self.data['user_id'])
         })
         self.data = utils.df_to_dict(pd.concat((self.corpus.relation_df, interaction_df), axis=0))
         self.neg_heads = np.zeros(len(self), dtype=int)
         self.neg_tails = np.zeros(len(self), dtype=int)
     super()._prepare()
Esempio n. 4
0
 def _prepare(self):
     self.kg_train = self.model.stage == 1 and self.phase == 'train'
     if self.kg_train:
         self.data = utils.df_to_dict(self.corpus.relation_df)
         self.neg_heads = np.zeros(len(self), dtype=int)
         self.neg_tails = np.zeros(len(self), dtype=int)
     else:
         col_name = self.model.category_col
         items = self.corpus.item_meta_df['item_id']
         categories = self.corpus.item_meta_df[col_name] if col_name is not None else np.zeros_like(items)
         self.item2cate = dict(zip(items, categories))
         super()._prepare()
Esempio n. 5
0
        def __init__(self, model, corpus, phase):
            self.model = model
            self.corpus = corpus
            self.phase = phase
            self.data = utils.df_to_dict(corpus.data_df[phase])
            # ↑ DataFrame is not compatible with multi-thread operations
            self.neg_items = None if phase == 'train' else self.data[
                'neg_items']
            # ↑ Sample negative items before each epoch during training
            self.buffer_dict = dict()
            self.buffer = self.model.buffer and self.phase != 'train'

            self._prepare()