# Using .generate with TAPAS as encoder in EncoderDecoder

**URL:** <https://discuss.huggingface.co/t/using-generate-with-tapas-as-encoder-in-encoderdecoder/13655>\
**Category:** Intermediate\
**Created:** [January 13, 2022, 12:35pm UTC](https://discuss.huggingface.co/t/using-generate-with-tapas-as-encoder-in-encoderdecoder/13655 "2022-01-13T12:35:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![per](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@per](https://discuss.huggingface.co/u/per)\
**Post date:** [January 13, 2022, 12:35pm UTC](https://discuss.huggingface.co/t/using-generate-with-tapas-as-encoder-in-encoderdecoder/13655/1 "2022-01-13T12:35:29Z")

</div>

Hi,  
I’m trying to to train the model to perform text generation conditioned on tables.

Since TAPAS can encode the semi-structured meaning in tables, I guessed it was a good choice to use it as an encoder and say GPT2 (or any other CLM) as a decoder.

I however encountered a problem when trying to generate from that EncoderDecoder model, this:

 ![image](https://us1.discourse-cdn.com/hellohellohello/original/2X/f/f450773b78ebe5afef3d0ce0cae24d80fcc703f3.png)

I guess this is since model.generate() for EncoderDecoder does not expect to have the extra dimension of token\_type\_ids that TAPAS has.  
Can anyone think of a way I can make this work?

Thanks!

---

<div class="post-metadata">

**Author:** ![per](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@per](https://discuss.huggingface.co/u/per)\
**Post date:** [January 17, 2022, 2:04pm UTC](https://discuss.huggingface.co/t/using-generate-with-tapas-as-encoder-in-encoderdecoder/13655/2 "2022-01-17T14:04:11Z")

</div>

Hi, does anyone know?  
@NielsRogge?

---

<div class="post-metadata">

**Author:** ![nielsr](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/nielsr/32/39617_2.png) [@nielsr](https://discuss.huggingface.co/u/nielsr)\
**Post date:** [January 17, 2022, 3:03pm UTC](https://discuss.huggingface.co/t/using-generate-with-tapas-as-encoder-in-encoderdecoder/13655/3 "2022-01-17T15:03:24Z")

</div>

Hi,

I’ll investigate and get back to you.

---

<div class="post-metadata">

**Author:** ![nielsr](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/nielsr/32/39617_2.png) [@nielsr](https://discuss.huggingface.co/u/nielsr)\
**Post date:** [January 17, 2022, 4:02pm UTC](https://discuss.huggingface.co/t/using-generate-with-tapas-as-encoder-in-encoderdecoder/13655/4 "2022-01-17T16:02:07Z")

</div>

Update: it works for me when overriding the `_update_model_kwargs_for_generation` [method](https://github.com/huggingface/transformers/blob/9a2dabae7002258e41419491c73dd43ad61b5de7/src/transformers/generation_utils.py#L572). The `token_type_ids` shouldn’t be updated, as a table only needs to get encoded once.

Notebook: [Google Colab](https://colab.research.google.com/drive/1ZBQZvqeXK2mIAZKx-X9Mf--xfdYI3Qig?usp=sharing)

---

<div class="post-metadata">

**Author:** ![per](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@per](https://discuss.huggingface.co/u/per)\
**Post date:** [January 18, 2022, 5:22pm UTC](https://discuss.huggingface.co/t/using-generate-with-tapas-as-encoder-in-encoderdecoder/13655/5 "2022-01-18T17:22:50Z")

</div>

It works for me!  
I’ll now go ahead and try to train it for conditional generation.  
Thanks! 🙏
