class_docstr: Multilingual encoder.
  
  This encoder consists of n separate encoders. A language token ID at the
  begin of the source sentence selects the encoder to use.
class_docstr_tok: ["Multilingual","encoder",".","This","encoder","consists","of","n","separate","encoders",".","A","language","token","ID","at","the","begin","of","the","source","sentence","selects","the","encoder","to","use","."]
code: def forward(self, src_tokens, src_lengths):
      # Fetch language IDs and remove them from src_tokens
      # Language IDs are on the right
      lang_ids = (
          src_tokens[:, -1]
          - pytorch_translate_data.MULTILING_DIALECT_ID_OFFSET
      )
      src_tokens = src_tokens[:, :-1]
      src_lengths -= 1
      # Create tensors for collecting encoder outputs
      bsz, seq_len = src_tokens.size()[:2]
      all_encoder_outs = utils.maybe_cuda(
          torch.zeros(seq_len, bsz, self.hidden_dim)
      )
      all_final_hidden = utils.maybe_cuda(
          torch.zeros(self.num_layers, bsz, self.hidden_dim)
      )
      all_final_cell = utils.maybe_cuda(
          torch.zeros(self.num_layers, bsz, self.hidden_dim)
      )
      # We cannot use zeros_like() for src_lengths because dtype changes
      # from LongInt to Int
      all_src_lengths = utils.maybe_cuda(
          torch.zeros(bsz, dtype=torch.int)
      )
      all_src_tokens = torch.zeros_like(src_tokens)
      all_embedded_words = utils.maybe_cuda(
          torch.zeros(seq_len, bsz, self.word_dim)
      )
      self.last_bsz = bsz
      self.last_lang_bszs = []
      for lang_id, encoder in enumerate(self.encoders):
          if encoder is None:
              continue
          indices = torch.nonzero(lang_ids == lang_id)
          lang_bsz = indices.size(0)
          self.last_lang_bszs.append(lang_bsz)
          if lang_bsz == 0:  # Language not in this batch
              for p in encoder.parameters():
                  p.grad = torch.zeros_like(p.data)
              continue
          indices = indices.squeeze(1)
          (
              lang_encoder_outs,
              lang_final_hidden,
              lang_final_cell,
              lang_src_lengths,
              lang_src_tokens,
              lang_embedded_words,
          ) = encoder(src_tokens[indices], src_lengths[indices])
          lang_seq_len = lang_encoder_outs.size(0)
          all_encoder_outs[
              :lang_seq_len, indices, :
          ] = lang_encoder_outs
          all_final_hidden[:, indices, :] = lang_final_hidden
          all_final_cell[:, indices, :] = lang_final_cell
          all_src_lengths[indices] = lang_src_lengths
          all_src_tokens[indices] = lang_src_tokens
          all_embedded_words[:, indices, :] = lang_embedded_words
      return (
          all_encoder_outs,
          all_final_hidden,
          all_final_cell,
          all_src_lengths,
          all_src_tokens,
          all_embedded_words,
      )
  
imports: import torch
  import torch.nn
  from fairseq.models import FairseqEncoder, FairseqIncrementalDecoder
  from pytorch_translate import utils
  from pytorch_translate.data import data
label_desc: Use image node_id 2 for calling the MultilingualEncoder obj's underlying member method code with example usage: obj.forward(src_tokens, src_lengths) and returns: all_encoder_outs,  all_final_hidden,  all_final_cell,  all_src_lengths,  all_src_tokens,  all_embedded_words