Learn how to use LLMs to infer information from text — sentiment, emotions, topics, and more — all with simple prompts instead of training separate ML models.
lamp_review = """Needed a nice lamp for the bedroom and this one had
additional storage. The company had great customer support..."""
# Full sentence response
prompt = f"""
What is the sentiment of the following product review?
Review: ```{lamp_review}```
"""
# Concise response (better for post-processing)
prompt = f"""
What is the sentiment of the following product review?
Give your answer in a single word: positive or negative.
Review: ```{lamp_review}```
"""
print(get_completion(prompt)) # → positive
prompt = f"""
Identify a list of emotions the writer of the following review is expressing.
Include no more than 5 items.
Review: ```{lamp_review}```
"""
# → satisfied, grateful, impressed, happy, appreciative
Check for anger specifically (useful for customer support):
prompt = f"""
Is the writer of the following review expressing anger?
Answer yes or no.
Review: ```{lamp_review}```
"""
# → no
prompt = f"""
Identify the following from the review:
- Item purchased
- Brand/company that made it
Format your response as JSON with keys: item, brand.
Review: ```{lamp_review}```
"""
# → {"item": "lamp", "brand": "Lumina"}
Instead of calling the API 3-4 times, do it all at once:
prompt = f"""
From the review below, identify:
1. Sentiment (positive/negative)
2. Is the reviewer angry? (boolean)
3. Item purchased
4. Company that made it
Format as JSON with keys: sentiment, anger, item, brand.
Review: ```{lamp_review}```
"""
# → {"sentiment": "positive", "anger": false, "item": "lamp with additional storage", "brand": "Lumina"}
⚡ One API call = multiple insights — saves time and cost