# Unable to Exclude OOV Tokens

**URL:** <https://community.deeplearning.ai/t/unable-to-exclude-oov-tokens/679010>\
**Category:** Natural Language Processing in TensorFlow\
**Tags:** week-module-1\
**Created:** [August 17, 2024, 5:58am UTC](https://community.deeplearning.ai/t/unable-to-exclude-oov-tokens/679010 "2024-08-17T05:58:02Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tiger\_G](https://avatars.discourse-cdn.com/v4/letter/t/b782af/32.png) [@Tiger\_G](https://community.deeplearning.ai/u/Tiger_G)\
**Post date:** [August 17, 2024, 5:58am UTC](https://community.deeplearning.ai/t/unable-to-exclude-oov-tokens/679010/1 "2024-08-17T05:58:02Z")

</div>

When creating a post, please add:

- Link to the classroom item you are referring to:  
[tensorflow-1-public/C3/W1/assignment/C3W1\_Assignment.ipynb at main · https-deeplearning-ai/tensorflow-1-public (github.com)](https://github.com/https-deeplearning-ai/tensorflow-1-public/blob/main/C3/W1/assignment/C3W1_Assignment.ipynb)

For _Exercise 4: fit\_label\_encoder_, my function is making all my OOV Tokens **None**. To exclude the OOV tokens from my vocabulary, I am setting the oov\_token parameter to _None_ in my tf.keras.layers.StringLookup function. However, I’m getting that the first element of my Vocabulary of labels is **None**. How can I fix this?

 ![image](https://global.discourse-cdn.com/dlai/original/3X/2/d/2d43b12464615be540df563a385b3a278f6ba6c2.png)

---

<div class="post-metadata">

**Author:** ![lukmanaj](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/lukmanaj/32/161609_2.png) [@lukmanaj](https://community.deeplearning.ai/u/lukmanaj)\
**Post date:** [August 17, 2024, 7:08am UTC](https://community.deeplearning.ai/t/unable-to-exclude-oov-tokens/679010/2 "2024-08-17T07:08:54Z")

</div>

As a hint, these are the arguments according to the Tensorflow documentation:

```auto
tf.keras.layers.StringLookup(
    max_tokens=None,
    num_oov_indices=1,
    mask_token=None,
    oov_token='[UNK]',
    vocabulary=None,
    idf_weights=None,
    invert=False,
    output_mode='int',
    pad_to_max_tokens=False,
    sparse=False,
    encoding='utf-8',
    name=None,
    **kwargs
)

```

In order to exclude OOV tokens, your argument of interest should be `num_oov_indices`. Hope this helps.

---

<div class="post-metadata">

**Author:** ![Tiger\_G](https://avatars.discourse-cdn.com/v4/letter/t/b782af/32.png) [@Tiger\_G](https://community.deeplearning.ai/u/Tiger_G)\
**Post date:** [August 17, 2024, 9:19pm UTC](https://community.deeplearning.ai/t/unable-to-exclude-oov-tokens/679010/3 "2024-08-17T21:19:00Z")

</div>

Oh, I see. Thanks!

---

<div class="post-metadata">

**Author:** ![Abdulwaliyi](https://avatars.discourse-cdn.com/v4/letter/a/d9b06d/32.png) [@Abdulwaliyi](https://community.deeplearning.ai/u/Abdulwaliyi)\
**Post date:** [September 29, 2024, 2:24pm UTC](https://community.deeplearning.ai/t/unable-to-exclude-oov-tokens/679010/4 "2024-09-29T14:24:51Z")

</div>

i am still getting the same error by setting the num\_oov\_indices to 1

---

<div class="post-metadata">

**Author:** ![Abdulwaliyi](https://avatars.discourse-cdn.com/v4/letter/a/d9b06d/32.png) [@Abdulwaliyi](https://community.deeplearning.ai/u/Abdulwaliyi)\
**Post date:** [September 29, 2024, 2:27pm UTC](https://community.deeplearning.ai/t/unable-to-exclude-oov-tokens/679010/5 "2024-09-29T14:27:18Z")

</div>

thanks i was able to get it by setting it to the right valule

---

<div class="post-metadata">

**Author:** ![lukmanaj](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/lukmanaj/32/161609_2.png) [@lukmanaj](https://community.deeplearning.ai/u/lukmanaj)\
**Post date:** [September 29, 2024, 4:01pm UTC](https://community.deeplearning.ai/t/unable-to-exclude-oov-tokens/679010/6 "2024-09-29T16:01:00Z")

</div>

Props to you for finding the right answer yourself.

---

<div class="post-metadata">

**Author:** ![2736739572](https://avatars.discourse-cdn.com/v4/letter/2/b77776/32.png) [@2736739572](https://community.deeplearning.ai/u/2736739572)\
**Post date:** [October 17, 2024, 12:58am UTC](https://community.deeplearning.ai/t/unable-to-exclude-oov-tokens/679010/7 "2024-10-17T00:58:29Z")

</div>

I still can’t rule it out. Can you tell me how you did it?

---

<div class="post-metadata">

**Author:** ![vaijj](https://avatars.discourse-cdn.com/v4/letter/v/b3f665/32.png) [@vaijj](https://community.deeplearning.ai/u/vaijj)\
**Post date:** [October 19, 2024, 7:32pm UTC](https://community.deeplearning.ai/t/unable-to-exclude-oov-tokens/679010/8 "2024-10-19T19:32:00Z")

</div>

{moderator edit: solution code removed}  
no OOV indices are generated

---

<div class="post-metadata">

**Author:** ![lukmanaj](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/lukmanaj/32/161609_2.png) [@lukmanaj](https://community.deeplearning.ai/u/lukmanaj)\
**Post date:** [October 20, 2024, 2:27am UTC](https://community.deeplearning.ai/t/unable-to-exclude-oov-tokens/679010/9 "2024-10-20T02:27:33Z")

</div>

Sorry I had to remove the solution code as it is not allowed by the community guidelines. Mentors can only provide hints so the person learning can work towards the solution. This is to ensure the integrity of the course. If the learner follows this topic and tries a few times, I’m sure the learner will figure out the answer. This way, learning is more effective. Thank you.

---

<div class="post-metadata">

**Author:** ![Pankaj\_Giri](https://avatars.discourse-cdn.com/v4/letter/p/6f9a4e/32.png) [@Pankaj\_Giri](https://community.deeplearning.ai/u/Pankaj_Giri)\
**Post date:** [November 18, 2024, 5:51pm UTC](https://community.deeplearning.ai/t/unable-to-exclude-oov-tokens/679010/10 "2024-11-18T17:51:46Z")

</div>

was able to resolve issue after seeing @lukmanaj comment.  
But before coming to forum, I gone through documentation.  
Unfortunately the parameter description in tensorflow didn’t make sense to me at that time. I feel tensorflow documentation about this parameter need little more clarification on its usages.
