-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreformat.py
More file actions
24 lines (19 loc) · 835 Bytes
/
reformat.py
File metadata and controls
24 lines (19 loc) · 835 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import json
def transform_jsonl(input_file, output_file):
with open(input_file, 'r') as infile, open(output_file, 'w') as outfile:
for line in infile:
data = json.loads(line)
# Create the transformed object
transformed_data = {
"conversations": [
{"from": "system", "value": data["system"]},
{"from": "human", "value": data["question"]},
{"from": "gpt", "value": data["chosen"]}
]
}
# Write the transformed object to the output file
outfile.write(json.dumps(transformed_data) + '\n')
# Usage
input_file = '/home/REDACTED/Downloads/Neural-DPO.jsonl'
output_file = 'neuraldposharegpt.jsonl'
transform_jsonl(input_file, output_file)