RUCAIBox / RecBole

A unified, comprehensive and efficient recommendation library
https://recbole.io/
MIT License
3.27k stars 590 forks source link

[🐛BUG] 利用自定义数据集跑GRU4Rec模型报错无timestamp序列,但已经在.yaml文件中load_col:指定了timestamp列且自定义数据集中存在timestamp #1985

Open Gabrielle240125 opened 5 months ago

Gabrielle240125 commented 5 months ago

描述这个 bug 利用自定义数据集跑GRU4Rec模型报错无timestamp序列,但已经在.yaml文件中load_col:指定了timestamp列且自定义数据集中存在timestamp

如何复现 复现这个 bug 的步骤:

  1. 您引入的额外 yaml 文件

    model config

    embedding_size: 32

    dataset config

    field_separator: "\t" #指定数据集field的分隔符 seq_separator: " " #指定数据集中token_seq或者float_seq域里的分隔符 USER_ID_FIELD: user_id #指定用户id域 ITEM_ID_FIELD: item_id #指定物品id域 RATING_FIELD: rating #指定打分rating域 TIME_FIELD: time #指定时间域 NEGPREFIX: neg #指定负采样前缀 LABEL_FIELD: label #指定标签域 ITEM_LIST_LENGTH_FIELD: item_length #指定序列长度域 LIST_SUFFIX: _list #指定序列前缀 MAX_ITEM_LIST_LENGTH: 50 #指定最大序列长度 POSITION_FIELD: position_id #指定生成的序列位置id

    指定从什么文件里读什么列,这里就是从ml-1m.inter里面读取user_id, item_id, rating, timestamp这四列,剩下的以此类推

    load_col: inter: [user_id, item_id, rating, timestamp]

training settings

epochs: 500 #训练的最大轮数 train_batch_size: 4096 #训练的batch_size learner: adam #使用的pytorch内置优化器 learning_rate: 0.001 #学习率 training_neg_sample_num: 0 #负采样数目 eval_step: 1 #每次训练后做evalaution的次数 stopping_step: 10 #控制训练收敛的步骤数,在该步骤数内若选取的评测标准没有什么变化,就可以提前停止了

evalution settings

eval_setting: TO_LS,full #对数据按时间排序,设置留一法划分数据集,并使用全排序 metrics: ["Recall", "MRR","NDCG","Hit","Precision"] #评测标准 valid_metric: MRR@10 #选取哪个评测标准作为作为提前停止训练的标准 eval_batch_size: 4096 #评测的batch_size

2.您的代码 python run_recbole.py --model=GRU4Rec --dataset=book ----config_files=test.yaml

  1. 您的运行脚本 feat[field].fillna(value=0, inplace=True) 30 Jan 11:50 INFO book The number of users: 39029 Average actions of users: 90.54571077175362 The number of items: 22 Average actions of items: 168277.04761904763 The number of inters: 3533818 The sparsity of the dataset: -311.5608673270924% Remain Fields: ['user_id', 'item_id'] Traceback (most recent call last): File "C:\Users\13566\Desktop\python\data\model\RecBole\run_recbole.py", line 46, in run( File "C:\Users\13566\Desktop\python\data\model\RecBole\recbole\quick_start\quick_start.py", line 52, in run res = run_recbole( ^^^^^^^^^^^^ File "C:\Users\13566\Desktop\python\data\model\RecBole\recbole\quick_start\quick_start.py", line 133, in run_recbole train_data, valid_data, test_data = data_preparation(config, dataset) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\13566\Desktop\python\data\model\RecBole\recbole\data\utils.py", line 166, in data_preparation built_datasets = dataset.build() ^^^^^^^^^^^^^^^ File "C:\Users\13566\Desktop\python\data\model\RecBole\recbole\data\dataset\sequential_dataset.py", line 225, in build return super().build() ^^^^^^^^^^^^^^^ File "C:\Users\13566\Desktop\python\data\model\RecBole\recbole\data\dataset\dataset.py", line 1753, in build self._change_feat_format() File "C:\Users\13566\Desktop\python\data\model\RecBole\recbole\data\dataset\sequential_dataset.py", line 49, in _change_feat_format self.data_augmentation() File "C:\Users\13566\Desktop\python\data\model\RecBole\recbole\data\dataset\sequential_dataset.py", line 100, in data_augmentation self.sort(by=[self.uid_field, self.time_field], ascending=True) File "C:\Users\13566\Desktop\python\data\model\RecBole\recbole\data\dataset\dataset.py", line 1744, in sort self.inter_feat.sort(by=by, ascending=ascending) File "C:\Users\13566\Desktop\python\data\model\RecBole\recbole\data\interaction.py", line 321, in sort raise ValueError(f"[{b}] is not exist in interaction [{self}].") ValueError: [timestamp] is not exist in interaction [The batch_size of interaction: 3533818 user_id, torch.Size([3533818]), cpu, torch.int64 item_id, torch.Size([3533818]), cpu, torch.int64

预期 1.自定义数据集是.txt或.csv格式的情况下,如何将其转化为原子文件 2..yaml中load_col:指定.inter/.user/.item中的多个数据列,但只读取.inter中的user_id与item_id,如何解决问题?

屏幕截图 屏幕截图 2024-01-30 124534

链接 添加能够复现 bug 的代码链接,如 Colab 或者其他在线 Jupyter 平台。(可选)

实验环境(请补全下列信息):

Gabrielle240125 commented 5 months ago

已解决: 1.更新到Recbole1.2.0 2.原子文件本质上是 .tsv 文件,和 csv 文件类似,只是 csv 文件使用逗号作为分隔符,而 tsv 使用制表符作为分隔符。可以用 python 的 dataframe 进行预处理,导出时选择 sep='\t' ,注意表头的名称需要符合原子文件的要求。 3.如果要加在额外的用户或物品属性,只需要在文件中包含对应的特征段即可,比如对于 ml-1m 数据集可以用如下命令加载 item 中的 genre 属性,从而运行 GRU4RecF 模型:

load_col: inter: [user_id, item_id, rating, timestamp] item: [item_id, genre] selected_features: [genre]

Fotiligner commented 4 months ago

@Gabrielle240125 您好!您的解决方法没有问题,我们也会在后续更新中优化对自定义输入数据构造方式的说明