# Generate() returns full prompt plus answer

**URL:** <https://discuss.huggingface.co/t/generate-returns-full-prompt-plus-answer/70453>\
**Category:** 🤗Transformers\
**Created:** [January 24, 2024, 5:53pm UTC](https://discuss.huggingface.co/t/generate-returns-full-prompt-plus-answer/70453 "2024-01-24T17:53:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexszen](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@alexszen](https://discuss.huggingface.co/u/alexszen)\
**Post date:** [January 24, 2024, 5:53pm UTC](https://discuss.huggingface.co/t/generate-returns-full-prompt-plus-answer/70453/1 "2024-01-24T17:53:10Z")

</div>

Hi all,

Some models, when generating text, return the prompt + the answer in the output. For instance mistral models and phi-2 have this behavior. Other models such as flan-t5 don’t do that, and the output only contains the generated text, without prepending the prompt. Is there a way to only return the generated text for e.g. mistral or phi-2? I’ve tried some solutions found online (e.g. [tiiuae/falcon-40b-instruct · Model returns entire input prompt together with output](https://huggingface.co/tiiuae/falcon-40b-instruct/discussions/43) suggest setting “include\_prompt\_in\_result” or “return\_full\_text” to False, but these args don’t seem to exist).

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Manel](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/manel/32/55218_2.png) [@Manel](https://discuss.huggingface.co/u/Manel)\
**Post date:** [February 19, 2024, 2:50am UTC](https://discuss.huggingface.co/t/generate-returns-full-prompt-plus-answer/70453/2 "2024-02-19T02:50:18Z")

</div>

Hi @alexszen

You can exclude the prompt part ‘prompt\_length’ from the model’s output, then you can pass only the answer to the decoder as follow:

```
inputs = tokenizer(prompt, return_tensors="pt")

outputs = model.generate(input_ids=inputs['input_ids'])

prompt_length = inputs['input_ids'].shape[1]

answer = tokenizer.decode(outputs[0][prompt_length:])

```
