Skip to content

TwoTower unable to use user-feats in .predict() #517

@Knarz-AP

Description

@Knarz-AP

Looking through source code, TwoTower.predict() seems to reference predict_from_embedding and not predict_tf_feat, despite the fact that TwoTower.recommend_user can use feats for prediction.

When trying to manually call predict_tf_feat, I receive this error:

`---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/tmp/ipykernel_4360/2307691744.py in
1 from libreco.recommendation import recommend_tf_feat
----> 2 recommend_tf_feat(model, user_ids='Not A Real ID', user_feats=row_dict, n_rec=10, filter_consumed=False, seq=None, random_rec=False)

/opt/conda/lib/python3.7/site-packages/libreco/recommendation/recommend.py in recommend_tf_feat(model, user_ids, n_rec, user_feats, seq, filter_consumed, random_rec, inner_id)
89 inner_id=False,
90 ):
---> 91 feed_dict = process_tf_feat(model, user_ids, user_feats, seq, inner_id)
92 if model.model_name == "SIM":
93 preds = model.sess.run(model.inference_output, feed_dict)

/opt/conda/lib/python3.7/site-packages/libreco/recommendation/preprocess.py in process_tf_feat(model, user_ids, user_feats, seq, inner_id)
131 assert isinstance(user_feats, dict), "user_feats must be dict."
132 sparse_indices, dense_values = set_temp_feats(
--> 133 model.data_info, sparse_indices, dense_values, user_feats
134 )
135

/opt/conda/lib/python3.7/site-packages/libreco/prediction/preprocess.py in set_temp_feats(data_info, sparse_indices, dense_values, feat_dict)
69 data_info.sparse_idx_mapping,
70 data_info.sparse_offset,
---> 71 feat_dict,
72 )
73 _set_dense_values(dense_values_copy, data_info.col_name_mapping, feat_dict)

/opt/conda/lib/python3.7/site-packages/libreco/prediction/preprocess.py in _set_sparse_indices(sparse_indices, col_mapping, sparse_idx_mapping, offsets, feat_dict)
93 feat_idx = idx_mapping[val]
94 offset = offsets[field_idx]
---> 95 sparse_indices[:, field_idx] = feat_idx + offset
96
97

TypeError: 'NoneType' object does not support item assignment`

Hopefully this is something that can be implemented, being able to get prediction scores of new users using feats would be incredibly useful. it seems feats being excluded from TwoTower.predict() is an oversight.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions