# Exclude words from GPT-2 generate( )

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fexclude-words-from-gpt-2-generate%2F4741%3E%5C
**Category:** 🤗Transformers\
**Created:** [March 19, 2021, 7:27pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fexclude-words-from-gpt-2-generate%2F4741 "2021-03-19T19:27:42Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![deathcrush](https://avatars.discourse-cdn.com/v4/letter/d/58f4c7/32.png) [@deathcrush](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fdeathcrush)%5C
**Post date:** [March 19, 2021, 7:32pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fexclude-words-from-gpt-2-generate%2F4741%2F2 "2021-03-19T19:32:07Z")

</div>

Hello!

I seems that this functionality is supported using the `bad_words_ids` input to the `generate` API. The [docs](https://huggingface.co/transformers/main_classes/model.html?highlight=generate) briefly describe that you need to find a list of integers for the words you care about using the `tokenizer` and then simply pass those to `generate`:

```auto
**bad_words_ids** ( `List[List[int]]` , optional) – List of token ids that are not allowed to be generated. In order to get the tokens of the words that should not appear in the generated text, use `tokenizer(bad_word, add_prefix_space=True).input_ids` .

I hope this helps!
``
```

---

_[View the full topic](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fexclude-words-from-gpt-2-generate%2F4741)._
