How to know OOV of nlp models with subword tokenization

Abdelkareem_Elkhateb: <p>How to know OOV from a model For example if i have the sentence " Kareem love Rawda but she can’t fly how to koberskobl"</p>
<p>and pass this sentence to tokenizer it will give me the following tokens:<br>
[‘ka’, ‘#<span class="hashtag-raw">#ree</span>’, ‘#<span class="hashtag-raw">#m</span>’, ‘love’, ‘raw’, ‘#<span class="hashtag-raw">#da</span>’, ‘but’, ‘she’, ‘cannot’, ‘fly’, ‘how’, ‘to’, ‘do’, ‘kobe’, ‘#<span class="hashtag-raw">#rsk</span>’, ‘#<span class="hashtag-raw">#ob</span>’, ‘#<span class="hashtag-raw">#l</span>’]<br>
and do the following code</p>
<p>for word in input_text.split():<br>
if tokenizer.convert_tokens_to_ids([word]) == [tokenizer.unk_token_id]:<br>
oov_words.append(word)</p>
<p>Print the OOV words<br>
print(“Out-of-vocabulary words:”, oov_words)<br>
It will give me Out-of-vocabulary words: [‘Kareem’, ‘Rawda’, ‘koberskobl’]<br>
Is this the best way to do this ! i think i have some misunderstanding of the Tokenization process !<br>
what i am trying to do is how to know if the word have a high probability to be OOV !</p>

Abdelkareem_Elkhateb: <p><a class="mention" href="/u/vdw">@vdw</a>  I will be happy to know your answer this is it will help a lot for improve the current arabic models i asked a lot of people, but all them say this is not possible to do with subword tokneization or general tokneizations !<br>
can you give me any suggestion !<br>
one of the solution that i am thinking is that i made a another dictionary that i will save all the words that i want to train my model on and do a lemmtization process before train the model ! this is really tedious any solutions or guides will help me alot and i am sorry for tagging you, but it’s important question for me <img src="https://discuss.pytorch.org/images/emoji/apple/sweat_smile.png?v=12" title=":sweat_smile:" class="emoji" alt=":sweat_smile:" loading="lazy" width="20" height="20"></p>

vdw: <p>I don’t think you have a misunderstanding. Tokenization simply means to split a string in tokens. This can characters, but more commonly words and/or subwords. The problem with basic word tokenization is that (a) the number of unique tokens can be very large and (b) their frequency typically show a Zipf distribution – mainly, there is a long tail of many tokens (i.e., words) that occur very rarely or maybe just once. That’s never good for statistical models.</p>
<p>You are using subword-based tokenization. This tokenizer is trained on a dataset to split strings into words and if needed subwords based on their frequencies. Since “Kareem” was very rare in this training dataset, the tokenizer will split into more common subword. For example “ree” is in “tree”, “free”, “freedom”, “greed”, “greedy”, “breed”, etc. So the  tokenizer knows “ree” just not “Kareem” as a whole. I assume that the tokenizer consider all tokens that are not complete words as OOV word, which seem intuitive :).</p>
<p>While a character and word-based tokenizer is relatively easy to implement using a RegEx and rule-based approach, subword tokenizers are trained over data. This it also depends in the training data (and the parameters for the training) if a certain word will be a OOV word later. So if you use a pretrained tokenizer, it’s difficult to know if a word/token will be OOV, at least as far as I can tell.</p>
<p><strong>EDIT:</strong> I’m not sure what you mean by Arabic models, since your example sentence is in English. In case of a machine translation task, you would of course 2 tokenizers, one for English and one for Arabic.</p>