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. 從儀表板點擊新建項目
    3. 命名為:「法律合約審查 - 教學」
    4. 選擇項目類型:微調

    你現在在 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. 在你的項目中點擊上傳資料

    2. 選擇你的 JSONL 文件(或拖放)

    3. Studio 驗證格式並顯示預覽:

      • 總範例數:顯示
      • 平均指令長度:顯示
      • 平均回應長度:顯示
      • 任何格式問題:標記出來
    4. 審查預覽——滾動瀏覽幾個範例以確認它們看起來正確

    5. 點擊確認上傳

    如果你沒有準備好法律資料集,Ertas Studio 包含常見使用案例的樣本資料集。選擇「法律合約分析」樣本資料集以繼續教學。

    第 10-15 分鐘:配置訓練

    上傳資料後,配置微調任務。

    基礎模型選擇

    點擊選擇基礎模型。在本教學中:

    • Llama 3.1 8B(推薦)——法律任務的品質和速度之間的良好平衡
    • Mistral 7B——可行的替代方案,輸出風格稍有不同

    選擇 Llama 3.1 8B

    訓練參數

    Studio 顯示帶有說明的預設參數。在本教學中,保持預設值:

    參數預設值含義
    適配器類型LoRA訓練一個小型適配器而不是修改整個模型
    LoRA rank16控制模型可以學習多少(16 是一個好的預設值)
    LoRA alpha32縮放因子(2 倍 rank 是標準)
    Epochs3訓練資料的訓練輪次
    學習率2e-4模型學習的積極程度
    Batch size自動Studio 根據你的資料和可用 GPU 優化

    對生產模型,你可能會根據結果調整這些。對教學,預設值效果很好。

    驗證分割

    Studio 自動保留 10% 的資料用於驗證——這些範例在訓練期間不使用,並在之後用於測量品質。這是標準的 ML 實踐,自動進行。

    第 15-20 分鐘:執行微調

    點擊開始訓練

    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 分鐘:匯出你的模型

    對品質滿意了嗎?匯出模型進行部署。

    匯出選項

    點擊匯出模型並選擇你的格式:

    • GGUF(大多數部署的推薦)——與 Ollama 本地推論兼容
    • SafeTensors——與 vLLM、Hugging Face Transformers 兼容
    • 僅 LoRA 適配器——只是適配器文件,與基礎模型一起使用

    在本教學中,選擇 GGUF

    下載

    Studio 打包並量化模型(在保持品質的同時減小文件大小)。對 8B 模型,下載通常為 4-6 GB。

    部署(附加步驟)

    在本地運行你的模型:

    # 安裝 Ollama(如果還沒有的話)
    # 訪問 https://ollama.com
    
    # 創建 Modelfile
    echo 'FROM /path/to/your-exported-model.gguf' > Modelfile
    
    # 註冊模型
    ollama create legal-contract-review -f Modelfile
    
    # 測試
    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