使用数据集:GitHub - AndrewZhe/lawyer-llama: 中文法律LLaMA (LLaMA for Chinese legel domain)
将数据集上传到讯飞星辰MaaS平台搭建自己的大模型。
如何搭建私有数据集?
首先了解Alpaca格式
再通过code将自己的数据转化为该格式,代码如下:
def extract_dialogues(file_path):
result = []
current_act_dialogues = []
with open(file_path, 'r', encoding='utf-8') as file:
lines = file.readlines()
for line in lines:
line = line.strip()
if line.startswith("("): # 过滤旁白行
continue
if line.startswith("第") and line.endswith("幕"): # 解析新的一幕
if current_act_dialogues:
result.append(current_act_dialogues)
current_act_dialogues = []
elif ":" in line: # 按:切分角色和对话内容
role, content = line.split(":", 1)
role = role.strip()
content = content.strip()
current_act_dialogues.append({"role": role, "content": content})
if current_act_dialogues: # 保存最后一幕
result.append(current_act_dialogues)
return result
file_path = '甄嬛传剧本11-20.txt'
dialogues = extract_dialogues(file_path)
print(dialogues)