0
0
NLPml~20 mins

Domain-specific sentiment in NLP - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Domain-Specific Sentiment Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why is domain-specific sentiment analysis important?

Imagine you want to analyze customer reviews about medical devices. Why might a general sentiment model fail here?

ABecause general sentiment models always perform better on any domain without retraining.
BBecause domain-specific sentiment ignores the context of words and focuses only on word frequency.
CBecause words like 'positive' or 'negative' have different meanings in medical contexts compared to general language.
DBecause medical reviews are always neutral and don't need sentiment analysis.
Attempts:
2 left
💡 Hint

Think about how words can change meaning depending on the topic.

Predict Output
intermediate
2:00remaining
Output of domain-specific sentiment prediction code

What is the output of this Python code that predicts sentiment using a domain-specific dictionary?

NLP
domain_sentiment_dict = {'stable': 1, 'critical': -1, 'improved': 1, 'declined': -1}
text = 'The patient condition is stable but later declined'
sentiment_score = sum(domain_sentiment_dict.get(word, 0) for word in text.lower().split())
print(sentiment_score)
A2
B0
C-1
D1
Attempts:
2 left
💡 Hint

Check which words in the text match the dictionary and sum their scores.

Model Choice
advanced
2:00remaining
Choosing a model for domain-specific sentiment analysis

You want to build a sentiment model for financial news articles. Which model choice is best?

AUse a rule-based sentiment model designed for movie reviews.
BTrain a sentiment model from scratch using only financial news labeled data.
CUse a pre-trained general sentiment model without any fine-tuning.
DFine-tune a pre-trained language model on labeled financial news sentiment data.
Attempts:
2 left
💡 Hint

Consider leveraging existing knowledge and adapting it to your domain.

Metrics
advanced
2:00remaining
Evaluating domain-specific sentiment model performance

You trained a domain-specific sentiment classifier. Which metric best shows how well it distinguishes positive and negative sentiment?

AF1-score
BAccuracy
CMean Squared Error
DPerplexity
Attempts:
2 left
💡 Hint

Think about metrics that balance precision and recall for classification.

🔧 Debug
expert
2:00remaining
Debugging domain-specific sentiment model training code

What error does this code raise when training a sentiment model with domain-specific data?

NLP
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.linear_model import LogisticRegression
texts = ['good profit', 'bad loss', 'stable growth']
labels = [1, 0]
vectorizer = CountVectorizer()
X = vectorizer.fit_transform(texts)
model = LogisticRegression()
model.fit(X, labels)
AValueError: Found input variables with inconsistent numbers of samples
BTypeError: 'int' object is not iterable
CAttributeError: 'CountVectorizer' object has no attribute 'fit_transform'
DNo error, model trains successfully
Attempts:
2 left
💡 Hint

Check if the number of texts matches the number of labels.