code: def generate_table(
      device,
      num_quadrant_inputs,
      pre_trained_baseline,
      pre_trained_cvae,
      num_particles,
      col_name,
  ):
      # Load sample random data
      datasets, dataloaders, dataset_sizes = get_data(
          num_quadrant_inputs=num_quadrant_inputs, batch_size=32
      )
  
      # Load sample data
      criterion = MaskedBCELoss()
      loss_fn = Trace_ELBO(
          num_particles=num_particles
      ).differentiable_loss
  
      baseline_cll = 0.0
      cvae_mc_cll = 0.0
      num_preds = 0
  
      df = pd.DataFrame(
          index=["NN (baseline)", "CVAE (Monte Carlo)"],
          columns=[col_name],
      )
  
      # Iterate over data.
      bar = tqdm(
          dataloaders["val"], desc="Generating predictions".ljust(20)
      )
      for batch in bar:
          inputs = batch["input"].to(device)
          outputs = batch["output"].to(device)
          num_preds += 1
  
          # Compute negative log likelihood for the baseline NN
          with torch.no_grad():
              preds = pre_trained_baseline(inputs)
          baseline_cll += criterion(
              preds, outputs
          ).item() / inputs.size(0)
  
          # Compute the negative conditional log likelihood for the CVAE
          cvae_mc_cll += loss_fn(
              pre_trained_cvae.model,
              pre_trained_cvae.guide,
              inputs,
              outputs,
          ).detach().item() / inputs.size(0)
  
      df.iloc[0, 0] = baseline_cll / num_preds
      df.iloc[1, 0] = cvae_mc_cll / num_preds
      return df
  
file_path: pyro/examples/cvae/util.py
imports: from pathlib import Path
  import matplotlib.pyplot
  import numpy
  import pandas
  import torch
  from baseline import MaskedBCELoss
  from mnist import get_data
  from torch.utils.data import DataLoader
  from torchvision.utils import make_grid
  from tqdm import tqdm
  from pyro.infer import Predictive, Trace_ELBO
label_desc: Use image node_id 3 for calling a global function with example usage: generate_table(device, num_quadrant_inputs, pre_trained_baseline, pre_trained_cvae, num_particles, col_name) and returns: df