class_docstr: Policy Gradient agent for sequence prediction.
  
  This is a wrapper of the **training process** that trains a model
  with policy gradient. Agent itself does not create new trainable variables.
  
  Args:
      samples: An `int` Tensor of shape `[batch_size, max_time]` containing
          sampled sequences from the model.
      logits: A float Tenosr of shape `[batch_size, max_time, vocab_size]`
          containing the logits of samples from the model.
      sequence_length: A Tensor of shape `[batch_size]`.
          Time steps beyond the respective sequence lengths are masked out.
      trainable_variables (optional): Trainable variables of the model to
          update during training. If `None`, all trainable variables in the
          graph are used.
      learning_rate (optional): Learning rate for policy optimization. If
          not given, determine the learning rate from :attr:`hparams`.
          See :func:`~texar.tf.core.get_train_op` for more details.
      sess (optional): A tf session.
          Can be `None` here and set later with `agent.sess = session`.
      hparams (dict or HParams, optional): Hyperparameters. Missing
          hyperparamerter will be set to default values. See
          :meth:`default_hparams` for the hyperparameter sturcture and
          default values.
  
  Example:
  
      .. code-block:: python
  
          ## Train a decoder with policy gradient
          decoder = BasicRNNDecoder(...)
          outputs, _, sequence_length = decoder(
              decoding_strategy='infer_sample', ...)
  
          sess = tf.Session()
          agent = SeqPGAgent(
              samples=outputs.sample_id,
              logits=outputs.logits,
              sequence_length=sequence_length,
              sess=sess)
          while training:
              # Generate samples
              vals = agent.get_samples()
              # Evaluate reward
              sample_text = tx.utils.map_ids_to_strs(vals['samples'], vocab)
              reward_bleu = []
              for y, y_ in zip(ground_truth, sample_text)
                  reward_bleu.append(tx.evals.sentence_bleu(y, y_)
              # Update
              agent.observe(reward=reward_bleu)
class_docstr_tok: ["Policy","Gradient","agent","for","sequence","prediction",".","This","is","a","wrapper","of","the","*","*","training","process","*","*","that","trains","a","model","with","policy","gradient",".","Agent","itself","does","not","create","new","trainable","variables",".","Args",":","samples",":","An","`","int","`","Tensor","of","shape","`","[","batch_size",",","max_time","]","`","containing","sampled","sequences","from","the","model",".","logits",":","A","float","Tenosr","of","shape","`","[","batch_size",",","max_time",",","vocab_size","]","`","containing","the","logits","of","samples","from","the","model",".","sequence_length",":","A","Tensor","of","shape","`","[","batch_size","]","`",".","Time","steps","beyond","the","respective","sequence","lengths","are","masked","out",".","trainable_variables","(","optional",")",":","Trainable","variables","of","the","model","to","update","during","training",".","If","`","None","`",",","all","trainable","variables","in","the","graph","are","used",".","learning_rate","(","optional",")",":","Learning","rate","for","policy","optimization",".","If","not","given",",","determine","the","learning","rate","from",":","attr",":","`","hparams","`",".","See",":","func",":","`","~texar.tf.core.get_train_op","`","for","more","details",".","sess","(","optional",")",":","A","tf","session",".","Can","be","`","None","`","here","and","set","later","with","`","agent.sess","=","session","`",".","hparams","(","dict","or","HParams",",","optional",")",":","Hyperparameters",".","Missing","hyperparamerter","will","be","set","to","default","values",".","See",":","meth",":","`","default_hparams","`","for","the","hyperparameter","sturcture","and","default","values",".","Example",":","..","code-block",":",":","python","#","#","Train","a","decoder","with","policy","gradient","decoder","=","BasicRNNDecoder","(","...",")","outputs",",","_",",","sequence_length","=","decoder","(","decoding_strategy='infer_sample","'",",","...",")","sess","=","tf.Session","(",")","agent","=","SeqPGAgent","(","samples=outputs.sample_id",",","logits=outputs.logits",",","sequence_length=sequence_length",",","sess=sess",")","while","training",":","#","Generate","samples","vals","=","agent.get_samples","(",")","#","Evaluate","reward","sample_text","=","tx.utils.map_ids_to_strs","(","vals","[","'samples","'","]",",","vocab",")","reward_bleu","=","[","]","for","y",",","y_","in","zip","(","ground_truth",",","sample_text",")","reward_bleu.append","(","tx.evals.sentence_bleu","(","y",",","y_",")","#","Update","agent.observe","(","reward=reward_bleu",")"]
code: def sess(self, sess):
      self._sess = sess
  
imports: import tensorflow
  from texar.tf.agents.seq_agent_base import SeqAgentBase
  from texar.tf.core import optimization
  from texar.tf.losses.pg_losses import pg_loss_with_logits
  from texar.tf.losses.rewards import discount_reward
  from texar.tf.losses.entropy import sequence_entropy_with_logits
label_desc: Use image node_id 16 for calling the SeqPGAgent obj's underlying member method code with example usage: obj.sess(sess) without return types