Sub topic 1
Start with the question: goals and a label taxonomy
Prerequisites
This chapter assumes you can read basic Python (lists, dictionaries, functions) and recognise JSON. You should know roughly what a large language model (LLM) is and how an API call to one works. You should also know the terms precision, recall and average. Later chapters write code for each step. This chapter has little code, because the decisions made here shape everything after it.
Why analysis starts with a question
A pile of reviews does not tell you what to do with it. If you run sentiment scoring on 20,000 reviews, you get a number such as "62% positive". Nobody can act on that number. The product team asks which feature to fix. The support team asks which problem is growing. Finance asks whether a price change hurt. A single score answers none of these.
The usual failure is to pick a tool first (a sentiment model, a clustering library, an LLM prompt) and then look for something to say about the output. The fix is to reverse the order:
- Write down the decision the analysis supports.
- Turn the decision into questions the data can answer.
- Define the labels you need to answer those questions.
- Only then choose methods.
This chapter covers steps 1 to 3. The rest of the tutorial covers step 4.
From decisions to questions
A decision is something a person can do on Monday. A good analysis goal names the decision, the owner, and the comparison that would change their mind.
| Weak goal | Stronger goal |
|---|---|
| Understand customer sentiment | Decide whether the Q3 packaging change should be rolled back, by comparing the share of delivery complaints that mention damage before and after the change |
| Find what customers talk about | Give the support lead a ranked list of the five problems that generate the most repeat contacts, so she can choose which help-centre articles to write |
| Analyse our reviews | Tell the product manager which app features appear most often in 1- and 2-star reviews, so the next sprint can target them |
Notice what the stronger goals share. Each has an owner. Each names a time window or a comparison. Each implies the labels you need: "mentions damage", "problem category", "feature name".
Question types
Most feedback questions fall into a small number of types. Knowing the type tells you which method fits.
| Question type | Example | Typical output |
|---|---|---|
| Measure | How positive are reviews of version 4.2? | A rate or score with a sample size |
| Compare | Did sentiment about delivery change after we switched couriers? | A difference between two groups or periods |
| Discover | What are customers complaining about that we have not listed? | A set of candidate themes |
| Locate | Which feature is the complaint about? | A label tied to a part of the product |
| Explain | Why did one-star reviews spike in March? | Examples and themes tied to a cause |
"Measure", "compare" and "locate" need a fixed set of labels decided in advance. "Discover" does not, which is why it comes with its own method (clustering, covered in a later chapter). Most real projects start with discovery on a small sample, then freeze a taxonomy and switch to measurement.
What a label taxonomy is
A label taxonomy is the fixed list of categories, with definitions, that you assign to each piece of feedback. It is the contract between the analysis and the people who read it. Every later step depends on it: a prompt asks an LLM to choose from it, an evaluation checks agreement against it, and a dashboard groups by it.
A taxonomy usually has several independent fields, not one big list. Mixing them into one list is the most common design error.
- Sentiment: the overall attitude. For example
positive,negative,neutral,mixed. - Theme: what the feedback is about. For example
pricing,delivery,product_quality,support,usability,other. - Intent or type (optional): what the writer wants. For example
complaint,praise,question,feature_request,bug_report. - Severity or urgency (optional): how serious it is. For example
low,medium,high.
A single review can carry several labels at once. "Delivery was two weeks late but the support agent refunded me quickly" is mixed in sentiment, and its themes are delivery and support.
Single-label versus multi-label
Decide for each field whether a review gets one value or several.
- Sentiment is usually single-label. The review gets one overall value, and
mixedcovers the cases where it does not fit. - Theme is usually multi-label. Forcing one theme per review hides the second problem in every review that has two.
- Intent is often single-label, but a review can be a complaint and a feature request. Allow multiple values if your team will filter on them.
Multi-label fields need a different counting rule. If a review has two themes, then counting "reviews per theme" gives totals that add up to more than the number of reviews. State this under every chart that uses it, or readers will think the data is wrong.
Rules for a good taxonomy
A taxonomy works when two careful people, given the same review, choose the same label most of the time. These rules make that more likely.
- Mutually exclusive within a field, where single-label. If
product_qualityandusabilityoverlap heavily, annotators will split on them at random. Either merge them or write a rule that separates them. - Collectively exhaustive. Include
other, so a review never has to be forced into a wrong label. Track how bigothergets. Above roughly 10 to 15 percent, the taxonomy is missing a category. - Defined by what it contains, with examples. A label name is not a definition. Write one sentence of definition, one example that belongs, and one near miss that does not.
- Tied to a decision. If no one would act differently based on a label, remove it. A taxonomy with 40 labels where 30 have fewer than 20 reviews is hard to maintain and hard to evaluate.
- Stable names. Use lowercase identifiers with underscores, such as
product_quality. They go into prompts, JSON and dashboards, and renaming them later breaks comparisons over time.
Write the taxonomy as data
Keep the taxonomy in one place that code can read. The same file feeds the prompt, the validator and the reports, so they cannot drift apart.
TAXONOMY = {
"sentiment": {
"multi": False,
"labels": {
"positive": "Overall favourable; no significant complaint.",
"negative": "Overall unfavourable; no significant praise.",
"neutral": "States facts or asks a question without a clear attitude.",
"mixed": "Contains both clear praise and a clear complaint.",
},
},
"themes": {
"multi": True,
"labels": {
"pricing": "Cost, value for money, fees, discounts.",
"delivery": "Shipping speed, packaging, courier behaviour.",
"product_quality": "Whether the item works, lasts, or matches its description.",
"support": "Interactions with customer service, refunds, returns handling.",
"usability": "How easy the product or app is to use.",
"other": "Anything that fits none of the above.",
},
},
}
def allowed_labels(field):
return set(TAXONOMY[field]["labels"])
def describe(field):
lines = [f"- {name}: {text}" for name, text in TAXONOMY[field]["labels"].items()]
return "\n".join(lines)
print(allowed_labels("sentiment"))
print(describe("themes"))Running this prints the four sentiment labels as a set, then the six theme definitions as a bullet list. The describe function produces text you can paste into an LLM prompt, so the model sees the same definitions that human annotators saw.
Granularity: how fine should labels be?
Fine labels carry more information but cost more to apply and to check. Coarse labels are easy to apply and give vague answers. A two-level hierarchy usually balances the two.
delivery
delivery.late
delivery.damaged
delivery.lost
product_quality
product_quality.defect
product_quality.not_as_describedStore the coarse level for reporting at first, and the fine level for drill-down. Assign fine labels only when a coarse theme is large enough to justify the effort. This also lets you start simple and split a category later without relabelling everything: delivery becomes delivery.*, and old data still rolls up correctly.
Two limits to keep in mind:
- Each label needs enough examples to evaluate. A label with five reviews in your human-labelled sample gives a precision figure that is mostly noise.
- LLM accuracy tends to fall as the number of labels in a prompt grows, and definitions that overlap make it worse. Test any taxonomy with more than about 15 labels in one prompt before you rely on it.
Choosing a method for each question
With questions and labels written down, method choice becomes straightforward. The following table is a first pass. Later chapters give the detail.
| You need | Labels known in advance? | Reasonable first method |
|---|---|---|
| Overall attitude per review | Yes (fixed sentiment set) | Pretrained classifier or LLM with a fixed label set |
| Themes per review | Yes | LLM structured extraction, validated against the taxonomy |
| Themes you have not thought of | No | TF-IDF or embedding clustering, then a person names the clusters |
| Attitude toward each feature | Yes (feature list) | Aspect-based sentiment, using extraction |
| A readable overview of many reviews | Not applicable | Summarisation with links back to source reviews |
None of these is fixed. A common workflow is: cluster a sample to discover themes, write the taxonomy from what you find, then label the full set with an LLM.
A planning worksheet
Before you write any code, fill in a short spec. It takes about fifteen minutes and catches most scope problems.
- Decision: What will someone do differently depending on the result?
- Owner: Who makes that decision, and what format do they read?
- Questions: Which of measure, compare, discover, locate and explain apply?
- Population: Which reviews, from which sources and dates? (The next chapter covers how sources skew results.)
- Fields and labels: For each field, single or multi-label, with a definition and example per label.
- Success check: How will you know the labels are good enough? For example, "agreement with two human annotators of at least 0.7 Cohen's kappa on a 200-review sample".
- Stopping rule: When is the analysis good enough to ship?
The success check matters because it makes the quality bar explicit before you see results. Without one, there is a temptation to accept whatever the model produced.
Common errors
- Starting with "sentiment" because it is easy. Sentiment is useful as one field. On its own it says that people are unhappy, not why.
- One field for everything. A list such as
positive,delivery_problem,pricing_complaintmixes attitude and topic. A review cannot be sorted cleanly, and you cannot ask "how do people feel about pricing?". - No
otherlabel. Annotators and models are forced to guess, and the guesses hide the gaps in your taxonomy. - Undefined labels. "Quality" can mean durability, appearance or accuracy of the product description. Different people read it differently, and an LLM picks whichever reading is likeliest.
- Changing labels silently. If you rename or split labels midway, trends before and after are no longer comparable. Version the taxonomy (for example
taxonomy_v2) and record which version labelled each review. - Counting multi-label data as single-label. Percentages that sum above 100 confuse readers. Report the share of reviews that mention each theme, and say so.
How the pieces fit together
The taxonomy sits at the centre. Goals determine it, and every later stage reads from it.
The loop from evaluation back to the taxonomy is intentional. When annotators disagree on a label, the usual cause is a weak definition, not careless people. Revise the definition, relabel the sample, and measure again.
Exercises
Exercise
A team's goal is "understand what customers think of our app". Rewrite it as a stronger goal, name the question type, and list at least two fields you would put in the taxonomy.
Show answer
One acceptable answer: "Tell the mobile product manager which app screens draw the most negative reviews in the last 90 days compared with the previous 90, so the next sprint can fix the worst two." The question type is compare (with a locate element). Fields: sentiment (single-label: positive, negative, neutral, mixed) and screen or feature (multi-label, with an other value). Any goal that names an owner, a decision and a comparison, and fields that separate attitude from topic, is acceptable.
Exercise
A colleague proposes a single label list: positive, negative, delivery, pricing, support, other. Give two problems with it and a fix.
Show answer
First, it mixes attitude (positive, negative) with topic (delivery, pricing, support), so a review about late delivery must be either negative or delivery, not both, and you cannot measure sentiment about pricing. Second, it is unclear whether a review gets one label or several, so counts are ambiguous. Fix: split it into a single-label sentiment field and a multi-label theme field, each with definitions and an other value in themes.
Exercise
In a dashboard, the theme percentages for 1,000 reviews add up to 135%. Is this a bug? What should the chart say?
Show answer
Not necessarily. Theme is a multi-label field, so one review can count toward several themes. The chart should state that each percentage is the share of the 1,000 reviews that mention the theme and that a review can mention more than one. If the field was meant to be single-label, then it is a bug in the labelling or counting.