code: def posterior_to_xarray(self):
          
          # Do not make pyro a requirement
          from pyro.infer import EmpiricalMarginal
  
          try:  # Try pyro>=0.3 release syntax
              data = {
                  name: np.expand_dims(samples.enumerate_support().squeeze(), 0)
                  if self.posterior.num_chains == 1
                  else samples.enumerate_support().squeeze()
                  for name, samples in self.posterior.marginal(
                      sites=self.latent_vars
                  ).empirical.items()
              }
          except AttributeError:  # Use pyro<0.3 release syntax
              data = {}
              for var_name in self.latent_vars:
                  # pylint: disable=no-member
                  samples = EmpiricalMarginal(
                      self.posterior, sites=var_name
                  ).get_samples_and_weights()[0]
                  data[var_name] = np.expand_dims(samples.numpy().squeeze(), 0)
          return dict_to_dataset(data, library=self.pyro, coords=self.coords, dims=self.dims)
docs: Convert the posterior to an xarray dataset.