src/rime/util/__init__.py
def explode_user_titles(user_hist, item_titles, gamma=0.5, min_gamma=0.1, pad_title='???'):
    """ explode last few user events and match with item titles;
    return splits and discount weights; empty user_hist will be turned into a single pad_title. """

    keep_last = int(np.log(min_gamma) / np.log(np.clip(gamma, 1e-10, 1 - 1e-10))) + 1  # default=4

    explode_titles = pd.Series([x[-keep_last:] for x in user_hist.values]).explode() \
        .to_frame('ITEM_ID').join(item_titles.to_frame('TITLE'), on='ITEM_ID')['TITLE']
    explode_titles = pd.Series(
        [x if not na else pad_title for x, na in
         zip(explode_titles.tolist(), explode_titles.isna().tolist())],
        index=explode_titles.index)

    splits = np.where(
        np.array(explode_titles.index.values[1:]) != np.array(explode_titles.index.values[:-1])
    )[0] + 1

    weights = np.hstack([gamma ** (np.cumsum(x) - np.sum(x))  # -2, -1, 0
                        for x in np.split(np.ones(len(explode_titles)), splits)])
    weights = np.hstack([x / x.sum() for x in np.split(weights, splits)])

    return explode_titles.values, splits, weights
 explode last few user events and match with item titles;
    return splits and discount weights; empty user_hist will be turned into a single pad_title. 
explode last few user events and match with item titles;
return splits and discount weights; empty user_hist will be turned into a single pad_title.
explode last few user events and match with item titles ; return splits and discount weights ; empty user_hist will be turned into a single pad_title .
def explode_user_titles(user_hist, item_titles, gamma=0.5, min_gamma=0.1, pad_title='???'):
    keep_last = int(np.log(min_gamma) / np.log(np.clip(gamma, 1e-10, 1 - 1e-10))) + 1  
    explode_titles = pd.Series([x[-keep_last:] for x in user_hist.values]).explode() \
        .to_frame('ITEM_ID').join(item_titles.to_frame('TITLE'), on='ITEM_ID')['TITLE']
    explode_titles = pd.Series(
        [x if not na else pad_title for x, na in
         zip(explode_titles.tolist(), explode_titles.isna().tolist())],
        index=explode_titles.index)
    splits = np.where(
        np.array(explode_titles.index.values[1:]) != np.array(explode_titles.index.values[:-1])
    )[0] + 1
    weights = np.hstack([gamma ** (np.cumsum(x) - np.sum(x))  
                        for x in np.split(np.ones(len(explode_titles)), splits)])
    weights = np.hstack([x / x.sum() for x in np.split(weights, splits)])
    return explode_titles.values, splits, weights
def explode_user_titles ( user_hist , item_titles , gamma = 0.5 , min_gamma = 0.1 , pad_title = '???' ) : keep_last = int ( np . log ( min_gamma ) / np . log ( np . clip ( gamma , 1e-10 , 1 - 1e-10 ) ) ) + 1 explode_titles = pd . Series ( [ x [ - keep_last : ] for x in user_hist . values ] ) . explode ( ) . to_frame ( 'ITEM_ID' ) . join ( item_titles . to_frame ( 'TITLE' ) , on = 'ITEM_ID' ) [ 'TITLE' ] explode_titles = pd . Series ( [ x if not na else pad_title for x , na in zip ( explode_titles . tolist ( ) , explode_titles . isna ( ) . tolist ( ) ) ] , index = explode_titles . index ) splits = np . where ( np . array ( explode_titles . index . values [ 1 : ] ) != np . array ( explode_titles . index . values [ : - 1 ] ) ) [ 0 ] + 1 weights = np . hstack ( [ gamma ** ( np . cumsum ( x ) - np . sum ( x ) ) for x in np . split ( np . ones ( len ( explode_titles ) ) , splits ) ] ) weights = np . hstack ( [ x / x . sum ( ) for x in np . split ( weights , splits ) ] ) return explode_titles . values , splits , weights
explode last few user events and match with item titles;
return splits and discount weights; empty user_hist will be turned into a single pad_title.
explode last few user events and match with item titles ; return splits and discount weights ; empty user_hist will be turned into a single pad_title .
""" explode last few user events and match with item titles;
    return splits and discount weights; empty user_hist will be turned into a single pad_title. """ # default=4 # -2, -1, 0
user_hist
item_titles
gamma
min_gamma
pad_title