SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2004.12585 · ACL · 2020

A Batch Normalized Inference Network Keeps the KL Vanishing Away

Xiaojiang Liu, Dapeng Wu, Wei Bi, Xiyao Ma, Xiaolin Li, Qile Zhu

arXiv · PDF · Open in the Atlas

Code that ran

5 of 11 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 1 honoured the contract we drafted, 0 violated it and 3 have no contract verdict; 1 failure of our instrument; 6 no recorded run), measured 2026-11-21; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2004.12585.json · badge: /api/ran/2004.12585.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
valdersoul/bn-vae canonical (classifier label)
classifier basis: census
5 ran · 6 no recorded run
FunctionStatusWhere it lives
calc_mi Ran
ran on a synthesized input
valdersoul/bn-vae/utils.py
code served (permissive licence) · get_code("cd7e66b917a18914")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Tensor, ndim 0, dtype family float, shape () as a later run recorded it. The image it ran in was not recorded. The code mentions cuda, and the harness aliases cuda to the CPU for every sample; whether this run needed that is not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn
import numpy as np
import math

torch.manual_seed(0)

class GaussianEncoder(nn.Module):
    def __init__(self, input_dim=5, latent_dim=4):
        super().__init__()
        self.fc = nn.Linear(input_dim, latent_dim * 2)
    
    def forward(self, x):
        h = self.fc(x)
        mu = h[:, :h.size(1)//2]
        logvar = h[:, h.size(1)//2:]
        return mu, logvar
    
    def reparameterize(self, mu, logvar, num_samples=1):
        std = (logvar / 2).exp()
        eps = torch.randn(mu.size(0), num_samples, mu.size(1))
        z = mu.unsqueeze(1) + eps * std.unsqueeze(1)
        return z

class Encoder(nn.Module):
    def __init__(self, input_dim=5, latent_dim=4):
        super().__init__()
        self.gaussian_enc = GaussianEncoder(input_dim, latent_dim)
    
    def forward(self, x):
        return self.gaussian_enc.forward(x)
    
    def reparameterize(self, mu, logvar, num_samples=1):
        return self.gaussian_enc.reparameterize(mu, logvar, num_samples)

class SimpleVAE(nn.Module):
    def __init__(self, input_dim=5, latent_dim=4):
        super().__init__()
        self.encoder = Encoder(input_dim, latent_dim)
    
    def forward(self, x):
        return self.encoder.forward(x)

# Create mock log_sum_exp function
def mock_log_sum_exp(x, dim):
    return torch.logsumexp(x, dim=dim)

# Patch the module
import sys
from types import ModuleType
modules_utils = ModuleType('modules.utils')
modules_utils.log_sum_exp = mock_log_sum_exp
sys.modules['modules.utils'] = modules_utils
modules = ModuleType('modules')
modules.utils = modules_utils
sys.modules['modules'] = modules

# Create test data batches (list of tensors)
batch_size = 2
input_dim = 5
latent_dim = 4

test_data_batch = [
    torch.randn(batch_size, input_dim),
    torch.randn(batch_size, input_dim)
]

# Create model
model = SimpleVAE(input_dim=input_dim, latent_dim=latent_dim)
model.eval()

ARGS = {
    "model": model,
    "test_data_batch": test_data_batch
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
modules, numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 0, dtype family float, shape () — shape () as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
create_exp_dir Ran
ran on a synthesized input
valdersoul/bn-vae/exp_utils.py
code served (permissive licence) · get_code("c8da81fe940d3ca2")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned partial. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import functools
import os
import shutil
import tempfile

# Create a temporary directory for the experiment
temp_dir = tempfile.mkdtemp()

# Create some dummy script files to save
dummy_script_1 = os.path.join(temp_dir, "dummy_script_1.py")
dummy_script_2 = os.path.join(temp_dir, "dummy_script_2.py")

with open(dummy_script_1, 'w') as f:
    f.write("# dummy script 1\n")

with open(dummy_script_2, 'w') as f:
    f.write("# dummy script 2\n")

# Create the experiment directory path
exp_dir_path = os.path.join(temp_dir, "experiment_dir")

ARGS = {
    "dir_path": exp_dir_path,
    "scripts_to_save": [dummy_script_1, dummy_script_2],
    "debug": False
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type partial — a partial output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a partial output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
generate_grid Ran
ran on a synthesized input
valdersoul/bn-vae/modules/utils.py
code served (permissive licence) · get_code("69f9f574272f9c32")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned tuple. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

torch.manual_seed(0)

ARGS = {
    "zmin": 0.0,
    "zmax": 2.0,
    "dz": 0.5,
    "device": "cpu",
    "ndim": 2,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple — a tuple output has no array shape of its own; none is stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
log_sum_exp Ran
ran; our contract draft was wrong, not the code
valdersoul/bn-vae/modules/utils.py
code served (permissive licence) · get_code("5efe6eb2209f6591")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Tensor, ndim 1, dtype family float, shape (2,) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

torch.manual_seed(0)

# Create a small tensor for testing log_sum_exp
# The function operates on a single tensor and optionally reduces along a dimension
value = torch.randn(2, 4)

# Test case 1: with dim specified
ARGS = {
    "value": value,
    "dim": 1,
    "keepdim": False
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 1, dtype family float, shape (2,) — shape (2,) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
safe_log Ran
ran, honoured the contract we drafted
valdersoul/bn-vae/modules/utils.py
pointer only (licence: MIT); the stored copy get_code serves, from ex4sperans/variational-inference-with-normalizing-flows, is pointer only (licence: NONE) · get_code("6298a45a525420e8")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from ex4sperans/variational-inference-with-normalizing-flows, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

calc_au Not yet run
unverified (harvested, no recorded run)
valdersoul/bn-vae/utils.py
code served (permissive licence) · get_code("ecb556d46a1e1a8e")
How it ran

no invocation recorded.

calc_iwnll Not yet run
unverified (harvested, no recorded run)
valdersoul/bn-vae/utils.py
code served (permissive licence) · get_code("6df3d4cb4d4dc5c5")
How it ran

no invocation recorded.

get_confirm_token Not yet run
unverified (harvested, no recorded run)
valdersoul/bn-vae/prepare_data.py
pointer only (licence: MIT); the stored copy get_code serves, from med-air/FedBN, is pointer only (licence: NONE) · get_code("135b3dc835ffe6ad")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from med-air/FedBN, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. No invocation recorded.

get_logger Not yet run
unverified (harvested, no recorded run)
valdersoul/bn-vae/exp_utils.py
code served (permissive licence) · get_code("2a751ef26f71f337")
How it ran

no invocation recorded.

test Not yet run
unverified (harvested, no recorded run)
valdersoul/bn-vae/lm.py
code served (permissive licence) · get_code("f1ba669623777faf")
How it ran

no invocation recorded.

test Not yet run
unverified (harvested, no recorded run)
valdersoul/bn-vae/t_s_f.py
code served (permissive licence) · get_code("7ad017041756a7ce")
How it ran

no invocation recorded.

Also present in other papers' code

Of 11 samples lifted from this paper's linked repositories, 11 carry a function identity and 0 do not. Of the 11 distinct functions with an identity, 5 are also present in other papers whose code we hold (4 with at least one paper dated earlier, 1 the same month, 3 later) and 6 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

FunctionAlso present inEarliest-datedOthers named
get_confirm_token 38 other papers
20 dated earlier, 1 the same month, 17 later
1409.8230 (2014-09)
RENOIR - A Dataset for Real Low-Light Image Noise Reduction
1503.03832 (2015-03)
FaceNet: A Unified Embedding for Face Recognition and Clustering
1506.03134 (2015-06)
Pointer Networks
and 35 more not named here
log_sum_exp 5 other papers
1 dated earlier, 4 later
1901.05534 (2019-01)
Lagging Inference Networks and Posterior Collapse in Variational Autoencoders
2110.12381 (2021-10)
Regularizing Variational Autoencoder with Diversity and Uncertainty Awareness
2207.06130 (2022-07)
Fuse It More Deeply! A Variational Transformer with Layer-Wise Latent Variable Inference for Text Generation
and 2 more not named here
get_logger 3 other papers
3 later
2106.06295 (2021-06)
Going Beyond Linear Transformers with Recurrent Fast Weight Programmers
2304.11062 (2023-04)
Scaling Transformer to 1M tokens and beyond with RMT
2406.13770 (2024-06)
Elliptical Attention
safe_log 2 other papers
2 dated earlier · 1 only as an assembly brick
1505.05770 (2015-05)
Variational Inference with Normalizing Flows
2002.11896 (2020-02)
Gradient Boosted Normalizing Flows
generate_grid 1 other paper
1 dated earlier
1901.05534 (2019-01)
Lagging Inference Networks and Posterior Collapse in Variational Autoencoders

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-21.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

Variational Autoencoder (VAE) is widely used as a generative model to approximate a model's posterior on latent variables by combining the amortized variational inference and deep neural networks. However, when paired with strong autoregressive decoders, VAE often converges to a degenerated local optimum known as "posterior collapse". Previous approaches consider the Kullback-Leibler divergence (KL) individual for each datapoint. We propose to let the KL follow a distribution across the whole dataset, and analyze that it is sufficient to prevent posterior collapse by keeping the expectation of the KL's distribution positive. Then we propose Batch Normalized-VAE (BN-VAE), a simple but effective approach to set a lower bound of the expectation by regularizing the distribution of the approximate posterior's parameters. Without introducing any new model component or modifying the objective, our approach can avoid the posterior collapse effectively and efficiently. We further show that the proposed BN-VAE can be extended to conditional VAE (CVAE). Empirically, our approach surpasses strong autoregressive baselines on language modeling, text classification and dialogue generation, and rivals more complex approaches while keeping almost the same training time as VAE.

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2004.12585")
get_code_for_paper("2004.12585")
have("2004.12585")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2004.12585.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2004.12585.svg)](https://syntology.ai/paper/2004.12585)

Connect an agent — have() is free.