hulehule commited on
Commit
cfc4e9f
·
verified ·
1 Parent(s): f266014

[auto] Upload folder Recommend/dataset

Browse files
Recommend/dataset/downloader_readme.md ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # PPD 这个项目只关注Lamp数据集,风格化实验只在Lamp 4, 5, 7上做
2
+
3
+
4
+ ‘’‘
5
+ 已下载的文件
6
+ LaMP 5: Personalized Scholarly Title Generation
7
+ data/lamp/LaMP_5/user/train/: 训练集(9682 条 questions + 9682 条 outputs)
8
+ data/lamp/LaMP_5/user/dev/: 验证集(2500 条 questions + 2500 条 outputs)
9
+ data/lamp/LaMP_5/user/test/: 测试集(2500 条 questions)
10
+ LaMP 7: Personalized Tweet Paraphrasing
11
+ data/lamp/LaMP_7/user/train/: 训练集(10437 条 questions + 10437 条 outputs)
12
+ data/lamp/LaMP_7/user/dev/: 验证集(1500 条 questions + 1500 条 outputs)
13
+ data/lamp/LaMP_7/user/test/: 测试集(1496 条 questions)
14
+ 数据格式
15
+ questions 文件:包含 id, input, profile 字段
16
+ outputs 文件:包含 task 和 golds 字段,其中 golds 是包含 id 和 output 的列表
17
+ ’‘’
Recommend/dataset/lamp_downloader.py ADDED
@@ -0,0 +1,286 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ LaMP 数据集下载脚本
5
+ 用于下载 LaMP 任务 4,5 和 7 的数据集
6
+ 示例:
7
+ python3 dataset/lamp_downloader.py --tasks 4 5 7
8
+ """
9
+
10
+ import os
11
+ import json
12
+ import requests
13
+ from pathlib import Path
14
+ from typing import List, Tuple
15
+ from tqdm import tqdm
16
+
17
+
18
+ class LaMPDownloader:
19
+ """LaMP 数据集下载器"""
20
+
21
+ BASE_URL = "https://ciir.cs.umass.edu/downloads/LaMP"
22
+ TIME_BASE_URL = "https://ciir.cs.umass.edu/downloads/LaMP/time"
23
+
24
+ # 任务配置(增加了 task 4)
25
+ TASKS = {
26
+ 4: "LaMP_4",
27
+ 5: "LaMP_5",
28
+ 7: "LaMP_7"
29
+ }
30
+
31
+ # 数据集分割
32
+ SPLITS = ["train", "dev", "test"]
33
+
34
+ def __init__(self, output_dir: str = "./lamp_data/lamp"):
35
+ """
36
+ 初始化下载器
37
+
38
+ Args:
39
+ output_dir: 输出目录路径
40
+ """
41
+ self.output_dir = Path(output_dir)
42
+ self.output_dir.mkdir(parents=True, exist_ok=True)
43
+
44
+ def download_file(self, url: str, filepath: Path) -> bool:
45
+ """
46
+ 下载单个文件
47
+
48
+ Args:
49
+ url: 文件 URL
50
+ filepath: 保存路径
51
+
52
+ Returns:
53
+ 是否下载成功
54
+ """
55
+ try:
56
+ response = requests.get(url, stream=True, timeout=30)
57
+ response.raise_for_status()
58
+
59
+ # 创建父目录
60
+ filepath.parent.mkdir(parents=True, exist_ok=True)
61
+
62
+ # 下载文件
63
+ total_size = int(response.headers.get('content-length', 0))
64
+ with open(filepath, 'wb') as f:
65
+ if total_size == 0:
66
+ f.write(response.content)
67
+ else:
68
+ with tqdm(total=total_size, unit='B', unit_scale=True, desc=filepath.name) as pbar:
69
+ for chunk in response.iter_content(chunk_size=8192):
70
+ if chunk:
71
+ f.write(chunk)
72
+ pbar.update(len(chunk))
73
+
74
+ return True
75
+ except Exception as e:
76
+ print(f"下载失败 {url}: {e}")
77
+ return False
78
+
79
+ def get_file_urls(self, task_num: int, split: str, setting: str = "user") -> Tuple[str, str]:
80
+ """
81
+ 获取文件 URL
82
+
83
+ Args:
84
+ task_num: 任务编号 (4, 5 或 7)
85
+ split: 数据集分割 (train, dev, test)
86
+ setting: 设置类型 ("user" 或 "time")
87
+
88
+ Returns:
89
+ (questions_url, outputs_url) 元组,test 分割时 outputs_url 为 None
90
+ """
91
+ task_name = self.TASKS[task_num]
92
+ base_url = self.BASE_URL if setting == "user" else self.TIME_BASE_URL
93
+
94
+ questions_url = f"{base_url}/{task_name}/{split}/{split}_questions.json"
95
+ outputs_url = None
96
+
97
+ if split != "test":
98
+ outputs_url = f"{base_url}/{task_name}/{split}/{split}_outputs.json"
99
+
100
+ return questions_url, outputs_url
101
+
102
+ def download_task(self, task_num: int, setting: str = "user") -> bool:
103
+ """
104
+ 下载指定任务的所有数据
105
+
106
+ Args:
107
+ task_num: 任务编号 (4, 5 或 7)
108
+ setting: 设置类型 ("user" 或 "time")
109
+
110
+ Returns:
111
+ 是否下载成功
112
+ """
113
+ if task_num not in self.TASKS:
114
+ print(f"错误: 不支持的任务编号 {task_num}")
115
+ return False
116
+
117
+ if setting not in ["user", "time"]:
118
+ print(f"错误: 不支持的设置类型 {setting}")
119
+ return False
120
+
121
+ task_name = self.TASKS[task_num]
122
+ print(f"\n开始下载 LaMP {task_num} ({setting}-based setting)...")
123
+
124
+ success_count = 0
125
+ total_count = 0
126
+
127
+ for split in self.SPLITS:
128
+ print(f"\n下载 {split} 分割...")
129
+
130
+ questions_url, outputs_url = self.get_file_urls(task_num, split, setting)
131
+
132
+ # 构建输出路径
133
+ output_subdir = self.output_dir / f"LaMP_{task_num}" / setting / split
134
+ questions_path = output_subdir / f"{split}_questions.json"
135
+ outputs_path = output_subdir / f"{split}_outputs.json" if outputs_url else None
136
+
137
+ # 下载 questions
138
+ total_count += 1
139
+ if self.download_file(questions_url, questions_path):
140
+ success_count += 1
141
+ print(f"✓ 已下载: {questions_path}")
142
+ else:
143
+ print(f"✗ 下载失败: {questions_url}")
144
+
145
+ # 下载 outputs (如果有)
146
+ if outputs_url:
147
+ total_count += 1
148
+ if self.download_file(outputs_url, outputs_path):
149
+ success_count += 1
150
+ print(f"✓ 已下载: {outputs_path}")
151
+ else:
152
+ print(f"✗ 下载失败: {outputs_url}")
153
+
154
+ print(f"\n任务 {task_num} 下载完成: {success_count}/{total_count} 个文件成功")
155
+ return success_count == total_count
156
+
157
+ def download_tasks(self, task_nums: List[int], setting: str = "user") -> bool:
158
+ """
159
+ 下载多个任务
160
+
161
+ Args:
162
+ task_nums: 任务编号列表
163
+ setting: 设置类型 ("user" 或 "time")
164
+
165
+ Returns:
166
+ 是否全部下载成功
167
+ """
168
+ all_success = True
169
+ for task_num in task_nums:
170
+ if not self.download_task(task_num, setting):
171
+ all_success = False
172
+
173
+ return all_success
174
+
175
+ def verify_downloads(self, task_num: int, setting: str = "user") -> bool:
176
+ """
177
+ 验证下载的文件
178
+
179
+ Args:
180
+ task_num: 任务编号
181
+ setting: 设置类型
182
+
183
+ Returns:
184
+ 是否验证通过
185
+ """
186
+ base_dir = self.output_dir / f"LaMP_{task_num}" / setting
187
+
188
+ print(f"\n验证 LaMP {task_num} ({setting}-based) 下载的文件...")
189
+
190
+ all_valid = True
191
+
192
+ for split in self.SPLITS:
193
+ split_dir = base_dir / split
194
+ questions_file = split_dir / f"{split}_questions.json"
195
+ outputs_file = split_dir / f"{split}_outputs.json"
196
+
197
+ # 检查 questions 文件
198
+ if not questions_file.exists():
199
+ print(f"✗ 缺失文件: {questions_file}")
200
+ all_valid = False
201
+ continue
202
+
203
+ try:
204
+ with open(questions_file, 'r', encoding='utf-8') as f:
205
+ data = json.load(f)
206
+ print(f"✓ {split}_questions.json: {len(data)} 条记录")
207
+ except Exception as e:
208
+ print(f"✗ 无法读取 {questions_file}: {e}")
209
+ all_valid = False
210
+
211
+ # 检查 outputs 文件 (test 分割没有)
212
+ if split != "test":
213
+ if not outputs_file.exists():
214
+ print(f"✗ 缺失文件: {outputs_file}")
215
+ all_valid = False
216
+ continue
217
+
218
+ try:
219
+ with open(outputs_file, 'r', encoding='utf-8') as f:
220
+ data = json.load(f)
221
+ print(f"✓ {split}_outputs.json: {len(data)} 条记录")
222
+ except Exception as e:
223
+ print(f"✗ 无法读取 {outputs_file}: {e}")
224
+ all_valid = False
225
+
226
+ return all_valid
227
+
228
+
229
+ def main():
230
+ """主函数"""
231
+ import argparse
232
+
233
+ parser = argparse.ArgumentParser(description="下载 LaMP 数据集")
234
+ parser.add_argument(
235
+ "--tasks",
236
+ type=int,
237
+ nargs="+",
238
+ default=[4, 5, 7], # 默认改为 4 5 7
239
+ help="要下载的任务编号 (默认: 4 5 7)"
240
+ )
241
+ parser.add_argument(
242
+ "--setting",
243
+ type=str,
244
+ choices=["user", "time"],
245
+ default="user",
246
+ help="数据集设置类型: user (用户分离) 或 time (时间分离) (默认: user)"
247
+ )
248
+ parser.add_argument(
249
+ "--output-dir",
250
+ type=str,
251
+ default="./data/lamp",
252
+ help="输出目录 (默认: ./data/lamp)"
253
+ )
254
+ parser.add_argument(
255
+ "--verify",
256
+ action="store_true",
257
+ help="下载后验证文件"
258
+ )
259
+
260
+ args = parser.parse_args()
261
+
262
+ # 创建下载器
263
+ downloader = LaMPDownloader(output_dir=args.output_dir)
264
+
265
+ # 下载任务
266
+ print(f"准备下载 LaMP 任务: {args.tasks}")
267
+ print(f"设置类型: {args.setting}-based")
268
+ print(f"输出目录: {args.output_dir}")
269
+
270
+ success = downloader.download_tasks(args.tasks, args.setting)
271
+
272
+ # 验证下载
273
+ if args.verify:
274
+ for task_num in args.tasks:
275
+ downloader.verify_downloads(task_num, args.setting)
276
+
277
+ if success:
278
+ print("\n✓ 所有文件下载成功!")
279
+ else:
280
+ print("\n✗ 部分文件下载失败,请检查错误信息")
281
+
282
+ return 0 if success else 1
283
+
284
+
285
+ if __name__ == "__main__":
286
+ exit(main())
Recommend/dataset/lamp_downloader_123.py ADDED
@@ -0,0 +1,313 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ LaMP 数据集下载脚本(Task 1 / 2 / 3 版本)
5
+
6
+ 用于下载 LaMP 任务 1,2 和 3 的数据集(支持 user-based 和 time-based)
7
+
8
+ 示例:
9
+ # 下载 user-based 的 1/2/3
10
+ python3 dataset/lamp_downloader_123.py --tasks 1 2 3 --setting user --output-dir ./data/lamp
11
+
12
+ # 下载 time-based 的 1/2/3
13
+ python3 dataset/lamp_downloader_123.py --tasks 1 2 3 --setting time --output-dir ./data/lamp
14
+
15
+ # 下载单个 task,例如只要 LaMP_2
16
+ python3 dataset/lamp_downloader_123.py --tasks 2 --setting user --output-dir ./data/lamp --verify
17
+ """
18
+ import os
19
+ import json
20
+ import requests
21
+ from pathlib import Path
22
+ from typing import List, Tuple
23
+ from tqdm import tqdm
24
+
25
+
26
+ class LaMPDownloader:
27
+ """LaMP 数据集下载器(支持 Task 1 / 2 / 3)"""
28
+
29
+ BASE_URL = "https://ciir.cs.umass.edu/downloads/LaMP"
30
+ TIME_BASE_URL = "https://ciir.cs.umass.edu/downloads/LaMP/time"
31
+
32
+ # 任务配置:这里改成 1 / 2 / 3
33
+ TASKS = {
34
+ 1: "LaMP_1",
35
+ 2: "LaMP_2",
36
+ 3: "LaMP_3",
37
+ }
38
+
39
+ # 数据集分割
40
+ SPLITS = ["train", "dev", "test"]
41
+
42
+ def __init__(self, output_dir: str = "./data/lamp"):
43
+ """
44
+ 初始化下载器
45
+
46
+ Args:
47
+ output_dir: 输出目录路径
48
+ """
49
+ self.output_dir = Path(output_dir)
50
+ self.output_dir.mkdir(parents=True, exist_ok=True)
51
+
52
+ def download_file(self, url: str, filepath: Path) -> bool:
53
+ """
54
+ 下载单个文件
55
+
56
+ Args:
57
+ url: 文件 URL
58
+ filepath: 保存路径
59
+
60
+ Returns:
61
+ 是否下载成功
62
+ """
63
+ try:
64
+ response = requests.get(url, stream=True, timeout=30)
65
+ response.raise_for_status()
66
+
67
+ # 创建父目录
68
+ filepath.parent.mkdir(parents=True, exist_ok=True)
69
+
70
+ # 下载文件
71
+ total_size = int(response.headers.get('content-length', 0))
72
+ with open(filepath, 'wb') as f:
73
+ if total_size == 0:
74
+ f.write(response.content)
75
+ else:
76
+ with tqdm(total=total_size, unit='B', unit_scale=True, desc=filepath.name) as pbar:
77
+ for chunk in response.iter_content(chunk_size=8192):
78
+ if chunk:
79
+ f.write(chunk)
80
+ pbar.update(len(chunk))
81
+
82
+ return True
83
+ except Exception as e:
84
+ print(f"下载失败 {url}: {e}")
85
+ return False
86
+
87
+ def get_file_urls(self, task_num: int, split: str, setting: str = "user") -> Tuple[str, str]:
88
+ """
89
+ 获取文件 URL
90
+
91
+ 特殊规则:
92
+ - LaMP_2 + user-based: train / dev 用 new/ 下的新版数据
93
+ train: .../LaMP_2/new/train/train_questions.json / train_outputs.json
94
+ dev : .../LaMP_2/new/dev/dev_questions.json / dev_outputs.json
95
+ test: .../LaMP_2/new/test/test_questions.json (无 outputs)
96
+ """
97
+ task_name = self.TASKS[task_num]
98
+ base_url = self.BASE_URL if setting == "user" else self.TIME_BASE_URL
99
+
100
+ # ================================
101
+ # 特殊处理:LaMP_2 + user-based
102
+ # ================================
103
+ if task_num == 2 and setting == "user":
104
+ # train / dev 用 new 目录
105
+ if split in ["train", "dev"]:
106
+ prefix = f"{base_url}/{task_name}/new/{split}/{split}"
107
+ questions_url = f"{prefix}_questions.json"
108
+ outputs_url = f"{prefix}_outputs.json"
109
+ return questions_url, outputs_url
110
+
111
+ # test 也有 new 版本(只有 questions)
112
+ if split == "test":
113
+ questions_url = f"{base_url}/{task_name}/new/test/test_questions.json"
114
+ return questions_url, None
115
+
116
+ # ================================
117
+ # 默认路径(非 LaMP_2 或非 user-based)
118
+ # ================================
119
+ questions_url = f"{base_url}/{task_name}/{split}/{split}_questions.json"
120
+ outputs_url = None
121
+
122
+ # test split 没有 outputs
123
+ if split != "test":
124
+ outputs_url = f"{base_url}/{task_name}/{split}/{split}_outputs.json"
125
+
126
+ return questions_url, outputs_url
127
+
128
+
129
+
130
+ def download_task(self, task_num: int, setting: str = "user") -> bool:
131
+ """
132
+ 下载指定任务的所有数据
133
+
134
+ Args:
135
+ task_num: 任务编号 (1, 2 或 3)
136
+ setting: 设置类型 ("user" 或 "time")
137
+
138
+ Returns:
139
+ 是否下载成功
140
+ """
141
+ if task_num not in self.TASKS:
142
+ print(f"错误: 不支持的任务编号 {task_num}")
143
+ return False
144
+
145
+ if setting not in ["user", "time"]:
146
+ print(f"错误: 不支持的设置类型 {setting}")
147
+ return False
148
+
149
+ print(f"\n开始下载 LaMP {task_num} ({setting}-based setting)...")
150
+
151
+ success_count = 0
152
+ total_count = 0
153
+
154
+ for split in self.SPLITS:
155
+ print(f"\n下载 {split} 分割...")
156
+
157
+ questions_url, outputs_url = self.get_file_urls(task_num, split, setting)
158
+
159
+ # 构建输出路径:data/lamp/LaMP_1/user/train/...
160
+ output_subdir = self.output_dir / f"LaMP_{task_num}" / setting / split
161
+ questions_path = output_subdir / f"{split}_questions.json"
162
+ outputs_path = output_subdir / f"{split}_outputs.json" if outputs_url else None
163
+
164
+ # 下载 questions
165
+ total_count += 1
166
+ if self.download_file(questions_url, questions_path):
167
+ success_count += 1
168
+ print(f"✓ 已下载: {questions_path}")
169
+ else:
170
+ print(f"✗ 下载失败: {questions_url}")
171
+
172
+ # 下载 outputs (如果有)
173
+ if outputs_url:
174
+ total_count += 1
175
+ if self.download_file(outputs_url, outputs_path):
176
+ success_count += 1
177
+ print(f"✓ 已下载: {outputs_path}")
178
+ else:
179
+ print(f"✗ 下载失败: {outputs_url}")
180
+
181
+ print(f"\n任务 {task_num} 下载完成: {success_count}/{total_count} 个文件成功")
182
+ return success_count == total_count
183
+
184
+ def download_tasks(self, task_nums: List[int], setting: str = "user") -> bool:
185
+ """
186
+ 下载多个任务
187
+
188
+ Args:
189
+ task_nums: 任务编号列表
190
+ setting: 设置类型 ("user" 或 "time")
191
+
192
+ Returns:
193
+ 是否全部下载成功
194
+ """
195
+ all_success = True
196
+ for task_num in task_nums:
197
+ if not self.download_task(task_num, setting):
198
+ all_success = False
199
+
200
+ return all_success
201
+
202
+ def verify_downloads(self, task_num: int, setting: str = "user") -> bool:
203
+ """
204
+ 验证下载的文件
205
+
206
+ Args:
207
+ task_num: 任务编号
208
+ setting: 设置类型
209
+
210
+ Returns:
211
+ 是否验证通过
212
+ """
213
+ base_dir = self.output_dir / f"LaMP_{task_num}" / setting
214
+
215
+ print(f"\n验证 LaMP {task_num} ({setting}-based) 下载的文件...")
216
+
217
+ all_valid = True
218
+
219
+ for split in self.SPLITS:
220
+ split_dir = base_dir / split
221
+ questions_file = split_dir / f"{split}_questions.json"
222
+ outputs_file = split_dir / f"{split}_outputs.json"
223
+
224
+ # 检查 questions 文件
225
+ if not questions_file.exists():
226
+ print(f"✗ 缺失文件: {questions_file}")
227
+ all_valid = False
228
+ continue
229
+
230
+ try:
231
+ with open(questions_file, 'r', encoding='utf-8') as f:
232
+ data = json.load(f)
233
+ print(f"✓ {split}_questions.json: {len(data)} 条记录")
234
+ except Exception as e:
235
+ print(f"✗ 无法读取 {questions_file}: {e}")
236
+ all_valid = False
237
+
238
+ # 检查 outputs 文件 (test 分割没有)
239
+ if split != "test":
240
+ if not outputs_file.exists():
241
+ print(f"✗ 缺失文件: {outputs_file}")
242
+ all_valid = False
243
+ continue
244
+
245
+ try:
246
+ with open(outputs_file, 'r', encoding='utf-8') as f:
247
+ data = json.load(f)
248
+ print(f"✓ {split}_outputs.json: {len(data)} 条记录")
249
+ except Exception as e:
250
+ print(f"✗ 无法读取 {outputs_file}: {e}")
251
+ all_valid = False
252
+
253
+ return all_valid
254
+
255
+
256
+ def main():
257
+ """主函数"""
258
+ import argparse
259
+
260
+ parser = argparse.ArgumentParser(description="下载 LaMP 数据集 (Tasks 1 / 2 / 3)")
261
+ parser.add_argument(
262
+ "--tasks",
263
+ type=int,
264
+ nargs="+",
265
+ default=[1, 2, 3], # 默认改为 1 2 3
266
+ help="要下载的任务编号 (默认: 1 2 3)"
267
+ )
268
+ parser.add_argument(
269
+ "--setting",
270
+ type=str,
271
+ choices=["user", "time"],
272
+ default="user",
273
+ help="数据集设置类型: user (用户分离) 或 time (时间分离) (默认: user)"
274
+ )
275
+ parser.add_argument(
276
+ "--output-dir",
277
+ type=str,
278
+ default="./data/lamp",
279
+ help="输出目录 (默认: ./data/lamp)"
280
+ )
281
+ parser.add_argument(
282
+ "--verify",
283
+ action="store_true",
284
+ help="下载后验证文件"
285
+ )
286
+
287
+ args = parser.parse_args()
288
+
289
+ # 创建下载器
290
+ downloader = LaMPDownloader(output_dir=args.output_dir)
291
+
292
+ # 下载任务
293
+ print(f"准备下载 LaMP 任务: {args.tasks}")
294
+ print(f"设置类型: {args.setting}-based")
295
+ print(f"输出目录: {args.output_dir}")
296
+
297
+ success = downloader.download_tasks(args.tasks, args.setting)
298
+
299
+ # 验证下载
300
+ if args.verify:
301
+ for task_num in args.tasks:
302
+ downloader.verify_downloads(task_num, args.setting)
303
+
304
+ if success:
305
+ print("\n✓ 所有文件下载成功!")
306
+ else:
307
+ print("\n✗ 部分文件下载失败,请检查错误信息")
308
+
309
+ return 0 if success else 1
310
+
311
+
312
+ if __name__ == "__main__":
313
+ exit(main())
Recommend/dataset/processing.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ '''
2
+ 把原始数据集分成一个小样本数据集,用于快速调试
3
+ '''
4
+
5
+
6
+
7
+ import json
8
+ import random
9
+ import os
10
+
11
+ def process_data(input_path, output_path, sample_ratio=0.1):
12
+ """处理数据并只保存指定比例的数据"""
13
+ print(f"处理文件: {input_path}")
14
+
15
+ # 读取原始数据
16
+ with open(input_path, 'r') as f:
17
+ data = [json.loads(line) for line in f if line.strip()]
18
+
19
+ print(f"原始数据量: {len(data)} 条")
20
+
21
+ # 随机采样10%的数据
22
+ sample_size = int(len(data) * sample_ratio)
23
+ sampled_data = random.sample(data, sample_size)
24
+
25
+ print(f"采样数据量: {len(sampled_data)} 条 ({sample_ratio*100}%)")
26
+
27
+ # 保存处理后的数据
28
+ with open(output_path, 'w') as f:
29
+ json.dump(sampled_data, f, ensure_ascii=False, indent=2)
30
+
31
+ print(f"数据已保存到: {output_path}")
32
+ print("-" * 50)
33
+
34
+ # 设置随机种子确保结果可重现
35
+ random.seed(42)
36
+
37
+ # 创建processed_data文件夹
38
+ processed_data_dir = '/opt/tiger/PLLM1.0/dataset/processed_data'
39
+ if not os.path.exists(processed_data_dir):
40
+ os.makedirs(processed_data_dir)
41
+ print(f"✅ 创建文件夹: {processed_data_dir}")
42
+ else:
43
+ print(f"📁 文件夹已存在: {processed_data_dir}")
44
+
45
+ # 处理训练数据
46
+ train_input_path = '/opt/tiger/PLLM1.0/dataset/abstract_train.json'
47
+ train_output_path = '/opt/tiger/PLLM1.0/dataset/processed_data/abstract_train.json'
48
+ process_data(train_input_path, train_output_path, sample_ratio=0.1)
49
+
50
+ # 处理测试数据
51
+ test_input_path = '/opt/tiger/PLLM1.0/dataset/abstract_test.json'
52
+ test_output_path = '/opt/tiger/PLLM1.0/dataset/processed_data/abstract_test.json'
53
+ process_data(test_input_path, test_output_path, sample_ratio=0.1)
54
+
55
+ print("✅ 数据处理完成!")
56
+