Neural Machine Translation Assignment - Why outputs = list(Yoh.swapaxes(0,1))?

Hi. I don’t understand why Albert does this

outputs = list(Yoh.swapaxes(0,1))

Somebody can explain me, please

Thanks

The shape of Yoh is (m, Ty, len(machine_vocab)), i.e., one-hot representation of Y.

Then, please look at modelf() that you worked. In the step 1, input X is processed by Bidirectional LSTM. Then, step 2 starts.
In this step, the important index is Ty, time step (length) of Y. And, output is created as the list of output from each time step.
So, we need to pick the Ty (axis 1) to be the list length, and create a list of (m, len(machine_vocab)).

And, easiest way to do that is,

  1. swap axis 0 and 1 → then, Yoh is now in the shape of (Ty, m, len(machine_vocab))
  2. then, convert to the list. → You can see len(outputs) = 10 as Ty=10.
1 Like