Back to blog
    如何在没有 ML 团队的情况下微调法律 AI 模型
    fine-tuninglegalno-codeagencysegment:agency

    如何在没有 ML 团队的情况下微调法律 AI 模型

    大多数 AI 代理机构没有 ML 工程师。以下是如何使用 Ertas Studio 微调生产级法律 AI 模型——无需 Python、无需 GPU 租赁、无需 ML 专业知识。

    EErtas Team·

    AI 代理机构进入法律垂直领域的最大瓶颈不是销售或合规知识——而是 ML 专业能力。传统上,微调语言模型需要精通 Python、理解训练超参数、拥有 GPU 基础设施以及调试训练运行的经验。

    大多数代理机构不具备这些。他们拥有自动化工程师、工作流专家和面向客户的顾问。招聘一名 ML 工程师需要增加 15 万至 25 万美元的薪资,而且在产出之前就要支付这笔费用。

    本文展示如何使用 Ertas Studio 完全绕过 ML 瓶颈,逐步完成从数据准备到部署的完整法律模型微调工作流程。

    代理机构的瓶颈

    典型 AI 代理机构为法律客户服务的工作流程如下:

    1. 客户需要 AI 驱动的合同审查
    2. 代理机构使用 GPT-4o 构建提示工程方案
    3. 结果尚可但精度不足以投入生产
    4. 客户要求更高的准确度和数据隐私
    5. 代理机构意识到需要微调和本地部署
    6. 代理机构遇到瓶颈——团队中没有人知道如何微调模型

    此时,代理机构通常会:

    • 拒绝这个项目(损失收入)
    • 外包给 ML 承包商(每个模型 1 万至 3 万美元,4-8 周周期)
    • 从零开始学习微调(数月的探索)

    这些方案都不可持续。Ertas Studio 提供了第四种选择:一个专为非 ML 团队打造的无代码微调界面。

    实战演练:微调法律合同审查模型

    以下是完整工作流程,逐步说明。

    步骤 1:准备训练数据

    法律合同审查的训练数据来自律师事务所的历史工作。您需要指令-响应对,其中:

    • **指令:**合同条款或章节 + 分析问题
    • **响应:**律师的分析、风险评估或提取的信息

    示例:

    {
      "instruction": "Review the following indemnification clause and assess risk level:\n\n'Tenant shall indemnify and hold harmless Landlord from and against any and all claims, damages, losses, costs and expenses (including reasonable attorneys' fees) arising out of or in connection with Tenant's use of the Premises, except to the extent caused by Landlord's gross negligence or willful misconduct.'",
      "response": "Risk Level: MODERATE\n\nAnalysis: This is a standard one-way indemnification clause favouring the landlord. The carve-out for landlord's gross negligence/willful misconduct provides some protection, but the clause is broader than ideal. Key concerns:\n1. 'Any and all claims' is very broad — consider narrowing to claims arising from tenant's negligence\n2. No cap on indemnification liability\n3. Includes attorneys' fees which could be significant\n\nRecommendation: Negotiate to add mutual indemnification and a liability cap tied to the lease value."
    }

    数据要求:

    • **最低:**500 个示例(基础模型)
    • **推荐:**2,000-3,000 个示例(生产质量)
    • **格式:**JSONL(每行一个 JSON 对象)

    数据来源:

    • 从文档管理系统导出(iManage、NetDocuments)
    • 将律师标注和评论转换为结构化对
    • 使用历史审查备忘录作为响应模板

    步骤 2:上传到 Ertas Studio

    Ertas Studio 中:

    1. 创建新项目并命名(例如"Acme Legal - Contract Review")
    2. 上传 JSONL 训练文件
    3. Studio 自动验证格式并显示示例预览
    4. 查看数据统计——响应长度分布、指令类别

    Studio 会标记潜在的数据质量问题:重复条目、过短响应、格式不一致。在继续之前修复这些问题。

    步骤 3:配置训练

    Studio 提供合理默认值的训练配置:

    参数默认值含义
    基础模型Llama 3.1 8B待微调的基础模型
    Adapter 类型LoRA训练小型适配器而非完整模型
    LoRA rank16控制适配器容量(更高 = 更大容量,更多计算)
    Epochs3遍历训练数据的次数
    学习率2e-4模型学习的激进程度(更低 = 更稳定)

    对于法律任务,默认值效果良好。主要决策是基础模型大小:

    • **8B:**训练快速,可在消费级 GPU 上运行,适合单任务模型(例如仅合同审查)
    • **13B:**训练较慢,需要更多 VRAM,适合多任务模型(合同审查 + 案例摘要 + 文档分类)

    步骤 4:训练

    点击"Start Training"。Studio 处理:

    • 分词和数据格式化
    • GPU 分配和调度
    • 训练执行及自动检查点保存
    • 在保留的验证集上进行评估
    • 实时显示损失曲线和质量指标

    2,000 个示例在 8B 模型上的训练时间:约 30-60 分钟。

    步骤 5:评估

    训练完成后,Studio 提供评估界面:

    • **并排对比:**将相同的合同条款分别发送给基础模型和微调模型,比较输出。
    • **验证指标:**保留数据的损失、响应质量评分
    • **自定义输入测试:**粘贴任何合同条款,查看微调模型的分析

    质量差异在这里变得明显。基础模型产生通用且有时不准确的分析。微调模型产生的分析与事务所自身律师的风格一致——使用他们的术语、应用他们的风险阈值、遵循他们的报告格式。

    步骤 6:导出和部署

    以您偏好的格式导出微调模型:

    • **GGUF:**用于通过 Ollama 部署(大多数代理机构部署推荐)
    • **SafeTensors:**用于通过 vLLM 或 Hugging Face Transformers 部署
    • **仅 LoRA 适配器:**如果与同一基础模型的其他适配器一起部署

    使用 Ollama 或 vLLM 部署到客户硬件。模型在本地运行——部署后无需互联网连接。

    微调前后:输出质量对比

    输入条款:

    "Notwithstanding any other provision of this Agreement, either party may terminate this Agreement immediately upon written notice if the other party commits a material breach and fails to cure such breach within ten (10) business days of receiving written notice thereof."

    基础模型(Llama 3.1 8B,未微调):

    "This is a termination clause. It allows either party to terminate the agreement if there is a material breach. The cure period is 10 business days."

    微调模型(相同基础,基于事务所数据训练):

    "Risk Level: LOW-MODERATE

    Standard mutual termination for material breach with cure period. The 10 business day cure period is shorter than our typical recommendation of 30 calendar days. Key considerations:

    1. 'Material breach' is undefined — recommend adding examples or referencing specific obligations
    2. 10 business days may be insufficient for complex curing actions (e.g., insurance procurement, structural repairs)
    3. 'Immediately upon written notice' after cure failure is acceptable
    4. 'Notwithstanding any other provision' creates potential conflict with force majeure clause in Section 14

    Recommendation: Negotiate cure period to 30 calendar days. Add definition of material breach or cross-reference to specific obligations."

    差异不是增量式的——而是质的飞跃。微调模型产生的分析与初级律师在审查事务所分析指南后撰写的内容相当。

    从一个模型到可扩展的业务

    一旦完成第一个法律模型的微调,流程就可以复制:

    1. **相同工作流程,不同客户:**每个新的律师事务所项目遵循相同的数据 → 训练 → 部署流程
    2. **相同基础模型,不同适配器:**从同一基础模型训练客户专属 LoRA 适配器
    3. **相同基础设施,多个模型:**单个 GPU 通过适配器热切换服务多个客户模型
    4. **组合定价:**每增加一个客户,单客户成本递减,利润率提升

    阻止您的代理机构进入法律垂直领域的 ML 瓶颈已不复存在。


    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