Sub topic 1
Start with the Question: Goals and a Label Taxonomy
Prerequisites
Assume you know basic Python, JSON, lists, dictionaries, functions, and averages. You should also understand that a large language model (LLM) generates text from a prompt and can return structured data, but its output still needs checking.
Start with the question: goals and a label taxonomy
Begin with a decision, not a model. For example, “Which delivery problems should the operations team fix first?” is more useful than “What is the sentiment?”
A label taxonomy is a defined set of categories for analysis. It keeps labels consistent across reviews and time. A small taxonomy is usually easier to validate than one with dozens of overlapping labels.
| Analysis goal | Useful labels or measure |
|---|---|
| Find unhappy customers | positive, negative, neutral, mixed |
| Find causes of complaints | delivery, pricing, support, usability |
| Prioritise product work | theme frequency combined with negative sentiment |
Define rules for unclear cases. For example, use mixed when one review contains both strong praise and criticism. Store the original review, assigned labels, evidence quotes, and model version.
Where feedback comes from and how it is skewed
Feedback sources represent different customers. App-store reviews may overrepresent extreme experiences. Support tickets overrepresent problems. Survey answers may overrepresent people willing to respond. A single customer may also submit the same complaint through several channels.
Record the source, date, product version, region, and customer segment when available. Report results by source instead of silently combining everything. Otherwise, a rise in support tickets might look like a product-wide sentiment change when it actually reflects a change in support volume.
Preparing review text: cleaning, deduplication and PII redaction
Clean text before analysis, but preserve a raw, access-controlled copy for audit. Redact personally identifiable information (PII), such as email addresses and phone numbers. Deduplicate after cleaning so repeated messages do not inflate counts.
import re
EMAIL = re.compile(r"[\w.+-]+@[\w-]+\.[\w.-]+")
PHONE = re.compile(r"\+?\d[\d\s().-]{7,}\d")
def clean_review(text):
text = EMAIL.sub("[EMAIL]", text)
text = PHONE.sub("[PHONE]", text)
return re.sub(r"\s+", " ", text).strip()
def deduplicate(reviews):
seen, unique = set(), []
for review in reviews:
key = clean_review(review).lower()
if key not in seen:
seen.add(key)
unique.append(review)
return uniqueMeasuring sentiment: lexicons, classifiers and LLMs
A lexicon assigns scores from word lists. It is fast and explainable but misses context and sarcasm. A classifier learns patterns from labelled examples and can fit your domain, but performance depends on label quality and drift. An LLM handles nuanced language and can combine sentiment with themes, but it costs more and may produce inconsistent labels.
Use a fixed taxonomy, validate every response, and compare a sample with human labels. Track precision, recall, and agreement rather than trusting a single overall score.
Exercise
Why should support tickets and public reviews usually be analysed separately?
Show answer
They have different sampling biases, so combining them can hide which customer group produced a change.