wasiahmad
(Wasi Ahmad)
March 17, 2017, 9:41am
1
I have an attention decoder whose forward function is as follows.
def forward(self, input, hidden, encoder_outputs):
embedded = self.embedding(input).view(1, 1, -1)
embedded = self.drop(embedded)
attn_weights = F.softmax(self.attn(torch.cat((embedded[0], hidden[0]), 1)))
How can I print the shape of embedded
tensor inside the forward function? I checked, simple print() statement doesn’t work.
Any suggestion?
3 Likes
A print statement (print(embedded.size())
) should work. What do you mean when you say it doesn’t work (nothing happens?)
6 Likes
You can do print(embedded.size())
. Works for me even in the forward
function.
2 Likes
The .size() solution didn’t work for me when I had created an embedding using nn.Embedding. However, just printing the embeddings does show me size at the end of it:
print(embedded).
Hope this helps someone
kingxueyuf
(Yufan Xue)
February 23, 2018, 5:59am
5
jekbradbury:
embedded.size()
does this return a tuple?
I saw it is torch.Size([19, 25, 2100])
jekbradbury
(James Bradbury)
February 23, 2018, 6:15am
6
torch.Size
is essentially a tuple, and can do the same things
eduamf
(Eduardo A Mello Freitas)
May 2, 2019, 4:41am
7
Use print(embedded) to see the shape, or embedded.eval()
If you want to see the content, embedded.weight will show you the tensor and if it requires grad.