# Generation but constraining first few tokens

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fgeneration-but-constraining-first-few-tokens%2F28421%3E%5C
**Category:** 🤗Transformers\
**Created:** [December 25, 2022, 11:01pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fgeneration-but-constraining-first-few-tokens%2F28421 "2022-12-25T23:01:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![minimario](https://avatars.discourse-cdn.com/v4/letter/m/e79b87/32.png) [@minimario](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fminimario)%5C
**Post date:** [December 25, 2022, 11:01pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fgeneration-but-constraining-first-few-tokens%2F28421%2F1 "2022-12-25T23:01:40Z")

</div>

I’m trying to use a pre-trained T5ForConditionalGeneration model to do generation from a prefix of a sentence. For example, I might feed it “ 2 + 2 =”, and I’d like it to generate “4”.

I notice that the generate() function for this model always produces a generation starting with the two tokens [pad\_token, bos\_token]. Therefore, if I just pass the input through model.generate, I get a nonsensical output. I see two potential solutions:

1. Feed it in “”, and fix the first few tokens of the generation to be “2 + 2 =”
2. Feed it in “ 2 + 2 =”, and find a way to remove the pad and bos tokens from the generation.

I don’t know how to do either, and help would be appreciated! Thanks!
