-
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
No way to get ONLY the generated text, not including the prompt. #17117
Comments
Hi @monsieurpooh ,
Two suggestions:
from transformers import pipeline
# This will remove the text for you.
pipe = pipeline(model="gpt2", return_full_text=False)
print(pipe("This is a test")) Does that solve your issue ? |
Thanks so much for your help Narsil! After a tiny bit of debugging and learning how to slice tensors, I figured out the correct code is: |
Thank you for giving the correct code here, will help other users for sure ! :) |
is there a fix for this? i'm using an workaround like this: |
Small observation. This works only if
|
System Info
Who can help?
@Narsil @patrickvonplaten
Information
Tasks
examples
folder (such as GLUE/SQuAD, ...)Reproduction
At first I thought I could just substring by the prompt's length. This doesn't work because there's a bug where it converts every instance of " ," to "," in the generated text.
For example, "Characters in this scene: King , Gertrude." becomes "Characters in this scene: King, Gertrude."
In https://github.com/huggingface/transformers/blob/main/src/transformers/generation_utils.py there are tons of options but not a single one of them allows us to specify it to ONLY return the generated text, not including the prompt.
I could do a workaround where I replace all the " ," with "," myself, but I'm sure this is a code smell which could lead to future problems.
Example code:
Expected behavior
Two possibilities: Either don't modify the prompt at all so I can substring by the prompt's length, or have an option where we get only the generated text not including the prompt.
The text was updated successfully, but these errors were encountered: