File size: 1,391 Bytes
2ad713c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
import json
import os

# Load the existing train.json file
with open('default/train.json', 'r') as f:
    data = json.load(f)

# Create the directory for the new format
os.makedirs('default-fixed', exist_ok=True)

# Convert to the correct format (JSONL - one JSON object per line)
with open('default-fixed/train.jsonl', 'w') as f:
    for i in range(len(data['file_name'])):
        example = {
            'file_name': data['file_name'][i],
            'file_path': data['file_path'][i],
            'file_size': data['file_size'][i],
            'content_type': data['content_type'][i]
        }
        f.write(json.dumps(example) + '\n')

print(f"Converted {len(data['file_name'])} examples to JSONL format")

# Update the dataset_infos.json file
with open('dataset_infos.json', 'r') as f:
    dataset_infos = json.load(f)

# Rename the default config to default-fixed
dataset_infos['default-fixed'] = dataset_infos.pop('default')

with open('dataset_infos.json', 'w') as f:
    json.dump(dataset_infos, f, indent=2)

# Update the dataset_dict.json file
with open('dataset_dict.json', 'r') as f:
    dataset_dict = json.load(f)

# Rename the default config to default-fixed
dataset_dict['default-fixed'] = dataset_dict.pop('default')

with open('dataset_dict.json', 'w') as f:
    json.dump(dataset_dict, f, indent=2)

print("Updated dataset configuration files")