In teaching word2vec in the A2Z class, I noticed two things about the API that would be good to discuss.
Arguments
While it's nice to have the option of adding, subtracting, averaging, etc. an array of vectors, the added square bracket syntax is confusing. It would be nice to overload the math functions to also parse multiple arguments as an array. I know this is probably tricky given we also allow for an optional argument as the number of elements to return. Maybe we can just allow for the case of math between two words not requiring an array.
Without access to the numeric vectors themselves (see: #215), it's problematic to do certain operations. Take the following "analogy" example:
let difference = await word2vec.subtract('kitten', 'cat');
let result = await word2vec.add(difference[0].word, 'dog');
This could lead to strange results since we are not actually adding the difference vector to dog, rather we are adding a vector associated with the word closest to that difference vector to dog. If the math functions returned both the closest word as well as the raw vector itself, we could say:
let difference = await word2vec.subtract('kitten', 'cat');
let result = await word2vec.add(difference.vector, 'dog');
This would also make it possible to "interpolate" between two words by calculating the vector then moving along it more slowly. To make this possible we would need to:
Add a vector property with the raw numbers (converted presumably from their corresponding tensor) to the result of all math operations like add(), average(), etc.
Overload all of the math operations to accept either a word or a raw array of numbers.
Perhaps both of these suggestions add too much complexity / maintenance?
In teaching word2vec in the A2Z class, I noticed two things about the API that would be good to discuss.
Arguments
While it's nice to have the option of adding, subtracting, averaging, etc. an array of vectors, the added square bracket syntax is confusing. It would be nice to overload the math functions to also parse multiple arguments as an array. I know this is probably tricky given we also allow for an optional argument as the number of elements to return. Maybe we can just allow for the case of math between two words not requiring an array.
Direct vector math
Without access to the numeric vectors themselves (see: #215), it's problematic to do certain operations. Take the following "analogy" example:
This could lead to strange results since we are not actually adding the difference vector to
dog
, rather we are adding a vector associated with the word closest to that difference vector todog
. If the math functions returned both the closest word as well as the raw vector itself, we could say:This would also make it possible to "interpolate" between two words by calculating the vector then moving along it more slowly. To make this possible we would need to:
vector
property with the raw numbers (converted presumably from their corresponding tensor) to the result of all math operations likeadd()
,average()
, etc.Perhaps both of these suggestions add too much complexity / maintenance?