Lyons-T / UMPR

Implementation using pytorch for the paper "Recommendation by Users' Multi-modal Preferences for Smart City Applications".

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

UMPR

Implementation for the paper:

Xu, Cai, Ziyu Guan, Wei Zhao, Quanzhou Wu, Meng Yan, Long Chen, and Qiguang Miao. "Recommendation by Users' Multi-modal Preferences for Smart City Applications." IEEE Transactions on Industrial Informatics (2020).

Environments

  • python 3.8
  • pytorch 1.7

Dataset and Word Embedding

UMPR
│
├─data
│  │
│  ├─amazonCSJ
│  │       reviews_Clothing_Shoes_and_Jewelry.json.gz
│  │       meta_Clothing_Shoes_and_Jewelry.json.gz
│  │
│  ├─music
│  │       reviews_Digital_Music.json.gz
│  │       meta_Digital_Music.json.gz
│  │
│  └─yelp
│     │    yelp_academic_dataset_review.json
│     │    photos.json
│     │
│     └─photos
│              *.jpg
│
└─embedding
           glove.6B.50d.txt
           punctuations.txt
           stopwords.txt

Running

  1. Pre-process dataset. Execute data_process.py to generate train.csv,valid.csv,test.csv,photos.json.

    python data/data_process.py --data_type amazon \
        --data_path ./data/music/reviews_Digital_Music.json.gz \
        --meta_path ./data/music/meta_Digital_Music.json.gz \
        --save_dir ./data/music \
        --train_rate 0.8
  2. Download photos of items. For amazon(not yelp), execute down_photos.py to download photos/*.jpg.

    python data/down_photos.py --photos_json ./data/music/photos.json
  3. Training Strategy (optional step)

    Click Here

  4. Train and evaluate the model. All parameters are defined in config.py.

    UMPR:

    python main.py --data_dir ./data/music
    python main.py --data_dir ./data/yelp --views ['food', 'inside', 'outside', 'drink']

    UMPR-R (only review_net work):

    python main.py --data_dir ./data/yelp --review_net_only True

    Test only:

    python main.py --data_dir ./data/music --test_only True \
        --model_path ./model/your_trained_model_name.pt
    python main.py --data_dir ./data/yelp --test_only True \
        --views ['food', 'inside', 'outside', 'drink'] \
        --model_path ./model/your_trained_model_name.pt

Experiment

Dataset (number of reviews) MF NeulMF DeepCoNN TransNets MPCN UMPR-R UMPR
Amazon Music small (64,706) 0.900899 0.822472 --- --- --- 1.117017 0.925538
Amazon Music (836,006) 0.875224 0.825261 --- --- --- 1.139187 0.955383
Amazon Clothing, Shoes and Jewelry (5,748,920) 1.512551 1.502135 --- --- --- 1.306969 1.218940
Yelp (8,021,121) 2.171064 2.041674 --- --- --- 1.282475 1.194455

Table 1. Performance comparison (mean squared error) on several datasets.

MF: General Matrix Factorization. Details

NeuMF: Neural Collaborative Filtering. Details

DeepCoNN: Details

TransNets: Details

MPCN: Details

UMPR-R: Only review network part of UMPR.

UMPR: Our complete model.

Experiment Notebook

  • 2021.03.22

    • 发现torchvision.models.models.vgg16最后一层是Linear,输出值很大(~1e6)。
    • 公式18涉及除法,有可能造成除以0的情况。解决:分母额外加1e-6。
  • 2021.03.24

    • 数据集处理技巧:评论的句子按长度排序,长句优先用于训练,短句则大概率在被对齐句数时丢弃。
    • GRU改为不定长输入。原方法是输入等长序列。
  • 2021.03.26

    • 对于图片集,一次性读入因内存不足而退出。
      解决:Dataset只存储图片路径,每个batch训练/测试时即时从磁盘中读取图片。
  • 2021.03.28

    • 尝试yelp数据集时,内存不足。
      解决:把sentence语句保存到“语句池”,统计语句时提取语句, 此时python只会得到其引用,从而节省内存
  • 2021.03.29

    • 多GPU训练时,不定长GRU潜在的巨坑:使用pytorch的DataParallel实现多GPU训练时, 它会将一个batch的数据均分输入到多个GPU上, 于是不定长GRU的输入lengths 只是一个batch中的一部分, 整个batch上的最大length值可能并不出现在当前GPU的lengths,但是序列(GRU的input) 却早已被pad为最大长度,即lengths最大值小于实际pad后的序列长度。 然后,nn.utils.rnn.pack_padded_sequence是依据lengths来pack的, 所以最后ImprovedRnn的输出tensor中序列长度那一个维度就被缩短了, 从而引起后续计算报维度不匹配的错误!
      解决:在GRU之后,执行nn.utils.rnn.pad_packed_sequence时设置参数total_length 为最大长度!

    • DataParallel进行多GPU训练报一个警告:/torch/nn/parallel/_functions.py:64: UserWarning: Was asked to gather along dimension 0, but all input tensors were scalars; will instead unsqueeze and return a vector. 原因是网络的输出loss是个标量,多个GPU输出的loss合并时,只能将这些标量合并为向量。
      解决:我删掉了源码中这句警告语句。

  • 2021.04.17

    • 运行代码时,参数如果是bool型,不管传什么,都会被解析为True。 例如,python main.py --test_only False,则实际执行的值为True
      分析:貌似是命令行按字符串类型接受参数值,而字符串默认作为true
      解决:对于bool类型的超参数, 指定parser.add_argument()的参数type=ast.literal_eval,比eval安全。

About

Implementation using pytorch for the paper "Recommendation by Users' Multi-modal Preferences for Smart City Applications".


Languages

Language:Python 100.0%