-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprocess_data.py
More file actions
138 lines (130 loc) · 4.21 KB
/
process_data.py
File metadata and controls
138 lines (130 loc) · 4.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
r"""Dataset processing for SeqRecBenchmark.
Copyright (c) 2025 Weiqin Yang (Tiny Snow) & Yue Pan @ Zhejiang University
"""
import argparse
import random
import numpy as np
import process_data
def set_seed(seed: int) -> None:
r"""Set the random seed for reproducibility.
This function sets the random seed for the built-in ``random`` and
``numpy`` libraries.
Args:
seed (int):
The random seed to set.
"""
random.seed(seed)
np.random.seed(seed)
if __name__ == "__main__":
set_seed(42)
parser = argparse.ArgumentParser(description="Process SeqRec datasets.")
parser.add_argument(
"--dataset-type",
type=str,
choices=[
"amazon",
"douban",
"food",
"gowalla",
"kuairec",
"movielens",
"retailrocket",
"steam",
"yelp",
"yoochoose",
],
required=True,
help="The type of the dataset to process.",
)
parser.add_argument(
"--dataset-dir",
type=str,
required=True,
help="The directory of the dataset.",
)
parser.add_argument(
"--k-core",
type=int,
default=5,
help="The K-core value for filtering out inactive users and items.",
)
parser.add_argument(
"--sample-user-size",
type=int,
default=None,
help="The number of users to sample from the dataset.",
)
parser.add_argument(
"--meta-available",
action="store_true",
help="If set, process item titles from meta file.",
)
args = parser.parse_args()
if args.dataset_type == "amazon":
processor = process_data.AmazonDatasetProcessor(
dataset_dir=args.dataset_dir,
meta_available=args.meta_available,
k_core=args.k_core,
sample_user_size=args.sample_user_size,
)
elif args.dataset_type == "douban":
processor = process_data.DoubanDatasetProcessor(
dataset_dir=args.dataset_dir,
k_core=args.k_core,
sample_user_size=args.sample_user_size,
)
elif args.dataset_type == "food":
processor = process_data.FoodDatasetProcessor(
dataset_dir=args.dataset_dir,
meta_available=True,
k_core=args.k_core,
sample_user_size=args.sample_user_size,
)
elif args.dataset_type == "gowalla":
processor = process_data.GowallaDatasetProcessor(
dataset_dir=args.dataset_dir,
k_core=args.k_core,
sample_user_size=args.sample_user_size,
)
elif args.dataset_type == "kuairec":
processor = process_data.KuaiRecDatasetProcessor(
dataset_dir=args.dataset_dir,
k_core=args.k_core,
sample_user_size=args.sample_user_size,
)
elif args.dataset_type == "movielens":
processor = process_data.MovielensDatasetProcessor(
dataset_dir=args.dataset_dir,
meta_available=True,
k_core=args.k_core,
sample_user_size=args.sample_user_size,
)
elif args.dataset_type == "retailrocket":
processor = process_data.RetailRocketDatasetProcessor(
dataset_dir=args.dataset_dir,
k_core=args.k_core,
sample_user_size=args.sample_user_size,
)
elif args.dataset_type == "steam":
processor = process_data.SteamDatasetProcessor(
dataset_dir=args.dataset_dir,
meta_available=True,
k_core=args.k_core,
sample_user_size=args.sample_user_size,
)
elif args.dataset_type == "yelp":
processor = process_data.YelpDatasetProcessor(
dataset_dir=args.dataset_dir,
meta_available=True,
k_core=args.k_core,
sample_user_size=args.sample_user_size,
)
elif args.dataset_type == "yoochoose":
processor = process_data.YooChooseDatasetProcessor(
dataset_dir=args.dataset_dir,
k_core=args.k_core,
sample_user_size=args.sample_user_size,
)
else:
raise ValueError(f"Unsupported dataset type: {args.dataset_type}")
processor.process()