# Can i vary the size of nn.TransformerEncoder outputs if not, then how do i calculate loss?

**URL:** <https://discuss.pytorch.org/t/can-i-vary-the-size-of-nn-transformerencoder-outputs-if-not-then-how-do-i-calculate-loss/82049>\
**Category:** Uncategorized\
**Created:** [May 19, 2020, 8:44pm UTC](https://discuss.pytorch.org/t/can-i-vary-the-size-of-nn-transformerencoder-outputs-if-not-then-how-do-i-calculate-loss/82049 "2020-05-19T20:44:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rohan\_Kumar](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/rohan_kumar/32/10228_2.png) [@Rohan\_Kumar](https://discuss.pytorch.org/u/Rohan_Kumar)\
**Post date:** [May 19, 2020, 8:44pm UTC](https://discuss.pytorch.org/t/can-i-vary-the-size-of-nn-transformerencoder-outputs-if-not-then-how-do-i-calculate-loss/82049/1 "2020-05-19T20:44:57Z")

</div>

I have followed this [guide](https://pytorch.org/tutorials/beginner/transformer_tutorial.html) on transformers, and found out that the input/ouput size of transformerEncoder layer is -

```auto
Input -> [source sequence length, batch size, embedding dimension]
Output -> [source sequence length, batch size, embedding dimension]

```

My question is that i have target sequence of length different than source sequence,

> target → [target sequence length ,batch size, embedding dimension]

so can i somehow change the code, so that my output matches the dimension of transformer, or how do i calculate the loss, given the dimensions dont match?
