code: def run_encoder(self,
                      source: mx.nd.NDArray,
                      source_max_length: int) -> Tuple['ModelState', mx.nd.NDArray]:
          
          batch_size = source.shape[0]
          batch = mx.io.DataBatch(data=[source],
                                  label=None,
                                  bucket_key=source_max_length,
                                  provide_data=self._get_encoder_data_shapes(source_max_length, batch_size))
  
          self.encoder_module.forward(data_batch=batch, is_train=False)
          decoder_init_states = self.encoder_module.get_outputs()
  
          if self.length_ratio is not None:
              estimated_length_ratio = decoder_init_states[-1]
              estimated_length_ratio = mx.nd.repeat(estimated_length_ratio, repeats=self.beam_size, axis=0)
              decoder_init_states = decoder_init_states[:-1]
          else:
              estimated_length_ratio = None
              decoder_init_states = decoder_init_states
          # replicate encoder/init module results beam size times
          decoder_init_states = [mx.nd.repeat(s, repeats=self.beam_size, axis=0) for s in decoder_init_states]
          return ModelState(decoder_init_states), estimated_length_ratio
docs: Runs forward pass of the encoder.
          Encodes source given source length and bucket key.
          Returns encoder representation of the source, source_length, initial hidden state of decoder RNN,
          and initial decoder states tiled to beam size.
  
          :param source: Integer-coded input tokens. Shape (batch_size, source length, num_source_factors).
          :param source_max_length: Bucket key.
          :return: Initial model state.