-
Notifications
You must be signed in to change notification settings - Fork 27.7k
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
stopping criteria for TextGenerationPipeline #26280
Comments
Hey! You can pass from transformers import pipeline, StoppingCriteriaList, MaxTimeCriteria
# Initialize the text generation pipeline
generator = pipeline("text-generation")
# Define the stopping criteria using MaxTimeCriteria
stopping_criteria = StoppingCriteriaList([MaxTimeCriteria(32)])
# Define the generation_kwargs with stopping criteria
generation_kwargs = {
"max_length": 100, # Maximum length of the generated text
"max_new_tokens": 10, # Maximum number of new tokens to generate
"generation_kwargs": {"stopping_criteria": stopping_criteria} # Add stopping criteria to generation_kwargs
}
# Pass the generation_kwargs to the pipeline
generated_text = generator(
"Hey! How are you able.",
**generation_kwargs
)
# Print the generated text
print(generated_text[0]["generated_text"])
>>> Hey! How are you able. Do you have a job or do you have |
This should probably be added to the documentation! |
cc @MKhalusova who is currently working on the |
The
However, I see a couple of issues:
I can address these. |
Is this a duplicate of #17562? If so, it seems the only reason that older issue is still open is because of the missing documentation. If the documentation is fixed then both can be closed. |
According to my experiments, setting generation_kwargs = {
"max_new_tokens": 1000, # Maximum number of new tokens to generate
"generation_kwargs": {"stopping_criteria": stopping_criteria} # Add stopping criteria to generation_kwargs
} is not feasible for passing a stopping criteria into a pipeline. Instead, if we let "stopping_criteria" out of "generation_kwargs", it then works well. As below: generation_kwargs = {
"max_new_tokens": 1000, # Maximum number of new tokens to generate
"stopping_criteria": stopping_criteria,
} |
Feature request
pass stopping criteria or string to TextGenerationPipeline
Motivation
it does not exist, have not found any way to do it at least, but would be very useful
Your contribution
none
The text was updated successfully, but these errors were encountered: