-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutil.py
54 lines (40 loc) · 1.29 KB
/
util.py
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
48
49
50
51
52
53
54
import json
import yaml
# Load configuration from YAML file
with open("config.yaml", "r") as f:
config = yaml.safe_load(f)
def read_and_validate_file(file_path):
"""Read a text file and return a list of sentences.
Args:
file_path (str): Path to the text file.
Returns:
list: List of sentences.
"""
with open(file_path, "r") as f:
data = f.readlines()
data = [line.strip() for line in data]
return data
def augment_data(data):
"""Placeholder for data augmentation logic.
Args:
data (list): List of sentences.
Raises:
NotImplementedError: Function not implemented yet.
"""
raise NotImplementedError
def generate_and_write_responses(data, output_file="generated_data.jsonl"):
generated_responses = []
data_repetition = config["fine_tuning"]["data_repetition"]
for entry in data:
generated_responses.append(
{
"messages": [
{"role": "user", "content": entry["input"]},
{"role": "assistant", "content": entry["response"]},
]
}
)
with open(output_file, "w") as f:
for entry in generated_responses * data_repetition:
f.write(json.dumps(entry) + "\n")
return output_file