forked from eosphoros-ai/DB-GPT-Hub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sparc multi-turn data set processing script (eosphoros-ai#225)
- Loading branch information
1 parent
81d69d9
commit ff50c75
Showing
2 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import json | ||
|
||
|
||
def process_data(input_file_path): | ||
# 读取原始数据 | ||
with open(input_file_path, "r") as file: | ||
original_data = json.load(file) | ||
|
||
# 新格式的数据列表 | ||
formatted_data = [] | ||
|
||
# 遍历原始数据 | ||
for entry in original_data: | ||
merged_entry = [] | ||
instruction = entry["instruction"] + entry["input"] | ||
history = entry["history"] | ||
|
||
# 合并指令和历史记录 | ||
merged_entry.append(instruction) | ||
merged_entry.append(entry["output"]) | ||
|
||
# 添加历史记录 | ||
for pair in history[1:]: | ||
for item in pair: | ||
merged_entry.append(item) | ||
|
||
# 添加布尔值列表 | ||
boolean_flags = [True, False] * len(history) | ||
formatted_entry = [merged_entry, boolean_flags] | ||
formatted_data.append(formatted_entry) | ||
|
||
# 将转换后的数据写入文件 | ||
with open(input_file_path, "w") as file: | ||
json.dump(formatted_data, file, indent=4) | ||
|
||
print(f"数据已成功转换并写入到文件:{input_file_path}") | ||
|
||
|
||
# 指定输入和输出文件路径 | ||
train_file_path = "./dbgpt_hub/data/example_text2sql_train.json" | ||
dev_file_path = "./dbgpt_hub/data/example_text2sql_dev.json" | ||
# 处理数据 | ||
process_data(train_file_path) | ||
process_data(dev_file_path) |