src/rime/models/lda.py
def transform(self, D, return_doc_data=False):
        """ run e-step to get doc data; output as low-rank nonnegative matrix """

        user_non_empty = D.user_in_test.reset_index()[D.user_in_test['_hist_len'].values > 0]
        past_event_df = user_non_empty['_hist_items'].explode().to_frame("ITEM_ID").join(
            pd.Series({k: j for j, k in enumerate(self._item_list)}).to_frame("j"),
            on="ITEM_ID", how="inner")  # drop oov items

        G = dgl.heterograph(
            {('doc', '', 'word'): (past_event_df.index.values, past_event_df['j'].values)},
            {'doc': len(D.user_in_test), 'word': len(self._item_list)}
        )

        trainer = Trainer(gpus=int(torch.cuda.is_available()))
        doc_nphi = trainer.predict(
            _LitLDA(self.model, G),
            DataLoader(np.arange(G.num_nodes('doc')).tolist(), self.batch_size),
        )
        doc_data = DocData(self.model.prior['doc'], torch.vstack(doc_nphi))

        u = doc_data._expectation().numpy()
        v = np.vstack([w._expectation().numpy() for w in self.model.word_data])
        out = LowRankDataFrame(
            u, v.T, D.user_in_test.index, np.array(self._item_list), '_nnmf'
        ).reindex(D.item_in_test.index, axis=1, fill_value=0)

        if return_doc_data:
            out = (out, doc_data)
        return out
 run e-step to get doc data; output as low-rank nonnegative matrix 
run e-step to get doc data; output as low-rank nonnegative matrix
run e - step to get doc data ; output as low - rank nonnegative matrix
def transform(self, D, return_doc_data=False):
        user_non_empty = D.user_in_test.reset_index()[D.user_in_test['_hist_len'].values > 0]
        past_event_df = user_non_empty['_hist_items'].explode().to_frame("ITEM_ID").join(
            pd.Series({k: j for j, k in enumerate(self._item_list)}).to_frame("j"),
            on="ITEM_ID", how="inner")  
        G = dgl.heterograph(
            {('doc', '', 'word'): (past_event_df.index.values, past_event_df['j'].values)},
            {'doc': len(D.user_in_test), 'word': len(self._item_list)}
        )
        trainer = Trainer(gpus=int(torch.cuda.is_available()))
        doc_nphi = trainer.predict(
            _LitLDA(self.model, G),
            DataLoader(np.arange(G.num_nodes('doc')).tolist(), self.batch_size),
        )
        doc_data = DocData(self.model.prior['doc'], torch.vstack(doc_nphi))
        u = doc_data._expectation().numpy()
        v = np.vstack([w._expectation().numpy() for w in self.model.word_data])
        out = LowRankDataFrame(
            u, v.T, D.user_in_test.index, np.array(self._item_list), '_nnmf'
        ).reindex(D.item_in_test.index, axis=1, fill_value=0)
        if return_doc_data:
            out = (out, doc_data)
        return out
def transform ( self , D , return_doc_data = False ) : user_non_empty = D . user_in_test . reset_index ( ) [ D . user_in_test [ '_hist_len' ] . values > 0 ] past_event_df = user_non_empty [ '_hist_items' ] . explode ( ) . to_frame ( "ITEM_ID" ) . join ( pd . Series ( { k : j for j , k in enumerate ( self . _item_list ) } ) . to_frame ( "j" ) , on = "ITEM_ID" , how = "inner" ) G = dgl . heterograph ( { ( 'doc' , '' , 'word' ) : ( past_event_df . index . values , past_event_df [ 'j' ] . values ) } , { 'doc' : len ( D . user_in_test ) , 'word' : len ( self . _item_list ) } ) trainer = Trainer ( gpus = int ( torch . cuda . is_available ( ) ) ) doc_nphi = trainer . predict ( _LitLDA ( self . model , G ) , DataLoader ( np . arange ( G . num_nodes ( 'doc' ) ) . tolist ( ) , self . batch_size ) , ) doc_data = DocData ( self . model . prior [ 'doc' ] , torch . vstack ( doc_nphi ) ) u = doc_data . _expectation ( ) . numpy ( ) v = np . vstack ( [ w . _expectation ( ) . numpy ( ) for w in self . model . word_data ] ) out = LowRankDataFrame ( u , v . T , D . user_in_test . index , np . array ( self . _item_list ) , '_nnmf' ) . reindex ( D . item_in_test . index , axis = 1 , fill_value = 0 ) if return_doc_data : out = ( out , doc_data ) return out
run e-step to get doc data; output as low-rank nonnegative matrix
run e - step to get doc data ; output as low - rank nonnegative matrix
""" run e-step to get doc data; output as low-rank nonnegative matrix """ # drop oov items
self
D
return_doc_data