4
$\begingroup$

I'm currently studying NLP and was practicing one-hot encoding for sentences at the word level.

My question is, if we have multiple examples of the same word in a sentence, does one-hot encoding normally assign separate "slots" for each instance of the same word?

For example, if we have the sentence "The cat sat on the mat." we can observe that the word "the" is used twice. Is each "the" assigned a separate entry, such that the encoding would look like:

1  0  0  0  0  0
0  1  0  0  0  0
0  0  1  0  0  0
0  0  0  1  0  0
0  0  0  0  1  0
0  0  0  0  0  1
$\endgroup$
2
  • 4
    $\begingroup$ Note that assigning different encodings to different instances of the same word would prevent the model from learning anything useful! $\endgroup$
    – tddevlin
    Commented Jul 15, 2019 at 6:52
  • $\begingroup$ @tddevlin That's a very good point, I hadn't thought about that. Thank you! $\endgroup$
    – Sean
    Commented Jul 15, 2019 at 7:51

1 Answer 1

5
$\begingroup$

If you consider the capitalization of the first

The

It might look like your example.

But if not. It would look like:

1  0  0  0  0  0
0  1  0  0  0  0
0  0  1  0  0  0
0  0  0  1  0  0
1  0  0  0  0  0
0  0  0  0  0  1

One hot encoding assigns a unique code for each unique word.

$\endgroup$

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.