line 21: maxlen = numpy.max(lengths)+1 line 27: x_mask[:lengths[idx]+1,idx] = 1. It seems unnecessary to have "+1" in both these two places. It would cause problem logically.