parameters: (dist_tensor, value, loss, baseline=None,
                     name="ScoreFunction")
docstring: Score function estimator.
  
    Computes the integrand of the score function with a baseline:
    `p.log_prob(value) * (loss - baseline)`.
  
    It will add a `stop_gradient` to the advantage `(loss - baseline)`.
  
    Args:
      dist_tensor: `DistributionTensor` p(x).
      value: `Tensor` x. Samples from p(x).
      loss: `Tensor`.
      baseline: `Tensor` broadcastable to `loss`.
      name: name to prepend ops with.
  
    Returns:
      `Tensor` `p.log_prob(x) * (loss - b)`. Taking the gradient yields the score
      function estimator.
docstring_summary: Score function estimator.
docstring_tokens: Score function estimator .
function: def score_function(dist_tensor, value, loss, baseline=None,
                     name="ScoreFunction"):
    """Score function estimator.
  
    Computes the integrand of the score function with a baseline:
    `p.log_prob(value) * (loss - baseline)`.
  
    It will add a `stop_gradient` to the advantage `(loss - baseline)`.
  
    Args:
      dist_tensor: `DistributionTensor` p(x).
      value: `Tensor` x. Samples from p(x).
      loss: `Tensor`.
      baseline: `Tensor` broadcastable to `loss`.
      name: name to prepend ops with.
  
    Returns:
      `Tensor` `p.log_prob(x) * (loss - b)`. Taking the gradient yields the score
      function estimator.
    """
    with ops.name_scope(name, values=[value, loss, baseline]):
      value = ops.convert_to_tensor(value)
      loss = ops.convert_to_tensor(loss)
      if baseline is not None:
        baseline = ops.convert_to_tensor(baseline)
        advantage = loss - baseline
      else:
        advantage = loss
  
      advantage = array_ops.stop_gradient(advantage)
      return dist_tensor.distribution.log_prob(value) * advantage
function_tokens: def score_function ( dist_tensor , value , loss , baseline = None , name = "ScoreFunction" ) : with ops . name_scope ( name , values = [ value , loss , baseline ] ) : value = ops . convert_to_tensor ( value ) loss = ops . convert_to_tensor ( loss ) if baseline is not None : baseline = ops . convert_to_tensor ( baseline ) advantage = loss - baseline else : advantage = loss advantage = array_ops . stop_gradient ( advantage ) return dist_tensor . distribution . log_prob ( value ) * advantage