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

peiying410632
from peiying410632 More from this publisher
22.02.2024 Views

Figure 8.14 - Final hidden states for eight sequences of the "perfect" squareFor clockwise movement, the final hidden states are situated in the upper-leftregion, while counterclockwise movement brings the final hidden states to thelower-right corner. The decision boundary, as expected from a logistic regression,is a straight line. The point closest to the decision boundary—that is, the one themodel is less confident about—corresponds to the sequence starting at the B corner(green) and moving clockwise (+)."What about the other hidden states for the actual sequences?"Let’s visualize them as well. In the figure below, clockwise sequences arerepresented by blue points and counterclockwise sequences, by red points.Figure 8.15 - Sequence of hidden statesWe can see that the model already achieves some separation after "seeing" two datapoints (corners), corresponding to "Hidden State #1." After "seeing" the thirdcorner, most of the sequences are already correctly classified, and, after observingRecurrent Neural Networks (RNNs) | 621

all corners, it gets every noisy square right."Can we pick one sequence and observe its hidden state from itsinitial to its final values?"Sure we can!The Journey of a Hidden StateLet’s use the ABCD sequence of the "perfect" square for this. The initial hiddenstate is (0, 0) by default, and it is colored black. Every time a new data point (corner)is going to be used in the computation, the affected hidden state is coloredaccordingly (gray, green, blue, and red, in order).The figure below tracks the progress of the hidden state over every operationperformed inside the RNN.The first column has the hidden state that’s an input for the RNN cell at a givenstep; the second column has the transformed hidden state; the third, thetranslated hidden state (by adding the transformed input); and the last, theactivated hidden state.There are four rows, one for each data point (corner) in our sequence. The initialhidden state of each row is the activated state of the previous row, so it starts atthe initial hidden state of the whole sequence (0, 0) and, after processing the gray,green, blue, and red corners, ends at the final hidden state, the red dot close to (-1,1) in the last plot.622 | Chapter 8: Sequences

all corners, it gets every noisy square right.

"Can we pick one sequence and observe its hidden state from its

initial to its final values?"

Sure we can!

The Journey of a Hidden State

Let’s use the ABCD sequence of the "perfect" square for this. The initial hidden

state is (0, 0) by default, and it is colored black. Every time a new data point (corner)

is going to be used in the computation, the affected hidden state is colored

accordingly (gray, green, blue, and red, in order).

The figure below tracks the progress of the hidden state over every operation

performed inside the RNN.

The first column has the hidden state that’s an input for the RNN cell at a given

step; the second column has the transformed hidden state; the third, the

translated hidden state (by adding the transformed input); and the last, the

activated hidden state.

There are four rows, one for each data point (corner) in our sequence. The initial

hidden state of each row is the activated state of the previous row, so it starts at

the initial hidden state of the whole sequence (0, 0) and, after processing the gray,

green, blue, and red corners, ends at the final hidden state, the red dot close to (-1,

1) in the last plot.

622 | Chapter 8: Sequences

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

Saved successfully!

Ooh no, something went wrong!