recommenders-team/recommenders

[ASK] Wide and Deep Scoring params for All Items or From Unrated items

Open

#1,874 创建于 2023年1月17日

在 GitHub 查看
 (1 评论) (0 反应) (0 负责人)Python (2,972 fork)batch import
help wanted

仓库指标

Star
 (17,706 star)
PR 合并指标
 (平均合并 6天 16小时) (30 天内合并 10 个 PR)

描述

Description

How to use the ScoreWideAndDeepRecommenderModule() and related score_params to make prediction for "new" userIds?

  1. I've trained a Wide and Deep model from the Studio to make item recommendation first with "From rated items" for model training and evaluation (userId with features like gender, job, religion etc and items with features like some categories ids etc)
  2. I registered the model (also exported) and tested it with online endpoint on Container instance -> all good

Now I want to modify the score.py to predict items for "all users" or "new users" so I have the following doubts: I've configured now the score_param as follow:

`def run(data): data = json.loads(data) input_entry = defaultdict(list) for row in data: for key, val in row.items(): input_entry[key].append(decode_nan(val))

data_frame_directory = create_dfd_from_dict(input_entry, schema_data)
score_params = dict(
    trained_wide_and_deep_recommendation_model=model,
    dataset_to_score=data_frame_directory,
    training_data=None,
    user_features=None,
    item_features=None,
    recommender_prediction_kind='Item Recommendation',
    recommended_item_selection='From All Items',
    maximum_number_of_items_to_recommend_to_a_user=3)
result_dfd, = ScoreWideAndDeepRecommenderModule().run(**score_params)
result_df = result_dfd.data
return json.dumps(result_df.to_dict("list"))`

Then i modified the _schema.json used to test the endpoint to accept "userId" and 2 other user features

Deploying these settings in an online endpoint and testing it with the appropriate json I always get the same prediction results even if I vary the features passed in, for example:

userId = 99999 (new user, not part of trained model) gender = female job = employed

result predictions = item 1: 123 item 2: 334, item 3: 887

userId = 99998 (new user, not part of trained model) gender = male job = student

result predictions = item 1: 123 item 2: 334, item 3: 887

(in json format...)

Thanks to anyone helping clarifying AGA

Other Comments

贡献者指南