Back to blog
    入门指南:使用 Ertas 在 30 分钟内微调您的首个法律 AI 模型
    tutorialfine-tuninglegalertas-studiogetting-startedsegment:agency

    入门指南:使用 Ertas 在 30 分钟内微调您的首个法律 AI 模型

    实操教程:注册 Ertas Studio,上传法律样本数据集,配置并运行微调,评估输出结果,导出模型——全程仅需 30 分钟。

    EErtas Team·

    这是一篇实操教程。学完之后,您将拥有一个经过微调的 AI 模型,能够分析法律合同条款——基于样本数据训练、评估完毕、随时可导出。

    无需 ML 经验。无需 Python。无需租用 GPU。只需一个浏览器和 30 分钟。

    您将构建的内容

    一个经过微调的模型,能够:

    • 将合同条款作为输入
    • 识别条款类型(赔偿、终止、保密等)
    • 评估风险等级(低、中、高)
    • 提供简要分析及关键关注点
    • 建议谈判要点

    这是代理机构为律师事务所客户部署合同审查模型的简化版本。流程完全相同——只是训练数据和范围不同。

    前置条件

    • 一个 Ertas 账号(在 ertas.ai 注册
    • 30 分钟不受打扰的时间
    • 无技术先决条件——教程涵盖所有内容

    第 0-5 分钟:注册并创建项目

    1. 前往 ertas.ai 创建账号
    2. 在仪表盘中点击 New Project
    3. 命名为:"Legal Contract Review - Tutorial"
    4. 选择项目类型:Fine-Tuning

    您现在进入了 Ertas Studio 工作区。您将在这里上传数据、配置训练并评估模型。

    第 5-10 分钟:上传法律样本数据集

    本教程使用标注过的合同条款样本数据集。在实际部署中,这些数据来自律师事务所的历史文件审查。

    样本数据格式

    训练数据是一个 JSONL 文件,每行是一个包含指令和响应的 JSON 对象:

    {"instruction": "Analyse the following contract clause for risk level and key concerns:\n\n'The Vendor shall indemnify, defend, and hold harmless the Client from and against any and all claims, losses, damages, liabilities, costs, and expenses (including reasonable attorneys' fees) arising out of or relating to any breach of this Agreement by the Vendor.'", "response": "Clause Type: Indemnification\nRisk Level: LOW\n\nAnalysis: This is a standard one-way indemnification clause where the vendor indemnifies the client. Key observations:\n1. Scope is limited to breaches of the agreement — this is appropriately narrow\n2. Includes attorneys' fees, which is standard\n3. Uses 'arising out of or relating to' — broader than 'arising out of' alone but still reasonable\n4. One-way protection favours the client\n\nNegotiation Points:\n- Consider adding a reciprocal indemnification clause\n- Consider adding a liability cap (e.g., aggregate limit equal to fees paid)\n- The 'relating to' language could be narrowed to 'directly arising from' if the vendor has leverage"}

    上传步骤

    1. 在项目中点击 Upload Data

    2. 选择您的 JSONL 文件(或拖拽上传)

    3. Studio 验证格式并显示预览:

      • 总示例数:已显示
      • 平均指令长度:已显示
      • 平均响应长度:已显示
      • 格式问题:已标记
    4. 查看预览——浏览几个示例确认无误

    5. 点击 Confirm Upload

    如果您尚未准备好法律数据集,Ertas Studio 提供常见用例的样本数据集。选择"Legal Contract Analysis"样本数据集即可继续教程。

    第 10-15 分钟:配置训练

    数据上传后,配置微调任务。

    基础模型选择

    点击 Select Base Model。本教程推荐:

    • Llama 3.1 8B(推荐)——在质量和速度之间取得良好平衡,适合法律任务
    • Mistral 7B——可行的替代方案,输出风格略有不同

    选择 Llama 3.1 8B

    训练参数

    Studio 显示带有说明的默认参数。本教程保持默认值:

    参数默认值含义
    Adapter 类型LoRA训练小型适配器而非修改整个模型
    LoRA rank16控制模型的学习能力(16 是良好的默认值)
    LoRA alpha32缩放因子(2 倍 rank 是标准设置)
    Epochs3遍历训练数据的次数
    学习率2e-4模型学习的激进程度
    Batch sizeAutoStudio 根据数据和可用 GPU 自动优化

    对于生产模型,您可能需要根据结果调整这些参数。对于本教程,默认值效果良好。

    验证集拆分

    Studio 自动保留 10% 的数据用于验证——这些示例不会在训练中使用,而是用于后续质量评估。这是标准的 ML 实践,会自动完成。

    第 15-20 分钟:运行微调

    点击 Start Training

    Studio 处理一切:

    1. 将数据格式化为所选基础模型的分词器格式
    2. 分配 GPU 资源
    3. 运行训练循环并自动保存检查点
    4. 在保留的验证集上进行评估

    您将看到的内容

    实时训练仪表盘显示:

    • 训练损失曲线——应下降并趋于稳定。平滑的下降曲线表示模型正在学习。
    • 验证损失——应跟踪训练损失而不发散。如果验证损失上升而训练损失下降,则模型过拟合(使用这些默认值时不太可能)。
    • 预计剩余时间——对于 8B 模型上的样本数据集,通常为 15-30 分钟。
    • 已保存的检查点——Studio 在每个 epoch 保存模型,因此如果后续 epoch 表现更差,您可以回退。

    训练运行期间,可以休息一下或阅读 LoRA 工作原理,了解底层机制。

    第 20-25 分钟:评估模型

    训练完成。现在测试您微调的模型。

    并排对比

    Studio 提供对比界面。输入一个模型从未见过的合同条款,比较基础模型和微调模型的输出。

    示例输入:

    "Either party may terminate this Agreement upon sixty (60) days' prior written notice to the other party. In the event of termination, all outstanding invoices shall become immediately due and payable, and the receiving party shall return or destroy all Confidential Information within thirty (30) days."

    基础模型输出(微调前):

    This is a termination clause. It allows either party to terminate with 60 days notice. There are provisions about invoices and confidential information.

    微调模型输出:

    Clause Type: Termination Risk Level: LOW-MODERATE

    Analysis: Standard mutual termination clause with reasonable notice period. Key observations:

    1. 60-day notice period is within normal range (30-90 days typical)
    2. Immediate acceleration of outstanding invoices on termination is standard but could create cash flow pressure if triggered unexpectedly
    3. 30-day window for return/destruction of Confidential Information is reasonable
    4. "Return or destroy" gives the receiving party flexibility — consider requiring certification of destruction

    Negotiation Points:

    • If you are the service provider, negotiate for a longer notice period (90 days) to allow for transition
    • Add a survival clause specifying which provisions continue after termination (indemnification, confidentiality, IP ownership)
    • Consider adding a termination-for-cause provision with a shorter notice period and cure right

    差异一目了然。微调模型产生结构化的分析输出,与初级律师的工作成果相匹配。

    验证指标

    Studio 显示量化指标:

    • 验证损失——越低越好,与基础模型对比
    • 响应质量评分——对输出连贯性和完整性的自动评估
    • 格式一致性——模型遵循训练数据输出格式的一致程度

    查看这些指标并额外测试 5-10 个条款,以建立对模型质量的信心。

    第 25-30 分钟:导出模型

    对质量满意吗?导出模型进行部署。

    导出选项

    点击 Export Model 并选择格式:

    • GGUF(大多数部署推荐)——兼容 Ollama 进行本地推理
    • SafeTensors——兼容 vLLM、Hugging Face Transformers
    • 仅 LoRA 适配器——仅适配器文件,与基础模型配合使用

    本教程选择 GGUF

    下载

    Studio 打包并量化模型(减小文件大小同时保持质量)。8B 模型的下载大小通常为 4-6 GB。

    部署(附加步骤)

    在本地运行模型:

    # Install Ollama (if you haven't already)
    # Visit https://ollama.com
    
    # Create a Modelfile
    echo 'FROM /path/to/your-exported-model.gguf' > Modelfile
    
    # Register the model
    ollama create legal-contract-review -f Modelfile
    
    # Test it
    ollama run legal-contract-review "Analyse this clause: [paste a clause]"

    您微调的法律 AI 模型现在在本地运行。无 API 费用。数据不发送给第三方。可以与 n8n 或任何支持 OpenAI 兼容 API 的应用集成。

    下一步

    您已完成基于样本数据的微调。从教程走向生产:

    1. 收集真实训练数据——来自律师事务所客户的历史合同审查、标注文件、分析备忘录
    2. 增加数据集——2,000-3,000 个示例以达到生产质量
    3. 为客户定制——其风险阈值、术语、格式偏好
    4. 在客户硬件上部署——本地部署以满足特权和合规要求
    5. 迭代——收集反馈、添加示例、定期重新训练

    该流程可扩展到任何法律任务——尽职调查、法律研究、监管合规、文件分类。流程一致:数据 → 微调 → 评估 → 部署。

    如需深入了解构建法律 AI 业务,请参阅我们的指南:无需 ML 团队微调法律 AI


    Ship AI that runs on your users' devices.

    Ertas early bird pricing starts at $14.50/mo — locked in for life. Plans for builders and agencies.

    延伸阅读

    Ship AI that runs on your users' devices.

    Early bird pricing starts at $14.50/mo — locked in for life. Plans for builders and agencies.

    Keep reading