root commited on
Commit
37d8447
·
1 Parent(s): 87ee19d
Files changed (1) hide show
  1. generate_config.py +0 -60
generate_config.py DELETED
@@ -1,60 +0,0 @@
1
- from datasets import load_dataset, Audio
2
-
3
- # 1. 登录 (如果需要)
4
- # ...
5
-
6
- # 2. 以 JSON Lines 格式加载原始的、嵌套的数据集
7
- print("正在以 JSON Lines 格式加载 metadata.jsonl...")
8
- nested_dataset = load_dataset('json', data_files='metadata.jsonl', split='train')
9
-
10
- # 3. 使用 .map() 扁平化数据集(适配新版 datasets 库)
11
- print("正在扁平化数据集结构 (使用 .map)...")
12
- def flatten_conversations_batch(batch):
13
- # 'batch' 是一个字典,它的值是列表,例如:
14
- # {'conversations': [ [{'No':1,...},{'No':2,...}], [{'No':3,...}] ]}
15
-
16
- # 我们创建一个新的字典来存放扁平化后的列
17
- flat_batch = {
18
- 'No': [],
19
- 'from': [],
20
- 'value': [],
21
- 'emotion': [],
22
- 'length': [],
23
- 'score_arousal': [],
24
- 'score_prosody': [],
25
- 'score_nature': [],
26
- 'score_expressive': [],
27
- 'audio-path': []
28
- }
29
-
30
- # 遍历批次中的每一个 'conversations' 列表
31
- for conversation_list in batch['conversations']:
32
- # 遍历列表中的每一个样本字典
33
- for sample in conversation_list:
34
- # 将样本的值追加到新字典的对应列表中
35
- for key in flat_batch:
36
- flat_batch[key].append(sample.get(key))
37
-
38
- return flat_batch
39
-
40
- # 使用 .map() 应用这个函数
41
- # batched=True 表示函数一次处理一批数据,效率更高
42
- # remove_columns 会移除原始的 'conversations' 列
43
- dataset = nested_dataset.map(
44
- flatten_conversations_batch,
45
- batched=True,
46
- remove_columns=nested_dataset.column_names
47
- )
48
-
49
- print("数据集已成功扁平化,现在的列为:", dataset.column_names)
50
-
51
- # 4. 定义数据类型
52
- print("正在转换音频列...")
53
- # 确保'audio-path'中的音频文件路径相对于仓库根目录是正确的
54
- dataset = dataset.cast_column("audio-path", Audio())
55
-
56
- # 5. 将配置和优化后的元数据推送到Hub
57
- print("正在将新的配置和元数据上传到Hub...")
58
- dataset.push_to_hub("FreedomIntelligence/ExpressiveSpeech")
59
-
60
- print("操作完成!请刷新您在Hugging Face上的数据集页面。")