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

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

一、硅基流动注册&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代码基础上,增加以下脚本:

bash 复制代码
# 把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}'")
相关推荐
晚霞的不甘4 小时前
CANN × ROS 2:为智能机器人打造实时 AI 推理底座
人工智能·神经网络·架构·机器人·开源
互联网Ai好者4 小时前
MiyoAI数参首发体验——不止于监控,更是你的智能决策参谋
人工智能
island13144 小时前
CANN HIXL 通信库深度解析:单边点对点数据传输、异步模型与异构设备间显存直接访问
人工智能·深度学习·神经网络
初恋叫萱萱4 小时前
CANN 生态中的图优化引擎:深入 `ge` 项目实现模型自动调优
人工智能
不爱学英文的码字机器4 小时前
深度解读CANN生态核心仓库——catlass,打造高效可扩展的分类器技术底座
人工智能·cann
Kiyra4 小时前
作为后端开发你不得不知的 AI 知识——RAG
人工智能·语言模型
共享家95274 小时前
Vibe Coding 与 LangChain、LangGraph 的协同进化
人工智能
dvlinker4 小时前
2026远程桌面安全白皮书:ToDesk/TeamViewer/向日葵核心安全性与合规性横向测评
人工智能
2的n次方_4 小时前
CANN ascend-transformer-boost 深度解析:针对大模型的高性能融合算子库与算力优化机制
人工智能·深度学习·transformer
熊猫_豆豆4 小时前
YOLOP车道检测
人工智能·python·算法