class_docstr: Greedy sequence generator based on the decoder followed by log_softmax.
  
  Args:
      embedding: nn.Module, transforms input_ids into vector embeddings
      decoder: nn.Module, takes embeddings and produces hidden_states
      log_softmax: nn.Module, takes hidden_states and produces log_probs
          which correspond to probability distribution of tokens (ids)
      pad: index of padding token in the vocabulary
      bos: index of beginning of sequence token in the vocabulary
      eos: index of end of sequence token in the vocabulary
      max_sequence_length: maximum allowed length for generated sequences
      max_delta_length: in case of encoder-decoder generation (e.g. NMT),
          forbids generated sequences to be longer than the length of
          source sequences plus max_delta_length
      batch_size: size of the batch of generated sequences if neither
          source nor target starting sequences are provided
class_docstr_tok: ["Greedy","sequence","generator","based","on","the","decoder","followed","by","log_softmax",".","Args",":","embedding",":","nn.Module",",","transforms","input_ids","into","vector","embeddings","decoder",":","nn.Module",",","takes","embeddings","and","produces","hidden_states","log_softmax",":","nn.Module",",","takes","hidden_states","and","produces","log_probs","which","correspond","to","probability","distribution","of","tokens","(","ids",")","pad",":","index","of","padding","token","in","the","vocabulary","bos",":","index","of","beginning","of","sequence","token","in","the","vocabulary","eos",":","index","of","end","of","sequence","token","in","the","vocabulary","max_sequence_length",":","maximum","allowed","length","for","generated","sequences","max_delta_length",":","in","case","of","encoder-decoder","generation","(","e.g",".","NMT",")",",","forbids","generated","sequences","to","be","longer","than","the","length","of","source","sequences","plus","max_delta_length","batch_size",":","size","of","the","batch","of","generated","sequences","if","neither","source","nor","target","starting","sequences","are","provided"]
code: def _forward(
      self,
      decoder_input_ids=None,
      encoder_hidden_states=None,
      encoder_input_mask=None,
      return_beam_scores=False,
  ):
      assert not return_beam_scores
      tgt, batch_size, max_generation_length = self._prepare_for_search(
          decoder_input_ids, encoder_hidden_states
      )
  
      # pad profile tracks sequences ending with <eos> token to replace
      # everything after <eos> with <pad> token
      decoder_parameter = next(self.decoder.parameters())
      pad_profile = (
          torch.zeros(batch_size, 1).long().to(decoder_parameter.device)
      )
  
      decoder_mems_list = None
      for i in range(max_generation_length):
          log_probs, decoder_mems_list = self._one_step_forward(
              tgt[:, -1:],
              encoder_hidden_states,
              encoder_input_mask,
              decoder_mems_list,
              i,
          )
  
          next_tokens = torch.argmax(
              log_probs[:, -1], dim=-1, keepdim=True
          )
          next_tokens = self.pad * pad_profile + next_tokens * (
              1 - pad_profile
          )
          pad_profile = torch.max(
              pad_profile, (next_tokens == self.eos).long()
          )
          tgt = torch.cat((tgt, next_tokens), dim=-1)
  
          # abort generation if all sequences end with <eos>
          if pad_profile.sum() == batch_size:
              break
  
      return tgt
  
imports: from contextlib import contextmanager
  import torch
  from nemo.collections.common.parts import NEG_INF, mask_padded_tokens
label_desc: Use image node_id 4 for calling the GreedySequenceGenerator obj's underlying member method code with example usage: obj._forward(decoder_input_ids, encoder_hidden_states, encoder_input_mask, return_beam_scores) and returns: tgt