Hi,

The TransformerEncoder “transforms” each input embeddings with the help of neighboring embeddings in the sequence, so it is normal that the output is homogeneous with the input : it should be the same shape as the input.
You can look at the implementation of nn.TransformerEncoderLayer 26 for more details : you can see where dim_feedforward is used.
See the full nn.Transformer documentation 51 for details on required shapes : It is effectively [seq, batch, emb].
Note that nn.Embedding works with any shape : [size1, size2] -> [size1, size2, emb]
So you can use [seq, batch, emb] or [batch, seq, emb] for nn.Embedding.