recommenders-team / recommenders

Best Practices on Recommendation Systems
https://recommenders-team.github.io/recommenders/intro.html
MIT License
19.3k stars 3.11k forks source link

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

Open AlbertoAGA27 opened 1 year ago

AlbertoAGA27 commented 1 year ago

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

loomlike commented 1 year ago

@AlbertoAGA27 How did you pass the user features? I'm not familiar w/ AzureML Designer but it seems score_params accept user features separately via user_features, while dataset_to_score is to pass transaction data. You may ask further questions to AzureML Designer.