code: def greedy_generate(
      decoder,
      tokens=None,
      state=None,
      max_length=20,
      max_len_a=0.0,
      num_beams=1,
      bos_token_id=None,
      eos_token_id=None,
      pad_token_id=0,
      repetition_penalty=1,
      length_penalty=1.0,
  ):
      """
      贪婪地搜索句子
  
      :param Decoder decoder: Decoder对象
      :param torch.LongTensor tokens: batch_size, len, decode的输入值，如果为None，则自动从bos_token_id开始生成
      :param State state: 应该包含encoder的一些输出。
      :param int max_length: 生成句子的最大长度, 每句话的decode长度为max_length + max_len_a*src_len
      :param float max_len_a: 每句话的decode长度为max_length + max_len_a*src_len。 如果不为0，需要保证State中包含encoder_mask
      :param int num_beams: 使用多大的beam进行解码。
      :param int bos_token_id: 如果tokens传入为None，则使用bos_token_id开始往后解码。
      :param int eos_token_id: 结束的token，如果为None，则一定会解码到max_length这么长。
      :param int pad_token_id: pad的token id
      :param float repetition_penalty: 对重复出现的token多大的惩罚。
      :param float length_penalty: 对每个token（除了eos）按照长度进行一定的惩罚。
      :return:
      """
      if num_beams == 1:
          token_ids = _no_beam_search_generate(
              decoder,
              tokens=tokens,
              state=state,
              max_length=max_length,
              max_len_a=max_len_a,
              temperature=1,
              top_k=50,
              top_p=1,
              bos_token_id=bos_token_id,
              eos_token_id=eos_token_id,
              do_sample=False,
              repetition_penalty=repetition_penalty,
              length_penalty=length_penalty,
              pad_token_id=pad_token_id,
          )
      else:
          token_ids = _beam_search_generate(
              decoder,
              tokens=tokens,
              state=state,
              max_length=max_length,
              max_len_a=max_len_a,
              num_beams=num_beams,
              temperature=1,
              top_k=50,
              top_p=1,
              bos_token_id=bos_token_id,
              eos_token_id=eos_token_id,
              do_sample=False,
              repetition_penalty=repetition_penalty,
              length_penalty=length_penalty,
              pad_token_id=pad_token_id,
          )
  
      return token_ids
  
file_path: fastNLP/fastNLP/modules/torch/generator/seq2seq_generator.py
imports: import torch
  from torch import nn
  import torch.nn.functional
  from ..decoder.seq2seq_decoder import Seq2SeqDecoder, State
  from functools import partial
label_desc: Use image node_id 2 for calling a global function with example usage: greedy_generate(decoder, tokens, state, max_length, max_len_a, num_beams, bos_token_id, eos_token_id, pad_token_id, repetition_penalty, length_penalty) and returns: token_ids