SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 1802.08786 · 2018

Syntax-Directed Variational Autoencoder for Structured Data

arXiv · PDF · Open in the Atlas

Code that ran

2 of 3 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; 0 honoured the contract we drafted, 0 violated it and 2 have no contract verdict; 0 failures of our instrument; 1 no recorded run), measured 2026-11-22; repository links from the Papers with Code archive attributed under CC BY-SA, no affiliation; 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/1802.08786.json · badge: /api/ran/1802.08786.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
Hanjun-Dai/sdvae canonical (classifier label)
classifier basis: census
2 ran · 1 no recorded run
FunctionStatusWhere it lives
my_perp_loss Ran
ran on a synthesized input
Hanjun-Dai/sdvae/mol_vae/mol_decoder/custom_loss.py
code served (permissive licence) · get_code("0e5d4ba1c7e73f4c")
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 (1,) 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.functional as F

torch.manual_seed(0)

# Analyze the function signature and body:
# - true_binary: used with .size()[1], operations like multiplication, accessed in dim 2
# - rule_masks: used with .size(), accessed in dim 2, has a [:, :, -1] slice
# - raw_logits: used with F.torch.max(..., 2, ...), accessed in dim 2

# Shape requirements from the code:
# - All three tensors need to support indexing in dimension 2
# - true_binary.size()[1] is used for normalization
# - rule_masks[:, :, -1] suggests shape (batch, seq, num_rules)
# - Need keepdim=True in max along dim 2, so at least 3D

# Build small tensors with distinct dimensions
batch_size = 2
seq_len = 3
num_rules = 4

# true_binary: binary targets, shape (batch, seq, num_rules)
true_binary = torch.zeros(batch_size, seq_len, num_rules, dtype=torch.float32)
true_binary[0, 0, 0] = 1.0
true_binary[1, 1, 2] = 1.0

# rule_masks: binary masks, shape (batch, seq, num_rules)
rule_masks = torch.ones(batch_size, seq_len, num_rules, dtype=torch.float32)
rule_masks[0, 0, -1] = 1.0  # Ensure last rule can be masked

# raw_logits: logits, shape (batch, seq, num_rules)
raw_logits = torch.randn(batch_size, seq_len, num_rules, dtype=torch.float32)

ARGS = {
    'true_binary': true_binary,
    'rule_masks': rule_masks,
    'raw_logits': raw_logits,
}
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 (1,) — shape (1,) 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
parse Ran
ran on a synthesized input
Hanjun-Dai/sdvae/mol_vae/cfg_parser/cfg_parser.py
code served (permissive licence) · get_code("0373d0c88b91050c")
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 list, ndim 1, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim 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 nltk
from nltk.grammar import Nonterminal, Production
from nltk.parse.generate import generate

# Create a minimal grammar object that satisfies the parse function's usage
class MockGrammar:
    def __init__(self):
        # Create a simple context-free grammar
        from nltk import CFG
        
        # Define production rules
        productions = [
            Production(Nonterminal('S'), [Nonterminal('NP'), Nonterminal('VP')]),
            Production(Nonterminal('NP'), ['dog']),
            Production(Nonterminal('NP'), ['cat']),
            Production(Nonterminal('VP'), ['runs']),
            Production(Nonterminal('VP'), ['sleeps']),
        ]
        
        self.cfg = CFG(Nonterminal('S'), productions)
        
        # Create head_to_rules mapping
        self.head_to_rules = {}
        for prod in productions:
            lhs = prod.lhs()
            if lhs not in self.head_to_rules:
                self.head_to_rules[lhs] = []
            self.head_to_rules[lhs].append(prod.rhs())
        
        # Create a parser
        from nltk.parse.chart import ChartParser
        self.cfg_parser = ChartParser(self.cfg)
    
    def tokenize(self, sent):
        # Simple whitespace tokenization
        if not isinstance(sent, str):
            return None
        tokens = sent.strip().split()
        return tokens if tokens else None

# Instantiate the grammar
grammar = MockGrammar()

# Create a simple sentence that can be parsed
sent = "dog runs"

ARGS = {
    'sent': sent,
    'grammar': grammar,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
nltk — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list, ndim 1, dtype family float — a list output has no array shape of its own; none is stated
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
my_binary_loss Not yet run
unverified (harvested, no recorded run)
Hanjun-Dai/sdvae/mol_vae/mol_decoder/custom_loss.py
code served (permissive licence) · get_code("80a3e2a84a56eb02")
How it ran

no invocation recorded.

Also present in other papers' code

Of 3 samples lifted from this paper's linked repositories, 3 carry a function identity and 0 do not. Of the 3 distinct functions with an identity, 0 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 0 later) and 3 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.

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-22.

Repositories linked to this paper

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

Abstract

Deep generative models have been enjoying success in modeling continuous data. However it remains challenging to capture the representations for discrete structures with formal grammars and semantics, e.g., computer programs and molecular structures. How to generate both syntactically and semantically correct data still remains largely an open problem. Inspired by the theory of compiler where the syntax and semantics check is done via syntax-directed translation (SDT), we propose a novel syntax-directed variational autoencoder (SD-VAE) by introducing stochastic lazy attributes. This approach converts the offline SDT check into on-the-fly generated guidance for constraining the decoder. Comparing to the state-of-the-art methods, our approach enforces constraints on the output space so that the output will be not only syntactically valid, but also semantically reasonable. We evaluate the proposed model with applications in programming language and molecules, including reconstruction and program/molecule optimization. The results demonstrate the effectiveness in incorporating syntactic and semantic constraints in discrete generative models, which is significantly better than current state-of-the-art approaches.

For agents

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

get_harvested_code_for_paper("1802.08786")
get_code_for_paper("1802.08786")
have("1802.08786")

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

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

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

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

Connect an agent — have() is free.