src/rime/models/graph_conv.py
def _extract_features(self, D):
        """ create item -> user graph; allow same USER_ID with different TEST_START_TIME """

        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")
        past_event_df["TIMESTAMP"] = user_non_empty['_hist_ts'].explode().values
        past_event_df = past_event_df.join(  # item embeddings are shared for different times
            pd.Series({k: j for j, k in enumerate(self._padded_item_list)}).to_frame("j"),
            on="ITEM_ID", how='inner')  # drop oov items

        G = dgl.heterograph(
            {('user', 'source', 'item'): (past_event_df.index.values,
                                          past_event_df["j"].values)},
            {'user': len(D.user_in_test), 'item': len(self._padded_item_list)}
        )
        G.edata['t'] = torch.as_tensor(past_event_df["TIMESTAMP"].values.astype('float64'))

        # add padding item to guard against users with empty histories
        n_users = G.num_nodes('user')
        pad_time = -np.inf * torch.ones(n_users).double()
        G = dgl.add_edges(G, range(n_users), [0] * n_users, {'t': pad_time})

        user_test_time = D.user_in_test['TEST_START_TIME'].values
        G.nodes['user'].data['test_t'] = torch.as_tensor(user_test_time)

        if hasattr(D.user_in_test, 'embedding'):
            user_ext_embeddings = np.vstack(D.user_in_test['embedding']).astype('float32')
            G.nodes['user'].data['embedding'] = torch.as_tensor(user_ext_embeddings)
        return G.reverse(copy_edata=True)
 create item -> user graph; allow same USER_ID with different TEST_START_TIME 
create item -> user graph; allow same USER_ID with different TEST_START_TIME
create item - > user graph ; allow same USER_ID with different TEST_START_TIME
def _extract_features(self, D):
        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")
        past_event_df["TIMESTAMP"] = user_non_empty['_hist_ts'].explode().values
        past_event_df = past_event_df.join(  
            pd.Series({k: j for j, k in enumerate(self._padded_item_list)}).to_frame("j"),
            on="ITEM_ID", how='inner')  
        G = dgl.heterograph(
            {('user', 'source', 'item'): (past_event_df.index.values,
                                          past_event_df["j"].values)},
            {'user': len(D.user_in_test), 'item': len(self._padded_item_list)}
        )
        G.edata['t'] = torch.as_tensor(past_event_df["TIMESTAMP"].values.astype('float64'))
        n_users = G.num_nodes('user')
        pad_time = -np.inf * torch.ones(n_users).double()
        G = dgl.add_edges(G, range(n_users), [0] * n_users, {'t': pad_time})
        user_test_time = D.user_in_test['TEST_START_TIME'].values
        G.nodes['user'].data['test_t'] = torch.as_tensor(user_test_time)
        if hasattr(D.user_in_test, 'embedding'):
            user_ext_embeddings = np.vstack(D.user_in_test['embedding']).astype('float32')
            G.nodes['user'].data['embedding'] = torch.as_tensor(user_ext_embeddings)
        return G.reverse(copy_edata=True)
def _extract_features ( self , D ) : 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" ) past_event_df [ "TIMESTAMP" ] = user_non_empty [ '_hist_ts' ] . explode ( ) . values past_event_df = past_event_df . join ( pd . Series ( { k : j for j , k in enumerate ( self . _padded_item_list ) } ) . to_frame ( "j" ) , on = "ITEM_ID" , how = 'inner' ) G = dgl . heterograph ( { ( 'user' , 'source' , 'item' ) : ( past_event_df . index . values , past_event_df [ "j" ] . values ) } , { 'user' : len ( D . user_in_test ) , 'item' : len ( self . _padded_item_list ) } ) G . edata [ 't' ] = torch . as_tensor ( past_event_df [ "TIMESTAMP" ] . values . astype ( 'float64' ) ) n_users = G . num_nodes ( 'user' ) pad_time = - np . inf * torch . ones ( n_users ) . double ( ) G = dgl . add_edges ( G , range ( n_users ) , [ 0 ] * n_users , { 't' : pad_time } ) user_test_time = D . user_in_test [ 'TEST_START_TIME' ] . values G . nodes [ 'user' ] . data [ 'test_t' ] = torch . as_tensor ( user_test_time ) if hasattr ( D . user_in_test , 'embedding' ) : user_ext_embeddings = np . vstack ( D . user_in_test [ 'embedding' ] ) . astype ( 'float32' ) G . nodes [ 'user' ] . data [ 'embedding' ] = torch . as_tensor ( user_ext_embeddings ) return G . reverse ( copy_edata = True )
create item -> user graph; allow same USER_ID with different TEST_START_TIME
create item - > user graph ; allow same USER_ID with different TEST_START_TIME
""" create item -> user graph; allow same USER_ID with different TEST_START_TIME """ # item embeddings are shared for different times # drop oov items # add padding item to guard against users with empty histories
self
D