Summarizing and rewriting text

Introduction to Claude Models

Nikhil Rangarajan

Data Scientist

Summarization tasks

  • Summarizing long reports

A page representing a summarized doc

Introduction to Claude Models

Summarization tasks

  • Summarizing long reports
  • Rewriting technical docs

A page representing a summarized doc, and a window open on an API coding repository

Introduction to Claude Models

Summarization tasks

  • Summarizing long reports
  • Rewriting technical docs
  • Changing from formal to friendly tone

$$

Maintains meaning while changing format

A page representing a summarized doc, a window open on an API coding repository, and a person reading a formal doc

Introduction to Claude Models

Summarization techniques

  • Specific prompt
  • Length control: Specify word count or paragraph limits
  • Focus points
# Summarization prompt
prompt = """Please summarize the 
following text in 2-3 sentences:
{project_report}. Focus on project 
updates."""

response = client.messages.create(
    model="claude-sonnet-4-20250514",
    messages=[{"role": "user", 
               "content": prompt}]
)
Introduction to Claude Models

Rewriting with system messages

  • System messages control tone and style globally
  • Tone options: Professional, casual, technical, friendly
  • Consistency: System message applies to entire conversation
messages=[{"role": "user", 
               "content": prompt}]

system_message = """You are a professional editor who rewrites content in a clear, engaging style."""
messages = [ {"role": "system", "content": system_message}, {"role": "user", "content": "Rewrite: [content]"}]
Introduction to Claude Models

Managing output length with max_tokens

  • max_tokens sets a specific response length
  • ~4 characters per token
  • 150 tokens = 600 characters = 1 paragraph
# Controlling output length
response = client.messages.create(
    model="claude-sonnet-4-20250514",
      # Approximately 600 characters
    max_tokens=150,  
    messages=[{
        "role": "user", 
        "content": "Summarize this 
             quarterly report: [text]"
    }])
Introduction to Claude Models

Key takeaways

$$

  • 📌 Summaries: long key points
  • 📝 Rewrites: adjust tone
  • 🔎 Be explicit on format
  • 🔧 Tune max_tokens
  • ✅ Verify meaning
Introduction to Claude Models

Let's practice!

Introduction to Claude Models

Preparing Video For Download...