Loading...
    • 開發者指南
    • API 參考
    • MCP
    • 資源
    • 發行說明
    Search...
    ⌘K

    資源

    overview詞彙表系統提示

    使用案例

    概述工單路由客戶支援代理內容審核法律文件摘要

    提示詞庫

    提示詞庫宇宙按鍵企業先知網站精靈Excel 公式專家Google apps 腳本編寫器Python 錯誤修復器時間旅行顧問故事創作夥伴引用您的來源SQL 魔法師夢境解析師雙關語專家烹飪創作者混成詞詩人Hal 幽默助手LaTeX 傳奇情緒色彩化器Git gud比喻專家倫理困境導航器會議記錄員成語解釋器程式碼顧問函數製造器新詞創造者CSV 轉換器表情符號編碼器散文潤飾師觀點思考者問答題產生器正念導師二年級簡化器VR 健身創新者PII 淨化器備忘錄大師職業教練評分專家繞口令面試問題製作器語法精靈猜猜這個謎題程式碼解釋器外星人類學家資料整理器品牌建構師效率估算器評論分類器方向解碼器激勵繆思電子郵件提取器主審查員課程規劃師蘇格拉底式智者頭韻煉金術師未來主義時尚顧問多語言超能力產品命名專家哲學思辨試算表魔法師科幻情境模擬器適應性編輯器Babel的廣播推文語調檢測器機場代碼分析器
    Console
    使用案例

    法律文件摘要

    本指南介紹如何利用 Claude 的先進自然語言處理能力,有效地總結法律文件、提取關鍵資訊並加快法律研究。使用 Claude,您可以簡化合約審查、訴訟準備和監管工作的流程,節省時間並確保法律流程的準確性。

    訪問我們的摘要食譜,查看使用 Claude 的法律摘要實現範例。

    使用 Claude 進行構建前

    決定是否使用 Claude 進行法律文件摘要

    以下是一些關鍵指標,表明您應該使用 Claude 等大型語言模型來總結法律文件:

    確定您希望摘要提取的詳細資訊

    任何給定文件都沒有單一正確的摘要。沒有明確的指導,Claude 可能難以確定要包含哪些詳細資訊。為了獲得最佳結果,請確定您想要在摘要中包含的具體資訊。

    例如,在總結轉租協議時,您可能希望提取以下關鍵要點:

    details_to_extract = [
        'Parties involved (sublessor, sublessee, and original lessor)',
        'Property details (address, description, and permitted use)', 
        'Term and rent (start date, end date, monthly rent, and security deposit)',
        'Responsibilities (utilities, maintenance, and repairs)',
        'Consent and notices (landlord\'s consent, and notice requirements)',
        'Special provisions (furniture, parking, and subletting restrictions)'
    ]

    建立成功標準

    評估摘要的品質是一項公認的具有挑戰性的任務。與許多其他自然語言處理任務不同,摘要的評估通常缺乏明確的客觀指標。此過程可能高度主觀,不同的讀者重視摘要的不同方面。以下是您在評估 Claude 執行法律摘要的效果時可能希望考慮的標準。

    有關更多資訊,請參閱我們的建立成功標準指南。


    如何使用 Claude 總結法律文件

    選擇正確的 Claude 模型

    在總結法律文件時,模型準確性極其重要。Claude Sonnet 4.5 是需要高準確性的此類用例的絕佳選擇。如果您的文件大小和數量很大,以至於成本開始成為問題,您也可以嘗試使用較小的模型,如 Claude Haiku 4.5。

    為了幫助估計這些成本,以下是使用 Sonnet 和 Haiku 總結 1,000 份轉租協議的成本比較:

    • 內容大小

      • 協議數量:1,000
      • 每份協議的字元數:300,000
      • 總字元數:300M
    • 估計的代幣

      • 輸入代幣:86M(假設每 3.5 個字元 1 個代幣)
      • 每份摘要的輸出代幣:350
      • 總輸出代幣:350,000
    • Claude Sonnet 4.5 估計成本

      • 輸入代幣成本:86 MTok * $3.00/MTok = $258
      • 輸出代幣成本:0.35 MTok * $15.00/MTok = $5.25
      • 總成本:$258.00 + $5.25 = $263.25
    • Claude Haiku 3 估計成本

      • 輸入代幣成本:86 MTok * $0.25/MTok = $21.50
      • 輸出代幣成本:0.35 MTok * $1.25/MTok = $0.44
      • 總成本:$21.50 + $0.44 = $21.96
    實際成本可能與這些估計不同。這些估計基於提示部分中突出顯示的範例。

    將文件轉換為 Claude 可以處理的格式

    在開始總結文件之前,您需要準備您的數據。這涉及從 PDF 中提取文本、清理文本並確保其準備好由 Claude 處理。

    以下是此流程在示例 pdf 上的演示:

    from io import BytesIO
    import re
    
    import pypdf
    import requests
    
    def get_llm_text(pdf_file):
        reader = pypdf.PdfReader(pdf_file)
        text = "\n".join([page.extract_text() for page in reader.pages])
    
        # Remove extra whitespace
        text = re.sub(r'\s+', ' ', text) 
    
        # Remove page numbers
        text = re.sub(r'\n\s*\d+\s*\n', '\n', text) 
    
        return text
    
    
    # Create the full URL from the GitHub repository
    url = "https://raw.githubusercontent.com/anthropics/anthropic-cookbook/main/skills/summarization/data/Sample Sublease Agreement.pdf"
    url = url.replace(" ", "%20")
    
    # Download the PDF file into memory
    response = requests.get(url)
    
    # Load the PDF from memory
    pdf_file = BytesIO(response.content)
    
    document_text = get_llm_text(pdf_file) 
    print(document_text[:50000]) 

    在此範例中,我們首先下載摘要食譜中使用的示例轉租協議的 pdf。此協議來自sec.gov 網站上的公開轉租協議。

    我們使用 pypdf 庫提取 pdf 的內容並將其轉換為文本。然後通過移除額外的空白和頁碼來清理文本數據。

    構建強大的提示

    Claude 可以適應各種摘要風格。您可以更改提示的詳細資訊,以指導 Claude 更詳細或更簡潔、包含更多或更少的技術術語,或提供更高或更低層次的上下文摘要。

    以下是如何建立提示的範例,以確保在分析轉租協議時生成的摘要遵循一致的結構:

    import anthropic
    
    # Initialize the Anthropic client
    client = anthropic.Anthropic()
    
    def summarize_document(text, details_to_extract, model="claude-sonnet-4-5", max_tokens=1000):
    
        # Format the details to extract to be placed within the prompt's context
        details_to_extract_str = '\n'.join(details_to_extract)
        
        # Prompt the model to summarize the sublease agreement
        prompt = f"""Summarize the following sublease agreement. Focus on these key aspects:
    
        {details_to_extract_str}
    
        Provide the summary in bullet points nested within the XML header for each section. For example:
    
        <parties involved>
        - Sublessor: [Name]
        // Add more details as needed
        </parties involved>
        
        If any information is not explicitly stated in the document, note it as "Not specified". Do not preamble.
    
        Sublease agreement text:
        {text}
        """
    
        response = client.messages.create(
            model=model,
            max_tokens=max_tokens,
            system="You are a legal analyst specializing in real estate law, known for highly accurate and detailed summaries of sublease agreements.",
            messages=[
                {"role": "user", "content": prompt},
                {"role": "assistant", "content": "Here is the summary of the sublease agreement: <summary>"}
            ],
            stop_sequences=["</summary>"]
        )
    
        return response.content[0].text
    
    sublease_summary = summarize_document(document_text, details_to_extract)
    print(sublease_summary)

    此代碼實現了一個 summarize_document 函數,該函數使用 Claude 總結轉租協議的內容。該函數接受文本字符串和要提取的詳細資訊列表作為輸入。在此範例中,我們使用之前代碼片段中定義的 document_text 和 details_to_extract 變數呼叫該函數。

    在函數中,為 Claude 生成提示,包括要總結的文件、要提取的詳細資訊以及總結文件的具體說明。提示指示 Claude 在 XML 標頭中以嵌套方式回應每個詳細資訊提取的摘要。

    因為我們決定在標籤中輸出摘要的每個部分,所以每個部分可以輕鬆地作為後處理步驟進行解析。此方法可實現結構化摘要,可針對您的用例進行調整,以便每份摘要遵循相同的模式。

    評估您的提示

    提示通常需要測試和優化才能準備好用於生產。為了確定解決方案的準備情況,請使用結合定量和定性方法的系統流程評估摘要的品質。根據您定義的成功標準建立強大的經驗評估將允許您優化提示。以下是您可能希望在經驗評估中包含的一些指標:

    部署您的提示

    以下是部署解決方案到生產時要牢記的一些其他考慮事項。

    1. 確保沒有責任:了解摘要中錯誤的法律含義,這可能導致您的組織或客戶的法律責任。提供免責聲明或法律通知,澄清摘要由人工智能生成,應由法律專業人士審查。

    2. 處理多種文件類型:在本指南中,我們討論了如何從 PDF 中提取文本。在現實中,文件可能採用多種格式(PDF、Word 文件、文本文件等)。確保您的數據提取管道可以轉換您期望接收的所有文件格式。

    3. 並行化對 Claude 的 API 呼叫:具有大量代幣的長文件可能需要長達一分鐘的時間才能讓 Claude 生成摘要。對於大型文件集合,您可能希望並行向 Claude 發送 API 呼叫,以便摘要可以在合理的時間範圍內完成。請參閱 Anthropic 的速率限制以確定可以並行執行的最大 API 呼叫數。


    改進效能

    在複雜的情況下,除了標準提示工程技術外,考慮其他策略來改進效能可能會有所幫助。以下是一些進階策略:

    執行元摘要以總結長文件

    法律摘要通常涉及處理長文件或一次處理許多相關文件,使得您超過 Claude 的上下文視窗。您可以使用稱為元摘要的分塊方法來處理此用例。此技術涉及將文件分解為較小的、可管理的塊,然後分別處理每個塊。然後,您可以組合每個塊的摘要以建立整個文件的元摘要。

    以下是如何執行元摘要的範例:

    import anthropic
    
    # Initialize the Anthropic client
    client = anthropic.Anthropic()
    
    def chunk_text(text, chunk_size=20000):
        return [text[i:i+chunk_size] for i in range(0, len(text), chunk_size)]
    
    def summarize_long_document(text, details_to_extract, model="claude-sonnet-4-5", max_tokens=1000):
    
        # Format the details to extract to be placed within the prompt's context
        details_to_extract_str = '\n'.join(details_to_extract)
    
        # Iterate over chunks and summarize each one
        chunk_summaries = [summarize_document(chunk, details_to_extract, model=model, max_tokens=max_tokens) for chunk in chunk_text(text)]
        
        final_summary_prompt = f"""
        
        You are looking at the chunked summaries of multiple documents that are all related. 
        Combine the following summaries of the document from different truthful sources into a coherent overall summary:
    
        <chunked_summaries>
        {"".join(chunk_summaries)}
        </chunked_summaries>
    
        Focus on these key aspects:
        {details_to_extract_str})
    
        Provide the summary in bullet points nested within the XML header for each section. For example:
    
        <parties involved>
        - Sublessor: [Name]
        // Add more details as needed
        </parties involved>
        
        If any information is not explicitly stated in the document, note it as "Not specified". Do not preamble.
        """
    
        response = client.messages.create(
            model=model,
            max_tokens=max_tokens,
            system="You are a legal expert that summarizes notes on one document.",
            messages=[
                {"role": "user",  "content": final_summary_prompt},
                {"role": "assistant", "content": "Here is the summary of the sublease agreement: <summary>"}
    
            ],
            stop_sequences=["</summary>"]
        )
        
        return response.content[0].text
    
    long_summary = summarize_long_document(document_text, details_to_extract)
    print(long_summary)

    summarize_long_document 函數通過將文件分割成較小的塊並分別總結每個塊來建立在早期 summarize_document 函數的基礎上。

    代碼通過將 summarize_document 函數應用於原始文件中的每個 20,000 字元的塊來實現此目的。然後組合各個摘要,並從這些塊摘要建立最終摘要。

    請注意,summarize_long_document 函數對於我們的範例 pdf 並非嚴格必要的,因為整個文件適合 Claude 的上下文視窗。但是,對於超過 Claude 上下文視窗的文件或在總結多個相關文件時,它變得必不可少。無論如何,此元摘要技術通常在最終摘要中捕捉到早期單摘要方法中遺漏的其他重要詳細資訊。

    使用摘要索引文件探索大型文件集合

    使用大型語言模型搜尋文件集合通常涉及檢索增強生成 (RAG)。但是,在涉及大型文件或當精確資訊檢索至關重要時,基本 RAG 方法可能不夠。摘要索引文件是一種進階 RAG 方法,提供了一種更有效的方式來對檢索文件進行排名,使用的上下文比傳統 RAG 方法少。在此方法中,您首先使用 Claude 為語料庫中的每個文件生成簡潔摘要,然後使用 Claude 對每份摘要與所提出的查詢的相關性進行排名。有關此方法的進一步詳細資訊,包括基於代碼的範例,請查看摘要食譜中的摘要索引文件部分。

    微調 Claude 以從您的數據集中學習

    改進 Claude 生成摘要能力的另一種進階技術是微調。微調涉及在與您的法律摘要需求特別一致的自訂數據集上訓練 Claude,確保 Claude 適應您的用例。以下是如何執行微調的概述:

    1. 識別錯誤:首先收集 Claude 摘要不足的實例 - 這可能包括遺漏關鍵法律詳細資訊、誤解上下文或使用不適當的法律術語。

    2. 策劃數據集:一旦您識別了這些問題,請編譯這些有問題範例的數據集。此數據集應包括原始法律文件以及您更正的摘要,確保 Claude 學習所需的行為。

    3. 執行微調:微調涉及在您的策劃數據集上重新訓練模型以調整其權重和參數。此重新訓練幫助 Claude 更好地理解您的法律領域的具體要求,改進其根據您的標準總結文件的能力。

    4. 迭代改進:微調不是一次性流程。當 Claude 繼續生成摘要時,您可以迭代地添加它表現不佳的新範例,進一步完善其功能。隨著時間的推移,此持續反饋循環將產生一個高度專門用於您的法律摘要任務的模型。

    微調目前僅通過 Amazon Bedrock 提供。其他詳細資訊可在 AWS 啟動部落格中取得。

    摘要食譜

    查看如何使用 Claude 總結合約的完整實現代碼範例。

    引用食譜

    探索我們的引用食譜配方,以獲得有關如何確保資訊準確性和可解釋性的指導。

    • 使用 Claude 進行構建前
    • 決定是否使用 Claude 進行法律文件摘要
    • 如何使用 Claude 總結法律文件
    • 選擇正確的 Claude 模型
    • 將文件轉換為 Claude 可以處理的格式
    • 微調 Claude 以從您的數據集中學習
    © 2025 ANTHROPIC PBC

    Products

    • Claude
    • Claude Code
    • Max plan
    • Team plan
    • Enterprise plan
    • Download app
    • Pricing
    • Log in

    Features

    • Claude and Slack
    • Claude in Excel

    Models

    • Opus
    • Sonnet
    • Haiku

    Solutions

    • AI agents
    • Code modernization
    • Coding
    • Customer support
    • Education
    • Financial services
    • Government
    • Life sciences

    Claude Developer Platform

    • Overview
    • Developer docs
    • Pricing
    • Amazon Bedrock
    • Google Cloud’s Vertex AI
    • Console login

    Learn

    • Blog
    • Catalog
    • Courses
    • Use cases
    • Connectors
    • Customer stories
    • Engineering at Anthropic
    • Events
    • Powered by Claude
    • Service partners
    • Startups program

    Company

    • Anthropic
    • Careers
    • Economic Futures
    • Research
    • News
    • Responsible Scaling Policy
    • Security and compliance
    • Transparency

    Help and security

    • Availability
    • Status
    • Support center

    Terms and policies

    • Privacy policy
    • Responsible disclosure policy
    • Terms of service: Commercial
    • Terms of service: Consumer
    • Usage policy

    Products

    • Claude
    • Claude Code
    • Max plan
    • Team plan
    • Enterprise plan
    • Download app
    • Pricing
    • Log in

    Features

    • Claude and Slack
    • Claude in Excel

    Models

    • Opus
    • Sonnet
    • Haiku

    Solutions

    • AI agents
    • Code modernization
    • Coding
    • Customer support
    • Education
    • Financial services
    • Government
    • Life sciences

    Claude Developer Platform

    • Overview
    • Developer docs
    • Pricing
    • Amazon Bedrock
    • Google Cloud’s Vertex AI
    • Console login

    Learn

    • Blog
    • Catalog
    • Courses
    • Use cases
    • Connectors
    • Customer stories
    • Engineering at Anthropic
    • Events
    • Powered by Claude
    • Service partners
    • Startups program

    Company

    • Anthropic
    • Careers
    • Economic Futures
    • Research
    • News
    • Responsible Scaling Policy
    • Security and compliance
    • Transparency

    Help and security

    • Availability
    • Status
    • Support center

    Terms and policies

    • Privacy policy
    • Responsible disclosure policy
    • Terms of service: Commercial
    • Terms of service: Consumer
    • Usage policy
    © 2025 ANTHROPIC PBC