code: def average_sources(source_encoded: mx.sym.Symbol, source_encoded_length: mx.sym.Symbol) -> mx.nd.NDArray:
          
          # source_masked: (n, source_encoded_length, hidden_size)
          source_masked = mx.sym.SequenceMask(data=source_encoded,
                                              axis=1,
                                              sequence_length=source_encoded_length,
                                              use_sequence_length=True,
                                              value=0.)
          # calculate the proper means of encoded sources
          averaged = mx.sym.broadcast_div(mx.sym.sum(source_masked, axis=1, keepdims=False),
                                                     mx.sym.reshape(source_encoded_length, shape=(-1, 1)))
          return averaged
docs: Calculate the average of encoded sources taking into account their lengths.
  
          :param source_encoded: Encoder representation for n elements. Shape: (n, source_encoded_length, hidden_size).
          :param source_encoded_length: A vector of encoded sequence lengths. Shape: (n,).
          :return: Average vectors. Shape(n, hidden_size).