Prediction on real time
shanian opened this issue · 4 comments
Hi,
Great job on he implementation.
Is there a way that predict method for SASrec works in the following way : (This can be used for real time cases)
Given a new user sequence of items that the user interacted with in real time and the model created based on the training data, a set of recommended items with their scores returns.
Thanks,
Sara
hi,dear
have you run the rp successfully?
and got each user's item sequence?
such as , for user A, the recommendatiom item sequence are [1,2,4,6,8,11,13]
Maybe you can manually create a batch (dict of data the model needs) and use the forward function of the trained model to get the prediction scores of candidate items. Like:
batch={'item_id': [[1, 2, 3, 4, 5]], 'history_items': [[7, 5, 2, 1]], 'lengths': [4]}
predictions = model(utils.batch_to_gpu(batch))['prediction']
print(predictions.cpu().data.numpy())
# predictions in shape (1, 5), precition scores of candidate items [1, 2, 3, 4, 5]
Then the items with top scores are recommended items.
hi,dear
have you run the rp successfully?
and got each user's item sequence?
such as , for user A, the recommendatiom item sequence are [1,2,4,6,8,11,13]
yes I did that.
Maybe you can manually create a batch (dict of data the model needs) and use the forward function of the trained model to get the prediction scores of candidate items. Like:
batch={'item_id': [[1, 2, 3, 4, 5]], 'history_items': [[7, 5, 2, 1]], 'lengths': [4]} predictions = model(utils.batch_to_gpu(batch)) print(prediction.cpu().data.numpy()) # predictions in shape (1, 5), precition scores of candidate items [1, 2, 3, 4, 5]
Then the items with top scores are recommended items.
Thanks for your reply I will try that 👍