Sub topic 11
When a Model Trained on Reviews Meets Social Posts
This chapter assumes that you understand train/test splits, TF-IDF, logistic regression, and precision, recall, and F1. You will learn why a model can perform well on product reviews but fail on social media posts.
What domain shift means
Domain shift occurs when the data used for training differs from the data used in production. A model trained on product reviews may expect complete sentences, standard spelling, and a clear opinion. Social posts often contain abbreviations, hashtags, emojis, slang, mentions, and sarcasm.
The task may look unchanged: predict positive, negative, or neutral sentiment. However, the relationship between words and labels can change.
For example, a review might say:
> The battery lasted only two hours, so I returned the phone.
A social post might say:
> Two hours of battery. Amazing. 🙃
The second post uses irony. The word “amazing” is usually positive, but the complete message is negative.
Measuring performance across domains
Do not estimate social-media performance from a review test set. Create separate evaluation sets for each domain:
- A source-domain set contains data similar to the training examples.
- A target-domain set represents the data the model will handle in production.
- Both sets should have reliable labels and should remain separate from training data.
The following example trains on reviews and evaluates on reviews and social posts.
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.linear_model import LogisticRegression
from sklearn.pipeline import make_pipeline
from sklearn.metrics import classification_report
review_train = [
"The camera takes sharp photos",
"The screen is bright and clear",
"The product stopped working after one day",
"The delivery was late and disappointing",
]
review_labels = ["positive", "positive", "negative", "negative"]
review_test = [
"This phone takes excellent photos",
"The product broke immediately",
]
review_test_labels = ["positive", "negative"]
social_test = [
"This camera is 🔥",
"Love waiting three weeks for delivery...",
]
social_test_labels = ["positive", "negative"]
model = make_pipeline(
TfidfVectorizer(ngram_range=(1, 2), lowercase=True),
LogisticRegression(max_iter=1000),
)
model.fit(review_train, review_labels)
for name, texts, labels in [
("reviews", review_test, review_test_labels),
("social posts", social_test, social_test_labels),
]:
predictions = model.predict(texts)
print(f"\n{name}")
print(classification_report(labels, predictions, zero_division=0))A performance gap between the two reports is evidence of domain shift. With only two examples per set, the numbers are not reliable estimates. A real evaluation needs enough examples to cover different authors, topics, time periods, and sentiment expressions.
Why the errors happen
A TF-IDF model represents text mainly through word and phrase frequencies. It does not inherently understand that:
- “🔥” can express strong approval.
- “lol great service” may be sarcastic.
- “not bad” is usually mildly positive.
- “sick” can mean impressive rather than ill.
- A hashtag may combine several words, such as
#worstupdateever.
Normalization can reduce some differences. For example, replacing URLs and mentions prevents the model from memorizing individual accounts or links. However, aggressive cleaning can remove useful signals such as emojis, repeated punctuation, or expressive capitalization.
Choosing a response
If the target-domain gap is small, continued monitoring may be enough. If the gap is large, consider these options:
| Option | Best use | Main trade-off |
|---|---|---|
| Add representative training examples | The target domain is stable | Requires labeled data |
| Use a pretrained social-text model | Slang and short posts matter | Model choice and licensing need review |
| Fine-tune on target data | You need higher domain-specific accuracy | Requires compute and careful validation |
| Use separate models | Domains have very different language | More maintenance and monitoring |
Fine-tuning is worthwhile only when you have enough high-quality target-domain labels and a clear improvement requirement. Before changing the model, inspect mistakes. The problem may instead be inconsistent labels, an unsuitable neutral category, or preprocessing that removes important social-text features.
Exercise
A review model scores 92% F1 on reviews and 68% F1 on social posts. What should you check before fine-tuning?
Show answer
Check that the label definitions match, inspect errors for slang, emojis, and sarcasm, verify that preprocessing preserves useful signals, and confirm that the social-post test set represents production traffic.