Machines process numbers, not words. Why is it necessary to convert text into numbers before feeding it to a machine learning model?
Think about how computers store and process information internally.
Computers operate using numbers (binary digits). Text must be converted into numbers so machines can perform calculations and learn patterns.
What is the output of this Python code that converts words to their length?
words = ['cat', 'dog', 'elephant'] lengths = [len(word) for word in words] print(lengths)
len(word) returns the number of characters in each word.
The code creates a list of lengths of each word: 'cat' and 'dog' have 3 letters, 'elephant' has 8.
You want to build a model to detect positive or negative feelings in movie reviews. Which numerical text representation is best to capture word meanings and context?
Consider which method captures word meanings and relationships best.
Pretrained embeddings represent words as vectors capturing semantic similarity, improving sentiment detection over simple counts or random numbers.
After converting text to numbers and training a classifier, which metric best tells you how well the model correctly identifies positive reviews?
Think about the metric that measures correctness of positive predictions.
Precision measures how many predicted positives are truly positive, important when false positives are costly.
Given this code snippet converting text to numbers, what error will it raise?
text = 'hello world' word_to_index = {'hello': 1, 'world': 2} numbers = [word_to_index[word] for word in text.split() + ['!']] print(numbers)
Check if all words exist in the dictionary before accessing.
The list includes '!' which is not a key in word_to_index, causing a KeyError when accessed.