🎯 Lecture Goal

Learn how to use LLMs to summarize text — with length control, focus by attribute, information extraction, and batch summarization of multiple reviews.


📝 Key Concepts

1️⃣ Basic Summary with Length Control

review = """Got this panda plush toy for my daughter's birthday, who loves it 
and takes it everywhere. It's soft and cute but a bit small for the price. 
Arrived a day earlier than expected."""

prompt = f"""
Your task is to generate a short summary of a product review 
from an e-commerce website.

Summarize the review below, delimited by triple backticks, in at most 30 words.

Review: ```{review}```
"""
print(get_completion(prompt))

✅ Output: Soft and cute panda plush toy loved by daughter, bit small for price, arrived early.

💡 You can swap 30 words with 3 sentences or 280 characters to control length differently.


2️⃣ Summarize with a Specific Focus (by Attribute)

Focus on Shipping:

prompt = f"""...Summarize in at most 30 words, focusing on any aspects 
that mention shipping and delivery.

Review: ```{review}```
"""

✅ Output highlights: arrived a day earlier than expected


Focus on Price/Value:

prompt = f"""...Summarize in at most 30 words, focusing on aspects 
relevant to price and perceived value.

Review: ```{review}```
"""

✅ Output highlights: price may be too high for the size


3️⃣ Extract Instead of Summarize

When you want only the specific info (no extras):