Complete the code to create a one-hot encoded vector for the word 'cat' using the vocabulary.
vocab = ['cat', 'dog', 'bird'] word = 'cat' one_hot = [1 if w == [1] else 0 for w in vocab]
We compare each word in the vocabulary to the string 'cat' to create the one-hot vector.
Complete the code to build a one-hot encoding dictionary for all words in the vocabulary.
vocab = ['apple', 'banana', 'cherry'] one_hot_dict = {word: [1 if w == [1] else 0 for w in vocab] for word in vocab}
We use the variable 'word' to create one-hot vectors for each word in the vocabulary.
Fix the error in the code to correctly create a one-hot vector for the word 'dog'.
vocab = ['cat', 'dog', 'fish'] word = 'dog' one_hot = [1 if w == [1] else 0 for w in vocab]
The comparison must be with the string 'dog' (in quotes) to match vocabulary words correctly.
Fill both blanks to create a one-hot encoding dictionary for the vocabulary.
vocab = ['red', 'green', 'blue'] one_hot_dict = {word: [1 if w == [1] else 0 for w in [2]] for word in vocab}
We compare each word 'w' to the current 'word' and iterate over the vocabulary list 'vocab'.
Fill all three blanks to create a one-hot encoding dictionary and print the vector for 'blue'.
vocab = ['red', 'green', 'blue'] one_hot_dict = { [1]: [1 if w == [2] else 0 for w in [3] ] for word in vocab } print(one_hot_dict['blue'])
The dictionary key is 'word', the comparison is with 'word', and the iteration is over 'vocab'.