Create a bag-of-words count vector for a token sequence and an ordered vocabulary. Output position i stores the number of times vocab[i] occurs in tokens. Ignore tokens outside the vocabulary and return a one-dimensional integer NumPy array.
Input: tokens = ["i", "love", "ml", "love"], vocab = ["i", "love", "hate", "ml"]
Output: [1, 2, 0, 1]
Explanation: The output follows vocabulary order, and "love" occurs twice.
Input: tokens = ["hello", "world"], vocab = ["hello", "ml"]
Output: [1, 0]
Input: tokens = [], vocab = ["hello", "world"]
Output: [0, 0]
Build {word: index for index, word in enumerate(vocab)}.
Increment the mapped position only when a token exists in the index dictionary.
Sign in to take notes on this problem
Accepts: array
Accepts: array
Create a bag-of-words count vector for a token sequence and an ordered vocabulary. Output position i stores the number of times vocab[i] occurs in tokens. Ignore tokens outside the vocabulary and return a one-dimensional integer NumPy array.
Input: tokens = ["i", "love", "ml", "love"], vocab = ["i", "love", "hate", "ml"]
Output: [1, 2, 0, 1]
Explanation: The output follows vocabulary order, and "love" occurs twice.
Input: tokens = ["hello", "world"], vocab = ["hello", "ml"]
Output: [1, 0]
Input: tokens = [], vocab = ["hello", "world"]
Output: [0, 0]
Build {word: index for index, word in enumerate(vocab)}.
Increment the mapped position only when a token exists in the index dictionary.
Sign in to take notes on this problem
Accepts: array
Accepts: array