如何使用文件摘要

檔摘要的設計目的是縮短使用者認為太長而無法讀取的內容。 擷取和抽象摘要會壓縮文章、論文或檔到關鍵句子。

擷取摘要 :藉由擷取共同代表原始內容內最重要的或相關資訊的句子來產生摘要。

抽象摘要 :從擷取主要想法的檔產生摘要句子來產生摘要。

這兩項功能都可以在指定時摘要說明感興趣的特定專案。

API 所使用的 AI 模型是由服務提供,您只需要傳送內容進行分析即可。

功能

提示

如果您想要開始使用這些功能,您可以遵循 快速入門文章 來開始使用。 您也可以使用 Language Studio 提出範例要求,而不需要撰寫程式碼。

擷取摘要 API 會使用自然語言處理技術,在非結構化文字檔中尋找主要句子。 這些句子會共同傳達檔的主要概念。

擷取摘要會傳回排名分數作為系統回應的一部分,以及擷取的句子及其在原始檔案中的位置。 排名分數是判斷句子與檔主要概念相關的指標。 此模型會為每個句子提供介於 0 到 1 之間的分數,並傳回每個要求的最高評分句子。 例如,如果您要求三個句子摘要,服務會傳回三個最高評分句子。

Azure AI 語言中有另一項功能, 關鍵字組擷取 ,可擷取關鍵資訊。 在關鍵字組擷取和擷取摘要之間決定時,請考慮下列事項:

  • 關鍵字組擷取會在擷取摘要傳回句子時傳回片語。
  • 擷取摘要會傳回句子與排名分數,而且每個要求會傳回排名最高的句子。
  • 擷取摘要也會傳回下列位置資訊:
    • Offset:每個擷取句子的開始位置。
    • 長度:每個擷取句子的長度。

決定如何處理資料(選擇性)

提交資料

您以文字字串的形式將檔提交至 API。 在收到要求時,會執行分析。 因為 API 是 非同步 的,因此傳送 API 要求和接收結果之間可能會有延遲。

當您使用這項功能時,API 結果會在擷取要求後 24 小時內提供,並在回應中指出。 在此期間之後,系統會清除結果,且無法再進行擷取。

取得檔摘要結果

當您從語言偵測取得結果時,您可以將結果串流至應用程式,或將輸出儲存到本機系統上的檔案。

以下是您可能會提交摘要的內容範例,其使用 Microsoft 部落格文章 整合 AI 的整體標記法來擷取。 本文只是範例,API 可以接受較長的輸入文字。 如需詳細資訊,請參閱資料限制一節。

「在 Microsoft,我們一直在尋求超越現有技術來提升 AI,方法是採用更全面、以人為本的學習和理解方法。 身為 Azure AI 服務的技術長,我一直致力於與優秀的科學家和工程師合作,將這項追求轉變成現實。 在我的角色中,我享有獨特的視角來檢視人類認知的三個屬性之間的關係:單語言文字(X)、音訊或視覺感訊號、(Y)和多語系(Z)。 在這三者交集時,有魔術,我們稱之為 XYZ 程式碼,如圖 1 所示,這是一個聯合標記法,可建立更強大的 AI,以更能說話、聆聽、查看及瞭解人類。 我們相信 XYZ 程式碼可讓我們實現我們的長期願景:跨領域轉移學習、跨越形式和語言。 目標是讓預先定型的模型能夠共同學習標記法,以支援廣泛的下游 AI 工作,就像人類現今所做的一樣。 在過去五年中,我們在對話式語音辨識、機器翻譯、對話式問答、機器閱讀理解和影像標題方面取得了人類效能。 這五項突破為我們提供了更雄心勃勃的信號,以產生 AI 功能的飛躍,實現多感應器和多語系學習,這更符合人類學習和理解的方式。 我相信,如果以下游 AI 工作中的外部知識來源為基礎,聯合 XYZ 程式碼是此願望的基礎元件。

檔摘要 API 要求會在收到要求時處理,方法是建立 API 後端的作業。 如果作業成功,則會傳回 API 的輸出。 輸出可供擷取 24 小時。 在此時間之後,會清除輸出。 由於多語系和表情符號支援,回應可能包含文字位移。 如需詳細資訊, 請參閱 如何處理位移。

當您使用上述範例時,API 可能會傳回下列摘要句子:

擷取摘要

  • 「在 Microsoft,我們一直在尋求超越現有技術來推進 AI,方法是採用更全面、以人為本的學習和理解方法。
  • 「我們相信 XYZ 程式碼可讓我們實現我們的長期願景:跨領域轉移學習、跨越形式和語言。
  • 「目標是讓預先定型的模型能夠共同學習標記法,以支援廣泛的下游 AI 工作,就像人類今天所做的一樣。

抽象摘要

  • 「Microsoft 正在採取更全面、以人為本的方法來學習和理解。 我們相信 XYZ 程式碼可讓我們實現我們的長期願景:跨領域轉移學習、跨越形式和語言。 在過去的五年裡,我們在基準方面取得了人類的表現。

嘗試檔擷取摘要

您可以使用檔擷取摘要來取得文章、檔或檔的摘要。 若要查看範例,請參閱 快速入門文章

您可以使用 sentenceCount 參數來引導傳回多少個句子,且 3 為預設值。 範圍從 1 到 20。

您也可以使用 sortby 參數來指定所擷取句子的傳回順序 - OffsetRank ,其 Offset 為預設值。

參數值 描述
順位 根據其與輸入檔的相關性來排序句子,如服務所決定。
Offset 保留句子出現在輸入檔中的原始順序。

試用檔抽象摘要

下列範例會讓您開始使用檔抽象摘要:

  1. 將下列命令複製到文字編輯器。 BASH 範例會使用 \ 行接續字元。 如果您的主控台或終端機使用不同的行接續字元,請改用該字元。
curl -i -X POST https://<your-language-resource-endpoint>/language/analyze-text/jobs?api-version=2022-10-01-preview \
-H "Content-Type: application/json" \
-H "Ocp-Apim-Subscription-Key: <your-language-resource-key>" \
-d \
' 
{
  "displayName": "Document Abstractive Summarization Task Example",
  "analysisInput": {
    "documents": [
      {
        "id": "1",
        "language": "en",
        "text": "At Microsoft, we have been on a quest to advance AI beyond existing techniques, by taking a more holistic, human-centric approach to learning and understanding. As Chief Technology Officer of Azure AI services, I have been working with a team of amazing scientists and engineers to turn this quest into a reality. In my role, I enjoy a unique perspective in viewing the relationship among three attributes of human cognition: monolingual text (X), audio or visual sensory signals, (Y) and multilingual (Z). At the intersection of all three, there’s magic—what we call XYZ-code as illustrated in Figure 1—a joint representation to create more powerful AI that can speak, hear, see, and understand humans better. We believe XYZ-code enables us to fulfill our long-term vision: cross-domain transfer learning, spanning modalities and languages. The goal is to have pretrained models that can jointly learn representations to support a broad range of downstream AI tasks, much in the way humans do today. Over the past five years, we have achieved human performance on benchmarks in conversational speech recognition, machine translation, conversational question answering, machine reading comprehension, and image captioning. These five breakthroughs provided us with strong signals toward our more ambitious aspiration to produce a leap in AI capabilities, achieving multi-sensory and multilingual learning that is closer in line with how humans learn and understand. I believe the joint XYZ-code is a foundational component of this aspiration, if grounded with external knowledge sources in the downstream AI tasks."
      }
    ]
  },
  "tasks": [
    {
      "kind": "AbstractiveSummarization",
      "taskName": "Document Abstractive Summarization Task 1",
      "parameters": {
        "summaryLength": short
      }
    }
  ]
}
'

如果您未指定 sentenceCount ,模型會決定摘要長度。 請注意,sentenceCount 是輸出摘要的句子計數近似值,範圍為 1 到 20。 不建議使用 sentenceCount 進行抽象摘要。

  1. 視需要在命令中進行下列變更:

    • 以您的索引鍵取代 值 your-language-resource-key
    • 將要求 URL your-language-resource-endpoint 的第一個部分取代為您的端點 URL。
  2. 開啟命令提示字元視窗(例如:BASH)。

  3. 將命令從文字編輯器貼到命令提示字元視窗中,然後執行 命令。

  4. operation-location從回應標頭取得 。 值看起來類似下列 URL:

https://<your-language-resource-endpoint>/language/analyze-text/jobs/12345678-1234-1234-1234-12345678?api-version=2022-10-01-preview
  1. 若要取得要求的結果,請使用下列 cURL 命令。 請務必將 取代 <my-job-id> 為您從上 operation-location 一個回應標頭收到的數值識別碼值:
curl -X GET https://<your-language-resource-endpoint>/language/analyze-text/jobs/<my-job-id>?api-version=2022-10-01-preview \
-H "Content-Type: application/json" \
-H "Ocp-Apim-Subscription-Key: <your-language-resource-key>"

抽象檔摘要範例 JSON 回應

{
    "jobId": "cd6418fe-db86-4350-aec1-f0d7c91442a6",
    "lastUpdateDateTime": "2022-09-08T16:45:14Z",
    "createdDateTime": "2022-09-08T16:44:53Z",
    "expirationDateTime": "2022-09-09T16:44:53Z",
    "status": "succeeded",
    "errors": [],
    "displayName": "Document Abstractive Summarization Task Example",
    "tasks": {
        "completed": 1,
        "failed": 0,
        "inProgress": 0,
        "total": 1,
        "items": [
            {
                "kind": "AbstractiveSummarizationLROResults",
                "taskName": "Document Abstractive Summarization Task 1",
                "lastUpdateDateTime": "2022-09-08T16:45:14.0717206Z",
                "status": "succeeded",
                "results": {
                    "documents": [
                        {
                            "summaries": [
                                {
                                    "text": "Microsoft is taking a more holistic, human-centric approach to AI. We've developed a joint representation to create more powerful AI that can speak, hear, see, and understand humans better. We've achieved human performance on benchmarks in conversational speech recognition, machine translation, ...... and image captions.",
                                    "contexts": [
                                        {
                                            "offset": 0,
                                            "length": 247
                                        }
                                    ]
                                }
                            ],
                            "id": "1"
                        }
                    ],
                    "errors": [],
                    "modelVersion": "latest"
                }
            }
        ]
    }
}
parameter 描述
-X POST <endpoint> 指定用於存取 API 的端點。
-H Content-Type: application/json 傳送 JSON 資料的內容類型。
-H "Ocp-Apim-Subscription-Key:<key> 指定用來存取 API 的金鑰。
-d <documents> 包含您要傳送之檔的 JSON。

下列 cURL 命令是從 BASH 殼層執行。 使用您自己的資源名稱、資源索引鍵和 JSON 值來編輯這些命令。

以查詢為基礎的摘要

以查詢為基礎的檔摘要 API 是現有檔摘要 API 的延伸模組。

最大的差異是要求主體中的新 query 欄位(在 下 querytasksparameters>> )。 此外,有一個新方法可以指定短/中/長「貯體」中的慣 summaryLength 用,我們建議使用 而非 sentenceCount ,特別是在使用抽象時。 以下是範例要求:

curl -i -X POST https://<your-language-resource-endpoint>/language/analyze-text/jobs?api-version=2023-11-15-preview \
-H "Content-Type: application/json" \
-H "Ocp-Apim-Subscription-Key: <your-language-resource-key>" \
-d \
' 
{
  "displayName": "Document Extractive Summarization Task Example",
  "analysisInput": {
    "documents": [
      {
        "id": "1",
        "language": "en",
        "text": "At Microsoft, we have been on a quest to advance AI beyond existing techniques, by taking a more holistic, human-centric approach to learning and understanding. As Chief Technology Officer of Azure AI services, I have been working with a team of amazing scientists and engineers to turn this quest into a reality. In my role, I enjoy a unique perspective in viewing the relationship among three attributes of human cognition: monolingual text (X), audio or visual sensory signals, (Y) and multilingual (Z). At the intersection of all three, there’s magic—what we call XYZ-code as illustrated in Figure 1—a joint representation to create more powerful AI that can speak, hear, see, and understand humans better. We believe XYZ-code enables us to fulfill our long-term vision: cross-domain transfer learning, spanning modalities and languages. The goal is to have pretrained models that can jointly learn representations to support a broad range of downstream AI tasks, much in the way humans do today. Over the past five years, we have achieved human performance on benchmarks in conversational speech recognition, machine translation, conversational question answering, machine reading comprehension, and image captioning. These five breakthroughs provided us with strong signals toward our more ambitious aspiration to produce a leap in AI capabilities, achieving multi-sensory and multilingual learning that is closer in line with how humans learn and understand. I believe the joint XYZ-code is a foundational component of this aspiration, if grounded with external knowledge sources in the downstream AI tasks."
      }
    ]
  },
  "tasks": [
    {
      "kind": "ExtractiveSummarization",
      "taskName": "Document Extractive Summarization Task 1",
      "parameters": {
        "query": "XYZ-code",
        "summaryLength": short
      }
    }
  ]
}
'

使用 summaryParameter

summaryLength針對 參數,會接受三個值:

  • short:產生大部分 2-3 個句子的摘要,大約 120 個標記。
  • 中:產生最多 4-6 個句子的摘要,其中包含大約 170 個標記。
  • long:產生最多超過 7 個句子的摘要,大約 210 個標記。

服務和資料限制

如需您可以每秒傳送的要求大小和數目的相關資訊,請參閱 服務限制 一文。

另請參閱