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",")"]
docstr: Returns a dictionary of hyperparameters with default values:
  
  .. role:: python(code)
     :language: python
  
  .. code-block:: python
  
      {
          'discount_factor': 0.95,
          'normalize_reward': False,
          'entropy_weight': 0.,
          'loss': {
              'average_across_batch': True,
              'average_across_timesteps': False,
              'sum_over_batch': False,
              'sum_over_timesteps': True,
              'time_major': False
          },
          'optimization': default_optimization_hparams(),
          'name': 'pg_agent',
      }
  
  Here:
  
  "discount_factor": float
      The discount factor of reward.
  
  "normalize_reward": bool
      Whether to normalize the discounted reward, by
      `(discounted_reward - mean) / std`. Here `mean` and `std` are
      over all time steps and all samples in the batch.
  
  "entropy_weight": float
      The weight of entropy loss of the sample distribution, to encourage
      maximizing the Shannon entropy. Set to 0 to disable the loss.
  
  "loss": dict
      Extra keyword arguments for
      :func:`~texar.tf.losses.pg_loss_with_logits`, including the
      reduce arguments (e.g., `average_across_batch`) and `time_major`
  
  "optimization": dict
      Hyperparameters of optimization for updating the policy net.
      See :func:`~texar.tf.core.default_optimization_hparams` for details.
  
  "name": str
      Name of the agent.
docstr_tok: ["Returns","a","dictionary","of","hyperparameters","with","default","values",":","..","role",":",":","python","(","code",")",":","language",":","python","..","code-block",":",":","python","{","'discount_factor","'",":","0.95",",","'normalize_reward","'",":","False",",","'entropy_weight","'",":","0.",",","'loss","'",":","{","'average_across_batch","'",":","True",",","'average_across_timesteps","'",":","False",",","'sum_over_batch","'",":","False",",","'sum_over_timesteps","'",":","True",",","'time_major","'",":","False","}",",","'optimization","'",":","default_optimization_hparams","(",")",",","'name","'",":","'pg_agent","'",",","}","Here",":","''","discount_factor","''",":","float","The","discount","factor","of","reward",".","``","normalize_reward","''",":","bool","Whether","to","normalize","the","discounted","reward",",","by","`","(","discounted_reward","-","mean",")","\/","std","`",".","Here","`","mean","`","and","`","std","`","are","over","all","time","steps","and","all","samples","in","the","batch",".","``","entropy_weight","''",":","float","The","weight","of","entropy","loss","of","the","sample","distribution",",","to","encourage","maximizing","the","Shannon","entropy",".","Set","to","0","to","disable","the","loss",".","``","loss","''",":","dict","Extra","keyword","arguments","for",":","func",":","`","~texar.tf.losses.pg_loss_with_logits","`",",","including","the","reduce","arguments","(","e.g.",",","`","average_across_batch","`",")","and","`","time_major","`","''","optimization","''",":","dict","Hyperparameters","of","optimization","for","updating","the","policy","net",".","See",":","func",":","`","~texar.tf.core.default_optimization_hparams","`","for","details",".","``","name","''",":","str","Name","of","the","agent","."]
code: def default_hparams():
      """Returns a dictionary of hyperparameters with default values:
  
      .. role:: python(code)
         :language: python
  
      .. code-block:: python
  
          {
              'discount_factor': 0.95,
              'normalize_reward': False,
              'entropy_weight': 0.,
              'loss': {
                  'average_across_batch': True,
                  'average_across_timesteps': False,
                  'sum_over_batch': False,
                  'sum_over_timesteps': True,
                  'time_major': False
              },
              'optimization': default_optimization_hparams(),
              'name': 'pg_agent',
          }
  
      Here:
  
      "discount_factor": float
          The discount factor of reward.
  
      "normalize_reward": bool
          Whether to normalize the discounted reward, by
          `(discounted_reward - mean) / std`. Here `mean` and `std` are
          over all time steps and all samples in the batch.
  
      "entropy_weight": float
          The weight of entropy loss of the sample distribution, to encourage
          maximizing the Shannon entropy. Set to 0 to disable the loss.
  
      "loss": dict
          Extra keyword arguments for
          :func:`~texar.tf.losses.pg_loss_with_logits`, including the
          reduce arguments (e.g., `average_across_batch`) and `time_major`
  
      "optimization": dict
          Hyperparameters of optimization for updating the policy net.
          See :func:`~texar.tf.core.default_optimization_hparams` for details.
  
      "name": str
          Name of the agent.
      """
      return {
          "discount_factor": 0.95,
          "normalize_reward": False,
          "entropy_weight": 0.0,
          "loss": {
              "average_across_batch": True,
              "average_across_timesteps": False,
              "sum_over_batch": False,
              "sum_over_timesteps": True,
              "time_major": False,
          },
          "optimization": opt.default_optimization_hparams(),
          "name": "pg_agent",
      }
  
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 6 for calling the SeqPGAgent obj's underlying member method code with example usage: obj.default_hparams() and returns: dict