# Text generation using custom constraints

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftext-generation-using-custom-constraints%2F22099%3E%5C
**Category:** 🤗Transformers\
**Created:** [August 25, 2022, 11:42am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftext-generation-using-custom-constraints%2F22099 "2022-08-25T11:42:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![et5h](https://avatars.discourse-cdn.com/v4/letter/e/839c29/32.png) [@et5h](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fet5h)%5C
**Post date:** [August 25, 2022, 11:42am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftext-generation-using-custom-constraints%2F22099%2F1 "2022-08-25T11:42:01Z")

</div>

Hi everyone,

I’d like to train a Seq2Seq model on predicting a new sequence containing the tokens of the input sequence plus some new tokens (here, token6, token7, token8).

Here, is an abstract example of my task since I’m training not on natural language but on a concept similar to SMILES to represent molecules:

Input: [‘token1’, 'token’2, ‘token3’, ‘token1’, ‘token5’]  
Output: [‘token1’, 'token’2, **‘token6’** , ‘token3’, ‘token1’, **‘token7’** , **‘token8’** , ‘token5’]

I wanted to ask if it is possible to contrain the text generation to force the model to use the tokens of the input sequence (here, 2x token1, 1x token2, 1x token3, 1x token5).  
In the [Generation documentation](https://huggingface.co/docs/transformers/main_classes/text_generation#transformers.generation_utils.GenerationMixin.generate.constraints) I found an argument called contraints, but I couldn’t figure out how I can use it.

Thanks in advance!
