code: def _capture_bernoulli_samples():
      """Use monkey-patching to capture the output of an Bernoulli sample."""
      observations = []
      true_sample = bernoulli_lib.Bernoulli.sample
  
      def _capturing_sample(
          self, sample_shape=(), seed=None, name="sample", **kwargs
      ):
          samples = true_sample(
              self, sample_shape, seed, name, **kwargs
          )
          observations.append(samples)
          return samples
  
      bernoulli_lib.Bernoulli.sample = _capturing_sample
      try:
          yield observations
      finally:
          bernoulli_lib.Bernoulli.sample = true_sample
  
imports: import contextlib
  from absl.testing import parameterized
  import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.distributions import bernoulli
  from tensorflow_probability.python.distributions import dpp
  from tensorflow_probability.python.distributions import uniform
  from tensorflow_probability.python.internal import test_util
  from tensorflow_probability.python.math.psd_kernels import exponentiated_quadratic
label_desc: Use image node_id 1 for calling a global function with example usage: _capture_bernoulli_samples() and returns: samples