Getting value of [UNK] labels
# ❓ Questions & Help

<!-- The GitHub issue tracker is primarly intended for bugs, feature requests,
     new models and benchmarks, and migration questions. For all other questions,
     we direct you to Stack Overflow (SO) where a whole community of PyTorch and
     Tensorflow enthusiast can help you out. Make sure to tag your question with the
     right deep learning framework as well as the huggingface-transformers tag: 
     https://stackoverflow.com/questions/tagged/huggingface-transformers 
     
     If your question wasn't answered after a period of time on Stack Overflow, you
     can always open a question on GitHub. You should then link to the SO question 
     that you posted.
     -->

I have created a NER model based ob Bert with this library, but I have a problem when  I run my model due to `[UNK]`. Sometimos there are entities that aren't on my vocab so they are marked as unkowns so I cant know what they are. 

I know I can't revert `[UNK]` label, so would like to be able to define the words that would be unknown before the processing of the sentence.          

## Details
<!-- Description of your issue -->

<!-- You should first ask your question on SO, and only if
     you didn't get an answer ask it here on GitHub. -->
**A link to original question on Stack Overflow**:  [https://stackoverflow.com/questions/60192523/get-the-value-of-unk-in-bert](url)
Did you try using the `add_tokens` method on the tokenizer alongside the `resize_token_embeddings` on the model, to add your tokens to the vocabulary? The won't be marked as `[UNK]` this way, but will instead receive brand new embeddings (which need to be trained).<|||||>This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
<|||||>@LysandreJik  Hello, I have the same problem。
I want to implement [pointer-generator](https://arxiv.org/abs/1704.04368) by BertTokenizer. Pointer-generator can generate OOV tokens in the inputs by dynamically extending vocab. And there is no way to add all the tokens directly, especially in the test set.
Do you have any good solutions?<|||||>Have you tried using the `add_tokens` method on the tokenizer and the `resize_token_embeddings` method on your model?<|||||>I tried the dumbest solution:
```
bert_tokens = tokenizer.tokenize(query)
tokens = []
pre_text = ""
for i in range(len(bert_tokens)):
    bert_token = bert_tokens[i].replace("##", "")
    if i+1 < len(bert_tokens):
        post_token = bert_tokens[i+1].replace("##", "")
    else:
        post_token = ""
    if bert_token == '[UNK]':
        token = str(
            re.match(f"{pre_text}(.*){post_token}(.*)",
                     query).group(1))
        tokens.append(token)
        pre_text += token
    else:
        tokens.append(bert_token)
        pre_text += bert_token
return tokens
```