2
$\begingroup$

in machine learning, using One-Hot encoded data like words for RNNs (especially when we have a large dictionary like 10M or larger?) causes the dot product with the weight matrix slow.

THE QUESTION IS: Is this true? and if yes, Is one-hot encoding still used even though?

and, Does word embedding algorithms use one-hot encoding to represent data in training?

$\endgroup$

1 Answer 1

6
$\begingroup$

No one actually computes the dot product explicitly, since with a one-hot encoding you just need to read off the corresponding row/column of the matrix you're multiplying with (which takes constant time and is very fast). Otherwise it's prohibitively expensive and extremely slow.

If your vocabulary size is very large (i.e. millions), then usually people use word-embeddings like word2vec, Glove, etc as inputs for RNNs and other models. However, to train these embeddings, you do one-hot encoding for your words. In word2vec, you randomly sample word/context pairs, and you never actually multiply the one-hot encoding as explained above. You hash your word vectors, so after selecting a pair of words, you look up their vectors, and then do a gradient descent step. So the only dot products you end up computing are with respect to the in/out embeddings of your words.

$\endgroup$
1
  • 1
    $\begingroup$ thanks..actually my question was about this idea of just reading the corresponding coulmn of the weight matrix.....i just discovered it by myslef and found that its much much faster...so does this method have a name? $\endgroup$
    – Mark Naeem
    Commented Feb 15, 2018 at 10:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.