Skip to content

Exclude bad words in text generation #3434

Answered by hverma-forrester
sroy-forr asked this question in Q&A
Discussion options

You must be logged in to vote

Just passing the logits of bad words token ID assigned with negative number worked for me:

def bad_word_processor(token_ids, logits):
    logits[121] = float("-inf")
    logits[345] = float("-inf")
    logits[420] = float("-inf")
    return logits

sampling_params = SamplingParams(temperature=0.2, top_p=0.99, max_tokens=512, frequency_penalty=1.1, logits_processors=[bad_word_processor])

outputs = llm.generate(prompts, sampling_params)

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by richardliaw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #3361 on March 15, 2024 16:59.