# Layoutlmv3 sequence\_length vs token\_sequnce\_length size mismatch

**URL:** <https://discuss.huggingface.co/t/layoutlmv3-sequence-length-vs-token-sequnce-length-size-mismatch/26270>\
**Category:** Models\
**Created:** [November 17, 2022, 9:08pm UTC](https://discuss.huggingface.co/t/layoutlmv3-sequence-length-vs-token-sequnce-length-size-mismatch/26270 "2022-11-17T21:08:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sajan](https://avatars.discourse-cdn.com/v4/letter/s/5e9695/32.png) [@Sajan](https://discuss.huggingface.co/u/Sajan)\
**Post date:** [November 17, 2022, 9:08pm UTC](https://discuss.huggingface.co/t/layoutlmv3-sequence-length-vs-token-sequnce-length-size-mismatch/26270/1 "2022-11-17T21:08:57Z")

</div>

I am trying to use Layoutlmv3Model for etracting features for every word/token, but sequecnce\_length/outut shape is different than input. The output shape is (batch, sequence\_length, embedding\_dim), the sequence length is always 197 more than length of input ids (eg, if I keep max\_length 100 in processor, my input\_ids are of length 100 but the model output is (batch\_len, 297, 768)). I am not sure what’s hapening and would like to know a way to map every token/subtoken to it’s extracted embedding. Are these the visual embeddings?

---

<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:** [November 18, 2022, 8:00am UTC](https://discuss.huggingface.co/t/layoutlmv3-sequence-length-vs-token-sequnce-length-size-mismatch/26270/2 "2022-11-18T08:00:31Z")

</div>

Hi,

This is because LayoutLMv3 uses both image and text modalities as input. The 197 comes from the fact that there are 196 image patches + 1 for the special CLS token (as the image resolution is 224 and the patch resolution is 16 =\> (224/16)\*\*2 = 196). So if you have input\_ids of length 100, then the total number of tokens that are sent through the Transformer are 197 + 100 = 297.

---

<div class="post-metadata">

**Author:** ![Sajan](https://avatars.discourse-cdn.com/v4/letter/s/5e9695/32.png) [@Sajan](https://discuss.huggingface.co/u/Sajan)\
**Post date:** [November 19, 2022, 5:40pm UTC](https://discuss.huggingface.co/t/layoutlmv3-sequence-length-vs-token-sequnce-length-size-mismatch/26270/3 "2022-11-19T17:40:03Z")

</div>

Hi,  
Thanks for clearing that up. I went through the code and there is a separate encoder block after concatenation of visual embedding and token embedding, so wanted to know if i simply do `output_embedding[1:len(subword_tokens)+1]` (assuming subword\_tokens without cls/pad) to get embeddings for the subwords, those features now also contain features from all the modalities
