Toggle Dark Mode

Text Summarization

The Azure Text Summarization service provides state‑of‑the‑art, extractive and abstractive summarization for large documents, articles, and conversation transcripts. It helps users quickly understand the key points of a piece of text.

Key Features

Quickstart Demo

Python Sample

import os, requests, json

endpoint = os.getenv("AZURE_ENDPOINT")
key = os.getenv("AZURE_API_KEY")
path = "/language/:analyze-text?api-version=2023-04-01-preview"

def summarize(text, length="medium"):
    url = endpoint + path
    headers = {
        "Ocp-Apim-Subscription-Key": key,
        "Content-Type": "application/json"
    }
    body = {
        "kind": "ExtractiveSummarization",
        "analysisInput": {"documents": [{"id": "1", "language": "en", "text": text}]},
        "parameters": {"summaryLength": length}
    }
    response = requests.post(url, headers=headers, json=body)
    response.raise_for_status()
    result = response.json()
    return result["summaries"][0]["text"]

sample = """Your long text goes here..."""
print(summarize(sample, "short"))

REST API Reference

POST https://{endpoint}/language/:analyze-text?api-version=2023-04-01-preview
Headers:
  Ocp-Apim-Subscription-Key: {key}
  Content-Type: application/json
Body:
{
  "kind": "ExtractiveSummarization",
  "analysisInput": {
    "documents": [
      {
        "id": "1",
        "language": "en",
        "text": "Your text..."
      }
    ]
  },
  "parameters": {
    "summaryLength": "medium"
  }
}
Response:
{
  "summaries": [
    {
      "text": "Summarized content..."
    }
  ]
}