-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathprep_fine_tuning.py
More file actions
47 lines (33 loc) · 1.08 KB
/
Copy pathprep_fine_tuning.py
File metadata and controls
47 lines (33 loc) · 1.08 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
'''
Created on Feb 6, 2024
@author: immanueltrummer
'''
import argparse
import jsonlines
import pandas
def get_samples(df):
""" Generate samples from data frame.
Args:
df: data frame containing samples.
Returns:
List of samples in OpenAI format for fine-tuning.
"""
samples = []
for _, row in df.iterrows():
text = row['text']
user_message = {'role':'user', 'content':text}
label = row['sentiment']
assistant_message = {'role':'assistant', 'content':label}
sample = {'messages':[user_message, assistant_message]}
samples += [sample]
return samples
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('in_path', type=str, help='Path to input')
parser.add_argument('out_path', type=str, help='Path to output')
args = parser.parse_args()
df = pandas.read_csv(args.in_path)
samples = get_samples(df)
with jsonlines.open(args.out_path, 'w') as file:
for sample in samples:
file.write(sample)