# How to customize "generate" function in Pretrained Models like BART?

**URL:** <https://discuss.huggingface.co/t/how-to-customize-generate-function-in-pretrained-models-like-bart/21734>\
**Category:** 🤗Transformers\
**Created:** [August 17, 2022, 9:11am UTC](https://discuss.huggingface.co/t/how-to-customize-generate-function-in-pretrained-models-like-bart/21734 "2022-08-17T09:11:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![xjw](https://avatars.discourse-cdn.com/v4/letter/x/e19adc/32.png) [@xjw](https://discuss.huggingface.co/u/xjw)\
**Post date:** [August 17, 2022, 9:11am UTC](https://discuss.huggingface.co/t/how-to-customize-generate-function-in-pretrained-models-like-bart/21734/1 "2022-08-17T09:11:29Z")

</div>

For instance, I would like to concatenate two last encoder hidden states from two different texts and then enter them into cross attention module of decoder layer as the key and value in it. However, it seems hard to achieve this using existing generate function that could conduct beam search. I really want to know how to modify existing function to reach the aforementioned goal instead of achieving my own beam search from scratch.
