22.02.2024 Views

Daniel Voigt Godoy - Deep Learning with PyTorch Step-by-Step A Beginner’s Guide-leanpub

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Output

(tensor([[[-0.6388, 0.8505],

[-0.4215, 0.8979],

[ 0.3792, 0.3432],

[ 0.3161, -0.1675]],

[[ 0.2911, -0.1811],

[ 0.3051, 0.7055],

[ 0.0000, 0.0000],

[ 0.0000, 0.0000]],

[[ 0.3385, 0.5927],

[-0.3875, 0.9422],

[-0.4832, 0.6595],

[ 0.0000, 0.0000]]], grad_fn=<IndexSelectBackward>),

tensor([4, 2, 3]))

It returns both the padded sequences and the original sizes, which will be useful as

well.

"Problem solved then? Can I take the last output now?"

Almost there—if you were to take the last output in the same way we did before,

you’d still get some padded zeros back:

output_unpacked[:, -1]

Output

tensor([[ 0.3161, -0.1675],

[ 0.0000, 0.0000],

[ 0.0000, 0.0000]], grad_fn=<SelectBackward>)

662 | Chapter 8: Sequences

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!