22.02.2024 Views

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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

column-wise fashion, from top to bottom, and from left to right, to assign the data

points to the corresponding indices in the data tensor.

Finally, it uses these indices to assemble the data tensor:

Figure 8.28 - Packed data points

Thus, to retrieve the values of the original sequences, we need to slice the data

tensor accordingly. For example, we can retrieve the first sequence from the data

tensor by reading the values from its corresponding indices: 0, 3, 6, and 8.

(packed.data[[0, 3, 6, 8]] == seq_tensors[0]).all()

Output

tensor(True)

Once the sequence is properly packed, we can feed it directly to an RNN:

output_packed, hidden_packed = rnn(packed)

output_packed, hidden_packed

Variable-Length Sequences | 659

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

Saved successfully!

Ooh no, something went wrong!