RUCAIBox / UniSRec

[KDD'22] Official PyTorch implementation for "Towards Universal Sequence Representation Learning for Recommender Systems".
MIT License
172 stars 26 forks source link

Requesting Guidance on Extracting User and Item Embeddings #19

Open niluminous opened 7 months ago

niluminous commented 7 months ago

Hello,

I am currently working on predicting ratings by calculating the dot product of user embeddings and item embeddings. I am considering using the Universal Sequence Representation module for user sequences and the MOE-enhanced adaptor for item embeddings.

However, I am unsure about how to properly extract these embeddings in UniSREC code. Could anyone provide some guidance or sample code on how to access these embeddings from the mentioned modules?

Thank you in advance for your help!

hyp1231 commented 5 months ago

Hi, sorry for the late reply!

1. Loading existing checkpoints

Below is an example of loading UniSRec models (either pretrained or fine-tuned).

https://github.com/RUCAIBox/UniSRec/blob/05aa5cba2809112c32808f70d16abc61c05c6538/finetune.py#L37-L40

2. Mapping external IDs to internal IDs

Here is an example of mapping the external user/item IDs (str, stored in .inter files) to internal IDs (int, remapped IDs stored in RecBole framework).

https://github.com/RUCAIBox/RecBole/blob/2b6e209372a1a666fe7207e6c2a96c7c3d49b427/run_example/case_study_example.py#L25

3. Extracting representations

Please refer to the following code:

https://github.com/RUCAIBox/UniSRec/blob/05aa5cba2809112c32808f70d16abc61c05c6538/unisrec.py#L174-L187