code: def test_docstring_example_bernoulli(self):
      num_draws = int(1e5)
      probs_p = tf.constant(0.4)
      probs_q = tf.constant(0.7)
  
      def exact_kl_bernoulli_bernoulli(probs_p, probs_q):
          p = bernoulli.Bernoulli(probs=probs_p)
          q = bernoulli.Bernoulli(probs=probs_q)
          return kullback_leibler.kl_divergence(p, q)
  
      def approx_kl_bernoulli_bernoulli(probs_p, probs_q):
          p = bernoulli.Bernoulli(probs=probs_p)
          q = bernoulli.Bernoulli(probs=probs_q)
          return expectation.expectation(
              f=lambda x: p.log_prob(x) - q.log_prob(x),
              samples=p.sample(num_draws, seed=test_util.test_seed()),
              log_prob=p.log_prob,
              use_reparameterization=(
                  p.reparameterization_type
                  == reparameterization.FULLY_REPARAMETERIZED
              ),
          )
  
      approx_kl_, approx_kl_grad = gradient.value_and_gradient(
          approx_kl_bernoulli_bernoulli, probs_p, probs_q
      )
      exact_kl_, exact_kl_grad = gradient.value_and_gradient(
          exact_kl_bernoulli_bernoulli, probs_p, probs_q
      )
  
      self.assertAllClose(exact_kl_, approx_kl_, rtol=0.02, atol=0.0)
  
      # Compare gradients. (Not present in `docstring`.)
      # Notice that variance (i.e., `rtol`) is higher when using score-trick.
      self.assertAllCloseNested(
          exact_kl_grad, approx_kl_grad, rtol=0.05, atol=0.0
      )
  
imports: import tensorflow.compat.v2
  from tensorflow_probability.python.distributions import bernoulli
  from tensorflow_probability.python.distributions import joint_distribution_named
  from tensorflow_probability.python.distributions import kullback_leibler
  from tensorflow_probability.python.distributions import normal
  from tensorflow_probability.python.internal import reparameterization
  from tensorflow_probability.python.internal import test_util
  from tensorflow_probability.python.internal.monte_carlo import _get_samples
  from tensorflow_probability.python.math import gradient
  from tensorflow_probability.python.monte_carlo import expectation
label_desc: Use image node_id 3 for calling the ExpectationTest obj's underlying member method code with example usage: obj.test_docstring_example_bernoulli() and returns: kullback_leibler, expectation