Skip to main content
Article
summarizationnlptext-condensationcontent-analysisextractive-summarizationabstractive-summarizationinformation-retrieval

Generate Concise Summaries from Long Text

Condense articles, reports, or documents into short, readable summaries. Use the Summarization skill to extract key points, control output length, and focus on specific topics, saving significant reading time.

beginner15 min4 steps
The play
  1. Create a Basic Extractive Summary
    Start with extractive summarization. This method pulls the most important sentences directly from the source text, making it fast and factually grounded. It's ideal for quickly getting the main points without any interpretation.
  2. Generate an Abstractive Summary
    For a more natural, human-like summary, switch to the abstractive method. The Summarization skill will generate new sentences that capture the core ideas, much like a person would. This is better for readability but may be slightly slower.
  3. Control the Summary Length
    Easily control the output size using the 'length' parameter. You can specify a target in sentences, words, or as a percentage of the original document to fit your exact needs.
  4. Focus the Summary on Key Topics
    Guide the summarization process by providing a list of keywords or topics with the 'focus' parameter. This creates a summary tailored to a specific area of interest within a larger document.
Starter code
import textwrap

# This is a mock class to make the example runnable.
# In a real scenario, you would import and instantiate the skill library.
class MockSummarizationSkill:
    """A mock implementation of the Summarization skill for demonstration."""
    def run(self, text: str, method: str = 'extractive', length: str = '3 sentences', focus: list = None):
        print(f"--- Running Summarization ---")
        print(f"Method: {method}, Length: {length}, Focus: {focus or 'None'}")
        # In a real implementation, this would call the AI model.
        # Here, we return a simple, hardcoded summary for demonstration.
        if focus and 'solar' in ' '.join(focus):
            return "The report highlights significant growth in the solar energy sector. Key investments in new technology are driving down costs. Future outlook remains positive with projected market expansion."
        else:
            return "The quarterly report indicates steady growth across all sectors. The company is investing in new technology and expanding its market reach. The financial outlook for the next quarter is positive."

# 1. Instantiate the Summarization skill
summarizer = MockSummarizationSkill()

# 2. Define a long document to summarize
long_text = """
In the latest quarterly report, the energy conglomerate posted record profits, driven largely by its renewable energy division. The solar energy sector, in particular, saw a 40% increase in revenue year-over-year. This growth is attributed to key investments in next-generation photovoltaic technology and a strategic expansion into new international markets. The report details the company's commitment to reducing its carbon footprint, with a new initiative aimed at improving supply chain logistics to minimize waste. While the fossil fuel division remained profitable, its growth was flat, signaling a broader market shift. The board expressed confidence that the focus on sustainable energy sources will ensure long-term financial health and market leadership. The outlook for the next quarter is overwhelmingly positive, with further market expansion planned.
"""

# 3. Run the summarization with specific parameters
summary = summarizer.run(
    long_text,
    method='abstractive',
    length='3 sentences',
    focus=['solar energy', 'market expansion']
)

# 4. Print the result
print("\n--- Original Text ---")
print(textwrap.fill(long_text, width=80))
print("\n--- Generated Summary ---")
print(summary)
Generate Concise Summaries from Long Text — Action Pack