v9.1.1
Menu

Binary Vectorizer

easyFREEText RepresentationNLP 1: Foundations

Given a vocabulary list and a text, create a binary vector where each position is 1 if the corresponding vocabulary word appears in the text, and 0 otherwise.

Input format:

  • Line 1: Comma-separated vocabulary words (already sorted)
  • Line 2: The text to vectorize

All comparisons are case-insensitive.

Output: A list of 0s and 1s.

Example

Input
cat,dog,fish,the
the cat sat
Output
[1, 0, 0, 1]
Reasoning

Step 1: Parse vocabulary ["cat", "dog", "fish", "the"]

Step 2: Check each vocab word in text "the cat sat" (lowered) contains: cat=yes, dog=no, fish=no, the=yes

Step 3: Build vector [1, 0, 0, 1]

Constraints

  • Vocabulary is provided comma-separated
  • Case-insensitive matching
  • Output: Python list of 0s and 1s

Learn this in

More from NLP 1: Foundations

solution.py

Test results

Sign in to run your code against the test cases.