【Datawhale AI夏令营】科大讯飞AI大赛(大模型技术)/夏令营:让AI理解列车排期表

发布于:2025-07-28 ⋅ 阅读:(17) ⋅ 点赞:(0)

跑的时候有些地方需要修改,在此记录。

一、硅基流动注册&API密钥使用

baseline.ipynb的此处需要进行修改:

如果不知道自己的token是什么,可参考:免费调用DeepSeek-R1!硅基流动注册&API密钥使用全攻略 | 手把手教程https://zhuanlan.zhihu.com/p/21156769766

二、json数组转换为独立json对象

由于baseline跑出来的结果是json数组,如果不转换直接在MaaS平台上训练,会产生如下报错:

{"category": "数据集错误","reason" :"JSON parse error: Column() changed from object to array in row 0"}

因此在baseline代码基础上,增加以下脚本:

# 把json数组转换独立的json对象({"category": "数据集错误","reason" :"JSON parse error: Column() changed from object to array in row 0"})
import json
import os

# === 第一步:转换 JSON 数组为 JSONL 格式 ===
input_json_file = 'single_row.json'
jsonl_file = 'train_data/single_row.jsonl'

# 读取 JSON 数组
with open(input_json_file, 'r', encoding='utf-8') as f:
    data = json.load(f)

# 写入 JSONL 格式(每行一个 JSON 对象)
with open(jsonl_file, 'w', encoding='utf-8') as f:
    for item in data:
        json.dump(item, f, ensure_ascii=False)
        f.write('\n')

print(f"转换完成,已保存为 JSONL 文件:'{jsonl_file}'")

# === 第二步:修复 JSONL 文件中的 output 字段 ===
temp_file = jsonl_file + '.tmp'

with open(jsonl_file, "r", encoding="utf-8") as infile, open(temp_file, "w", encoding="utf-8") as outfile:
    for line_num, line in enumerate(infile, start=1):
        line = line.strip()
        if not line:
            continue
        try:
            data = json.loads(line)
            if "output" in data and not isinstance(data["output"], str):
                data["output"] = str(data["output"])
            json.dump(data, outfile, ensure_ascii=False)
            outfile.write("\n")
        except json.JSONDecodeError as e:
            print(f"第 {line_num} 行解析错误:{e}")

# 替换原文件
os.replace(temp_file, jsonl_file)
print(f"修复完成,JSONL 文件已更新:'{jsonl_file}'")


网站公告

今日签到

点亮在社区的每一天
去签到