First of all, I know this question is kind of off-topic, but I have already tried to ask elsewhere but got no response.
Adding a UNK
token to the vocabulary is a conventional way to handle oov words in tasks of NLP. It is totally understandable to have it for encoding, but what's the point to have it for decoding? I mean you would never expect your decoder to generate a UNK
token during prediction, right?
Depending on how you preprocess your training data, you might need the UNK
during training. Even if you use BPE or other subword segmentation, OOV can appear in the training data, usually some weird UTF-8 stuff, fragments of alphabets, you are not interested in at all, etc.
For example, if you take WMT training data for English-German translation, do BPE and take the vocabulary, you vocabulary will contain thousands of Chinese characters that occur exactly once in the training data. Even if you keep them in the vocabulary, the model has no chance to learn anything about them, not even to copy them. It makes sense to represent them as UNK
s.
Of course, what you usually do at the inference time is that you prevent the model predict UNK
tokens, UNK
is always incorrect.