anthropics / anthropics/claude-cookbooks

[PROPOSAL] Cookbook: Aspect-Based Sentiment Analysis with Claude API

Aperta
#697 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Jupyter Notebook
Stelle
52.7k
Fork
6.3k
Merge medio
25m
PR unite (30g)
6

Descrizione

Preflight Checklist

(1) I have searched existing cookbooks, and this topic isn't already covered
(2) This proposal focuses on the Claude API/SDK capabilities (not external frameworks)
(3) I am prepared to implement this cookbook

Problem
Developers building review analysis systems, customer feedback tools, or
Social media monitors need more than basic positive/negative sentiment.
They need aspect-level insights.
For example, a review like

"The camera takes stunning photos, but the battery dies way too fast. The price is reasonable."

Contains three distinct signals:

camera → positive
battery life → negative
price → neutral

Basic sentiment analysis collapses this into a single ambiguous label.
There is currently no cookbook in this repo demonstrating aspect-based
sentiment analysis (ABSA) with Claude.

Proposed Cookbook
A Jupyter notebook (capabilities/aspect_based_sentiment_analysis/guide.ipynb)
demonstrating ABSA using Claude's tool for structured output.

What it covers:
Defining a tool schema that enforces structured JSON output (aspect, sentiment, confidence, evidence)
Extracting explicit and implicit aspects from review text
Batch processing multiple reviews across domains (smartphones, restaurants, apps, hotels)
Filtering by confidence score for production-ready pipelines
Visualising sentiment distributions with matplotlib

What makes it different from the existing classification cookbook:
The classification cookbook assigns a single category to a whole document.
This cookbook extracts multiple structured entities per document, each
With its own sentiment label, a fundamentally different pattern using a tool.
Target Audience
Developers building:

Product review dashboards (e-commerce, app stores)
Customer feedback analysis systems
Social media brand monitoring tools
Healthcare patient experience platforms

Implementation Plan
I have a working implementation ready:

guide.ipynb: full notebook with tool definition, batch analysis, DataFrame output, visualisation, and a try-it-yourself cell
README.md folder, readme with usage example and model recommendations
Tested with Claude-Haiku-4.5 (fast, cost-efficient for batch use)
Follows repo conventions: non-dated model alias, %%capture for pip installs, markdown/code cell structure

Happy to open a PR immediately upon maintainer approval.

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.