Loading...
Given a simple embedding table (word-to-vector mapping) and a list of words, look up each word's embedding vector and return the average embedding.
Input format:
If a word is not in the table, skip it. Round each dimension of the result to 4 decimal places.
3 cat 1.0,0.0 dog 0.0,1.0 fish 0.5,0.5 cat dog
[0.5, 0.5]
Step 1: Build embedding table cat → [1.0, 0.0], dog → [0.0, 1.0], fish → [0.5, 0.5]
Step 2: Look up words cat → [1.0, 0.0], dog → [0.0, 1.0]
Step 3: Average [(1.0+0.0)/2, (0.0+1.0)/2] = [0.5, 0.5]