0
0
NLPml~10 mins

Domain-specific sentiment in NLP - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to load the domain-specific sentiment dataset.

NLP
import pandas as pd
data = pd.read_csv('[1]')
Drag options to blanks, or click blank then click option'
Ageneral_sentiment.csv
Bdomain_sentiment.csv
Crandom_data.csv
Duser_reviews.csv
Attempts:
3 left
💡 Hint
Common Mistakes
Loading a general sentiment dataset instead of domain-specific.
Using a file name that does not exist.
2fill in blank
medium

Complete the code to split the dataset into features and labels.

NLP
X = data['[1]']
y = data['sentiment']
Drag options to blanks, or click blank then click option'
Atext
Blabel
Cscore
Dreview
Attempts:
3 left
💡 Hint
Common Mistakes
Using the label column as features.
Choosing a column unrelated to text.
3fill in blank
hard

Fix the error in the code to vectorize the text data using TF-IDF.

NLP
from sklearn.feature_extraction.text import TfidfVectorizer
vectorizer = TfidfVectorizer()
X_vectorized = vectorizer.[1](X)
Drag options to blanks, or click blank then click option'
Afit
Btransform
Cfit_transform
Dvectorize
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'transform' without fitting first causes errors.
Using 'fit' alone returns the vectorizer, not transformed data.
4fill in blank
hard

Fill both blanks to train a logistic regression model and predict sentiments.

NLP
from sklearn.linear_model import LogisticRegression
model = LogisticRegression()
model.[1](X_vectorized, y)
predictions = model.[2](X_vectorized)
Drag options to blanks, or click blank then click option'
Afit
Bpredict
Ctransform
Dscore
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'score' instead of 'predict' to get predictions.
Trying to 'transform' data with the model.
5fill in blank
hard

Fill all three blanks to compute accuracy, precision, and recall for the model.

NLP
from sklearn.metrics import [1], [2], [3]
accuracy = accuracy_score(y, predictions)
precision = precision_score(y, predictions, average='macro')
recall = recall_score(y, predictions, average='macro')
Drag options to blanks, or click blank then click option'
Aaccuracy_score
Bprecision_score
Crecall_score
Df1_score
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'f1_score' instead of one of the required metrics.
Forgetting to import all three metrics.