-
Notifications
You must be signed in to change notification settings - Fork 25.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bad_words_ids not working #17504
Comments
I wrote a function to enumerate all possible permutations of " Badword", but it quickly blows up with hundreds of permutations like [" B","a","d","w","o","r","d"]. Limiting the token length works ok, but still doesn't prevent generation of variations like [" Bad","words"] I think this overall approach just doesn't really work for preventing the generation of bad_words. Don't know if there's a better solution than generate + filter.
|
Hey @Jack000 👋 It is not clear from your description -- have you tried using the tokenizer with the instructions given in the ["...in order to get the token ids of the words that should not appear in the generated text, use |
That's what I did. This will consistently tokenize [" Badword"] as [11908] but during inference the model will generate [7286, 1754] which is [" Bad", "word"] as I mentioned above I wrote a function to enumerate all possible ways of combining tokens to form "Badword", but the problem is that it doesn't work for variations like "Badwords" and "Badwordo". Extending the permutations to include these variations results in thousands of permutations per bad_word and doesn't really scale. |
Okay, I think I got your issue :) When you add a word to There are a few things worth mentioning here:
You can see an example for a few cases mentioned above here. The solution for banning subwords is to explicitly add them to the list of |
ah the actual bad word I was trying to ban was [" Hitler"]. I do understand how the bad_words_ids feature works, but I guess my issue is that I don't want the word "Hitler" generated under any circumstances subwords or otherwise. As you can see I did implement a function to enumerate all possible ways tokens can be combined to form "Hitler" to add to bad_words_ids, but if I include "Hitlers" and other such variations the possible permutations will number in the thousands. anyways, I don't see a simple solution to this but the function I wrote in addition to filtering afterwards works ok for now. |
My apologies :D Better safe than sorry, in case there was some confusion about the intended behavior. |
@patil-suraj could you maybe also take a look here? Otherwise happy to dive deeper if necessary |
Sorry could I ping @ArthurZucker or @gante on this one maybe? :-) |
Hey! I looked at the problem a bit, and as you mentioned, the permutations would be a bit too problematic. We can probably work this out by rather banning a normalized string. Instead of checking if [Bad_id,Word_id] are generated, we can should convert the a string by deciding, normalize and remove the bad word. This is more efficient but might not have its place in the generate function, as the tokenizer is not available. But it probably makes sens to have a custom logit processor that needs to be initialized with the tokenizer. Let me ask around 🤗 |
This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread. Please note that issues that do not follow the contributing guidelines are likely to be ignored. |
Feature request
I'm using gpt2 for text generation with a word blacklist and noticed that some words on the blacklist were still being generated.
I found that even though the word ["badword"] would not be generated, it would still generate ["bad", "word"] in two tokens.
an example of this is [11908] and [7286, 1754]
this seems to be a different issue from the leading space issue and padding issue. I think I could get around it by adding the split tokens to the blacklist, but I can't seem to get the tokenizer to split the string to produce [7286, 1754]. Is there a way to get all possible permutations of a string to add to the blacklist?
Motivation
Without this feature bad_words_ids basically doesn't work most of the time
Your contribution
Not familiar with the tokenizer code unfortunately
The text was updated successfully, but these errors were encountered: