In pytorch, when we want to provide a 2-dimensional input with shape (batch_size, embedding_size), we should be careful with the definition. By default, the pytorch will treat the first dimension as sequence dimension, and second dimension as embedding dimension. So we should do two things : (1) Set batch_first to be True in TransformerEncoderLayer (2) Modify the input data to be 3 dimensional to indicate it’s a sequence of size of 1
Reprint policy:
All articles in this blog are used except for special statements
CC BY 4.0
reprint policy. If reproduced, please indicate source
robot learner
!