0
0
NLPml~20 mins

Hybrid approaches in NLP - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Hybrid NLP Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding Hybrid Models in NLP

Which of the following best describes a hybrid approach in Natural Language Processing (NLP)?

ACombining rule-based methods with machine learning models to improve text understanding.
BUsing only deep learning models without any handcrafted rules.
CApplying unsupervised learning exclusively for text classification.
DRelying solely on dictionary lookups for language translation.
Attempts:
2 left
💡 Hint

Think about mixing different techniques to get better results.

Model Choice
intermediate
2:00remaining
Choosing Models for a Hybrid Sentiment Analysis System

You want to build a sentiment analysis system that uses both a lexicon-based method and a machine learning classifier. Which combination below fits a hybrid approach?

AUse only a pre-trained transformer model without any lexicon.
BUse a sentiment dictionary to score words and a logistic regression model trained on labeled reviews.
CApply k-means clustering on unlabeled text data.
DUse a rule-based system that assigns sentiment based on fixed patterns only.
Attempts:
2 left
💡 Hint

Look for a mix of dictionary and machine learning.

Predict Output
advanced
3:00remaining
Output of Hybrid Text Classification Pipeline

What is the output of the following Python code that combines TF-IDF features with a rule-based keyword count for classification?

NLP
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.linear_model import LogisticRegression
import numpy as np

texts = ["I love sunny days", "I hate rain", "Sunny weather is great", "Rainy days are gloomy"]
labels = [1, 0, 1, 0]

# Rule-based feature: count of positive words
positive_words = {'love', 'sunny', 'great'}
rule_features = np.array([[sum(word in positive_words for word in text.lower().split())] for text in texts])

# TF-IDF features
vectorizer = TfidfVectorizer()
tfidf_features = vectorizer.fit_transform(texts).toarray()

# Combine features
X = np.hstack((tfidf_features, rule_features))

model = LogisticRegression().fit(X, labels)
predictions = model.predict(X)
print(predictions.tolist())
A[0, 0, 0, 0]
B[0, 1, 0, 1]
C[1, 0, 1, 0]
D[1, 1, 1, 1]
Attempts:
2 left
💡 Hint

Check how the rule-based feature and TF-IDF features help the logistic regression model.

Hyperparameter
advanced
2:00remaining
Tuning Hybrid Model Parameters

In a hybrid NLP model combining a rule-based sentiment score and a neural network, which hyperparameter adjustment is most likely to improve the balance between the two components?

AIncrease the number of epochs for training the neural network only.
BUse a smaller batch size without changing the model architecture.
CRemove the rule-based component to simplify the model.
DAdjust the weight given to the rule-based score in the final prediction layer.
Attempts:
2 left
💡 Hint

Think about how to control the influence of each part in the combined output.

🔧 Debug
expert
3:00remaining
Debugging a Hybrid NLP Pipeline Error

Consider this hybrid NLP pipeline code snippet that combines a rule-based feature with a machine learning model. It raises a ValueError: shapes (4,5) and (4,1) not aligned. What is the cause?

NLP
import numpy as np
from sklearn.linear_model import LogisticRegression

texts = ["happy day", "sad night", "joyful morning", "gloomy evening"]
labels = [1, 0, 1, 0]

# Rule-based feature: count of positive words
positive_words = {'happy', 'joyful'}
rule_features = np.array([[sum(word in positive_words for word in text.split())] for text in texts])

# Dummy TF-IDF features with wrong shape
tfidf_features = np.random.rand(4, 5)

# Incorrect feature combination
X = np.dot(tfidf_features, rule_features)

model = LogisticRegression().fit(X, labels)
AUsing np.dot to combine features with incompatible shapes causes the error.
BThe rule-based feature calculation is incorrect and returns empty arrays.
CLogisticRegression cannot be trained on combined features.
DLabels array length does not match feature rows.
Attempts:
2 left
💡 Hint

Check how features are combined and their shapes.