class_docstr: TextGenerationTask use rnn as decoder and beam search technology when predict.
  Args:
      feature(Variable): The sentence-level feature, shape as [-1, emb_size].
      token_feature(Variable): The token-level feature, shape as [-1, seq_len, emb_size].
      max_seq_len(int): the decoder max sequence length.
      num_classes(int): total labels of the task.
      dataset(GenerationDataset): the dataset containing training set, development set and so on. If you want to finetune the model, you should set it.
               Otherwise, if you just want to use the model to predict, you can omit it. Default None
      num_layers(int): the decoder rnn layers number. Default 1
      hidden_size(int): the decoder rnn hidden size. Default 128
      dropout(float): the decoder dropout rate. Default 0.
      beam_size(int): the beam search size during predict phase. Default 10.
      beam_max_step_num(int): the beam search max step number. Default 30.
      start_token(str): the beam search start token. Default '<s>'
      end_token(str): the beam search end token. Default '</s>'
      startup_program(Program): the customized startup_program, default None
      config(RunConfig): the config for the task, default None
      metrics_choices(list): metrics used to the task, default ['bleu']
class_docstr_tok: ["TextGenerationTask","use","rnn","as","decoder","and","beam","search","technology","when","predict",".","Args",":","feature","(","Variable",")",":","The","sentence-level","feature",",","shape","as","[","-1",",","emb_size","]",".","token_feature","(","Variable",")",":","The","token-level","feature",",","shape","as","[","-1",",","seq_len",",","emb_size","]",".","max_seq_len","(","int",")",":","the","decoder","max","sequence","length",".","num_classes","(","int",")",":","total","labels","of","the","task",".","dataset","(","GenerationDataset",")",":","the","dataset","containing","training","set",",","development","set","and","so","on",".","If","you","want","to","finetune","the","model",",","you","should","set","it",".","Otherwise",",","if","you","just","want","to","use","the","model","to","predict",",","you","can","omit","it",".","Default","None","num_layers","(","int",")",":","the","decoder","rnn","layers","number",".","Default","1","hidden_size","(","int",")",":","the","decoder","rnn","hidden","size",".","Default","128","dropout","(","float",")",":","the","decoder","dropout","rate",".","Default","0.","beam_size","(","int",")",":","the","beam","search","size","during","predict","phase",".","Default","10.","beam_max_step_num","(","int",")",":","the","beam","search","max","step","number",".","Default","30.","start_token","(","str",")",":","the","beam","search","start","token",".","Default","'","<","s",">","'","end_token","(","str",")",":","the","beam","search","end","token",".","Default","'","<","\/s",">","'","startup_program","(","Program",")",":","the","customized","startup_program",",","default","None","config","(","RunConfig",")",":","the","config","for","the","task",",","default","None","metrics_choices","(","list",")",":","metrics","used","to","the","task",",","default","[","'bleu","'","]"]
code: def _build_net(self):
      self.seq_len = paddle.static.data(
          name="seq_len", shape=[1], dtype="int64", lod_level=0
      )
      self.seq_len_used = paddle.squeeze(self.seq_len)
      src_mask = nn.functional.sequence_mask(
          self.seq_len_used, maxlen=self.max_seq_len, dtype="float32"
      )
      enc_padding_mask = src_mask - 1.0
  
      # Define decoder and initialize it.
      dec_cell = AttentionDecoderCell(
          self.num_layers,
          self.feature.shape[-1],
          self.hidden_size,
          self.dropout,
      )
      dec_init_hidden = paddle.static.nn.fc(
          self.feature,
          size=self.hidden_size,
          num_flatten_dims=1,
          weight_attr=ParamAttr(
              name="dec_init_hidden_w",
              initializer=nn.initializer.TruncatedNormal(std=0.02),
          ),
          bias_attr=ParamAttr(
              name="dec_init_hidden_b",
              initializer=nn.initializer.Constant(0.0),
          ),
      )
      dec_initial_states = [
          [
              [
                  dec_init_hidden,
                  dec_cell.get_initial_states(
                      batch_ref=self.feature, shape=[self.hidden_size]
                  ),
              ]
          ]
          * self.num_layers,
          dec_cell.get_initial_states(
              batch_ref=self.feature, shape=[self.hidden_size]
          ),
      ]
      tar_vocab_size = len(self._label_list)
      tar_embeder = lambda x: paddle.static.nn.embedding(
          input=x,
          size=[tar_vocab_size, self.hidden_size],
          dtype="float32",
          is_sparse=False,
          param_attr=ParamAttr(
              name="target_embedding",
              initializer=nn.initializer.Uniform(low=-0.1, high=0.1),
          ),
      )
      start_token_id = self._label_list.index(self.start_token)
      end_token_id = self._label_list.index(self.end_token)
      if not self.is_predict_phase:
          self.dec_input = paddle.static.data(
              name="dec_input", shape=[self.max_seq_len], dtype="int64"
          )
          tar_emb = tar_embeder(self.dec_input)
          rnn = nn.RNN(dec_cell, is_reverse=False, time_major=False)
          dec_output, _ = rnn(
              inputs=tar_emb,
              initial_states=dec_initial_states,
              enc_output=self.token_feature,
              enc_padding_mask=enc_padding_mask,
          )
          self.logits = paddle.static.nn.fc(
              dec_output,
              size=tar_vocab_size,
              num_flatten_dims=len(dec_output.shape) - 1,
              weight_attr=ParamAttr(
                  name="output_w",
                  initializer=nn.initializer.Uniform(
                      low=-0.1, high=0.1
                  ),
              ),
          )
          self.ret_infers = paddle.reshape(
              x=paddle.argmax(self.logits, axis=2), shape=[-1, 1]
          )
          logits = self.logits
          logits = nn.functional.softmax(logits)
          return [logits]
      else:
          output_layer = lambda x: paddle.static.nn.fc(
              x,
              size=tar_vocab_size,
              num_flatten_dims=len(x.shape) - 1,
              weight_attr=ParamAttr(name="output_w"),
          )
          beam_search_decoder = BeamSearchDecoder(
              dec_cell,
              start_token_id,
              end_token_id,
              self.beam_size,
              embedding_fn=tar_embeder,
              output_fn=output_layer,
          )
          enc_output = beam_search_decoder.tile_beam_merge_with_batch(
              self.token_feature, self.beam_size
          )
          enc_padding_mask = (
              beam_search_decoder.tile_beam_merge_with_batch(
                  enc_padding_mask, self.beam_size
              )
          )
          self.ret_infers, _ = dynamic_decode(
              beam_search_decoder,
              inits=dec_initial_states,
              max_step_num=self.beam_max_step_num,
              enc_output=enc_output,
              enc_padding_mask=enc_padding_mask,
          )
          return self.ret_infers
  
imports: import time
  from collections import OrderedDict
  import numpy
  import paddle
  import paddle.nn
  from paddle import ParamAttr
  from paddle.nn import BeamSearchDecoder
  from paddle.nn import dynamic_decode
  from paddle.nn import LSTMCell
  from paddle.nn import RNN
  from paddle.nn import RNNCellBase
  from paddlehub.compat.task.base_task import BaseTask
  from paddlehub.compat.task.metrics import compute_bleu
label_desc: Use image node_id 3 for calling the TextGenerationTask obj's underlying member method code with example usage: obj._build_net() and returns: list, self