# How to use the generation\_utils.generate?

**URL:** <https://discuss.huggingface.co/t/how-to-use-the-generation-utils-generate/17277>\
**Category:** 🤗Transformers\
**Created:** [April 28, 2022, 9:16am UTC](https://discuss.huggingface.co/t/how-to-use-the-generation-utils-generate/17277 "2022-04-28T09:16:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![newbietuan](https://avatars.discourse-cdn.com/v4/letter/n/dec6dc/32.png) [@newbietuan](https://discuss.huggingface.co/u/newbietuan)\
**Post date:** [April 28, 2022, 9:16am UTC](https://discuss.huggingface.co/t/how-to-use-the-generation-utils-generate/17277/1 "2022-04-28T09:16:39Z")

</div>

i am doing image caption generation task，there are various implementation in different communities，which have their own improvements，i want to write a code that use the standard transformer structure，and i referenced the code in [The Annotated Transformer](http://nlp.seas.harvard.edu/2018/04/03/attention.html) ，  
now i should implement the beam\_search code for sequence generation，i noticed the transformer library has a implementation in the generation\_utils.generate, and there’s a lot document about text generation，but they are all pre-trained models and directly use the model.generate to generate sequence, but how should i use the generation\_utils.generate to generate caption on my own datasets based on the standard transformer structure? Is there any examples or tutorials that I can refer to？  
thanks a lot.
