Loading...
Build a Bag-of-Words (BoW) representation for a corpus of documents.
Algorithm:
Input format:
Output:
3 the cat sat the dog sat the cat and the dog
['and', 'cat', 'dog', 'sat', 'the'] [[0, 1, 0, 1, 1], [0, 0, 1, 1, 1], [1, 1, 1, 0, 2]]
Step 1: Build vocabulary All unique words: {"the", "cat", "sat", "dog", "and"} Sorted: ["and", "cat", "dog", "sat", "the"]
Step 2: Count words per document