5 things to check when UNK tokens appear often
Do you keep seeing UNK in your analysis results? UNK is the unclassified state (tag=0) in which Bareun could not classify a morpheme as any part of speech. This document lists five things to check, in order, when UNK is frequent.
Symptoms
A morpheme's tag comes out as UNK, or a morpheme's out_of_vocab value is shown as OUT_OF_VOCAB (unregistered, automatically guessed).
It appears often in domain-specific text (medicine, law, games, new words).
Cause
For each morpheme, Bareun tells you where that word came from in the out_of_vocab value.
| Value | Meaning |
|---|---|
IN_WORD_EMBEDDING | Included in the trained word embeddings |
OUT_OF_VOCAB | Out-of-vocabulary word (OOV), automatically guessed |
IN_CUSTOM_DICT | Registered in the custom dictionary |
IN_BUILTIN_DICT | Included in the basic dictionary |
IN_URIMALSAEM | Urimalsaem (Open Korean Dictionary) |
IN_WIKI_DICT | Wikipedia dictionary |
IN_ON_DICT | Onterm dictionary (Korean terminology platform) |
The last three sources appear only in the spell checker
IN_URIMALSAEM, IN_WIKI_DICT, and IN_ON_DICT are dictionaries used by the spell checker (the distribution that includes the correction feature).
When you use only the morphological analyzer, these three values do not appear.
Frequent UNK means there are many OUT_OF_VOCAB morphemes, which in turn means the input has many words that are not in the training data or the built-in dictionaries.
Solution: 5 things to check
-
Check the
out_of_vocabvalue first. If it isOUT_OF_VOCAB, it is an out-of-vocabulary word. If it isIN_*, it is a normal word that came from a dictionary. If the word is normal but only the tag looks odd, see Results that differ from expectations. -
Register proper nouns and technical terms in the custom dictionary. This is the most effective method. If you add an entry with
UpdateCustomDictionary, the morpheme changes toIN_CUSTOM_DICT. -
Use
cp_set/cp_caret_setfor compound nouns. Put long words made of several nouns into the compound noun dictionary, and usecp_caret_set, which marks the split point with^, to make decomposition accurate. -
Check word spacing. If eojeol (space-delimited word unit) boundaries are broken, even perfectly good words become
UNK. Turn onauto_spacingto have it corrected. -
Check the input encoding and cleanup. Broken characters, control characters, and mixed-in foreign text increase
UNK. Also check thatencoding_type(UTF8/UTF16/UTF32) matches the input.
Checklist at a glance
- Is
out_of_vocabOUT_OF_VOCAB? - Did you register proper nouns and technical terms in the dictionary?
- Did you put compound nouns in
cp_set/cp_caret_set? - Did you check word spacing (
auto_spacing)? - Did you check the encoding and input cleanup?
Prevention and tips
- Building a domain dictionary in advance noticeably lowers the
UNKrate. You can keep several dictionaries and specify them incustom_dict_namesin priority order (the dictionary specified first takes priority). - Custom dictionaries detect file changes in real time and are updated with zero downtime. You can add words even during operation.
Frequently asked questions
Q. How are UNK and OUT_OF_VOCAB different?
UNK is the tag (tag=0) for a morpheme that was not classified as any part of speech, and OUT_OF_VOCAB is the mark (the out_of_vocab value) that the word's source is "unregistered, automatically guessed." Both often come from out-of-vocabulary words.
Q. What is the fastest way to reduce UNK?
Register frequently appearing proper nouns and technical terms in the custom dictionary. After registering, if you specify custom_dict_names in the analysis request, those words are recognized as IN_CUSTOM_DICT.
Q. Domain terms keep showing up as UNK. What should I do?
Domain-specific text such as medicine, law, and games has many out-of-vocabulary words that are not in the training data or built-in dictionaries, so UNK is frequent.
Register those terms in the custom dictionary (np_set, or cp_set/cp_caret_set for compound nouns) and specify them with
custom_dict_names. You can give several dictionaries in priority order.
Q. Do I need to restart the server after adding UNK words to the dictionary?
No. Custom dictionaries are managed with the CustomDictionaryService API, and Bareun detects file changes in the dictionary directory in real time and applies them immediately with zero downtime. If you add words during operation, they apply from the next request.