@yngtodd lengths is a list of integers, in which each number corresponds to the actual length of each sentence.
It is need in order to take into account the zero-padded timesteps. Only by knowing the length of each sentence we can properly calculate the attention weights. We want to assign weight only on the actual words. Without knowing the length, the zero padded words will be assigned a non-zero weight by the attention mechanism.