手把手教程:用Google Colab免费GPU训练「劳动法分类模型」(新手友好)
(目标:自动分类法律咨询属于「加班工资」「劳动合同解除」等劳动法场景)
一、准备工作(5分钟)
-
打开Colab并挂载Google Drive
from google.colab import drive drive.mount('/content/drive') # 授权后会生成文件夹
-
启用GPU(关键!)
点击菜单栏 → Runtime → Change runtime type → 选择 GPU(免费版为Tesla T4,8GB显存)。 -
验证GPU是否可用
import torch print("GPU状态:", "可用" if torch.cuda.is_available() else "不可用") # 应输出“可用”
二、数据准备(10分钟)
📌 劳动法示例数据(2类:加班工资、合同解除)
- 从GitHub下载示例数据(含200条标注数据),或手动创建:
import pandas as pd data = [ ["周末加班没调休,能拿多少工资?", "加班工资"], ["公司没签合同,离职可以索赔吗?", "劳动合同解除"], # 更多数据... ] df = pd.DataFrame(data, columns=["text", "label"]) df