Loading...
Given a vocabulary and a sequence of words, encode each word as a one-hot vector.
Input format:
Each word becomes a vector of length |vocab| with 1 at the word's index and 0 elsewhere. If a word is not in the vocabulary, use all zeros.
Output: One vector per line as a list.
cat,dog,fish dog cat fish
[0, 1, 0] [1, 0, 0] [0, 0, 1]
Step 1: Build vocabulary index cat=0, dog=1, fish=2
Step 2: Encode each word "dog" → index 1 → [0, 1, 0] "cat" → index 0 → [1, 0, 0] "fish" → index 2 → [0, 0, 1]