计算负 ELBO

Calculating negative ELBO

我正在阅读深度马尔可夫模型的教程,他们在其中尝试学习和弦数据集。 Link 教程是:

https://pyro.ai/examples/dmm.html

该模型使用神经网络对转换和排放进行参数化,对于变分推理部分,他们使用 RNN 将可观察 'x' 映射到潜在 space。为了确保他们的模型正在学习一些东西,他们试图最大化 ELBO 或最小化负 ELBO。他们将负 ELBO 称为 NLL。到目前为止,我明白他们在做什么。然而,下一步让我感到困惑。一旦他们有了 NLL,他们就会将其除以序列长度之和。

times = [time.time()]
for epoch in range(args.num_epochs):
    # accumulator for our estimate of the negative log likelihood
    # (or rather -elbo) for this epoch
    epoch_nll = 0.0
    # prepare mini-batch subsampling indices for this epoch
    shuffled_indices = np.arange(N_train_data)
    np.random.shuffle(shuffled_indices)

    # process each mini-batch; this is where we take gradient steps
    for which_mini_batch in range(N_mini_batches):
        epoch_nll += process_minibatch(epoch, which_mini_batch, shuffled_indices)

    # report training diagnostics
    times.append(time.time())
    epoch_time = times[-1] - times[-2]
    log("[training epoch %04d]  %.4f \t\t\t\t(dt = %.3f sec)" %
        (epoch, epoch_nll / N_train_time_slices, epoch_time))

而且我不太明白他们为什么要这样做。有人可以解释一下吗?他们在这里平均吗?不胜感激。

在教程中,他们通过优化过程试图减少损失,最后想将其与教程中的参考资料[1]进行比较。

"Finally we report some diagnostic info. Note that we normalize the loss by the total number of time slices in the training set (this allows us to compare to reference [1])."

这来自您提供的教程。

基本上计算所有小批量的损失,他们正在对其进行归一化,以便最终损失将是他们最初采用的整个训练数据序列长度的损失。

当我们将 运行 代码时,我们可以在从日志记录生成的诊断报告中的每个时期之后的整体损失。