SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2004.03762 · 2020

Generating Narrative Text in a Switching Dynamical System

arXiv · PDF · Open in the Atlas

Code that ran

9 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; 0 honoured the contract we drafted, 0 violated it and 8 have no contract verdict; 1 failure of our instrument; 2 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/2004.03762.json · badge: /api/ran/2004.03762.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
StonyBrookNLP/SLDS-Stories canonical (classifier label)
classifier basis: census
9 ran · 2 no recorded run
FunctionStatusWhere it lives
compute_loss_unsupervised_LM Ran
ran on a synthesized input
StonyBrookNLP/SLDS-Stories/masked_cross_entropy.py
code served (permissive licence) · get_code("4a83c296dd50e739")
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, ndim 2, dtype family float; no output shape is stated. 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 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 torch
from torch.autograd import Variable

torch.manual_seed(0)

# Define the parameters for compute_loss_unsupervised_LM
num_sents = 2
batch_size = 2
seq_len = 3
vocab_size = 4

# text_logits: [num_sents, batch, seq_len, vocab_size]
text_logits = Variable(torch.randn(num_sents, batch_size, seq_len, vocab_size))

# text_targets: [num_sents, batch, seq_len] - indices of true classes
text_targets = Variable(torch.randint(0, vocab_size, (num_sents, batch_size, seq_len)).long())

# target_lens: [num_sents, batch] - lengths of sequences (must be <= seq_len)
target_lens = Variable(torch.tensor([[3, 2], [2, 3]], dtype=torch.long))

iteration = 0
use_cuda = False
do_print = False
test = False

ARGS = {
    'text_logits': text_logits,
    'text_targets': text_targets,
    'target_lens': target_lens,
    'iteration': iteration,
    'use_cuda': use_cuda,
    'do_print': do_print,
    'test': test
}
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, ndim 2, dtype family float — a tuple 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
fix_enc_hidden Ran
ran on a synthesized input
StonyBrookNLP/SLDS-Stories/EncDec.py
code served (permissive licence) · get_code("2f057e280e22d44b")
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 3, dtype family float, shape (2, 2, 16) 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)

# The function takes a tensor h and concatenates even and odd indexed slices along dimension 2
# h is indexed with [0:size:2] and [1:size:2] which means it expects h to have at least 1 dimension
# The result of cat along dimension 2 means h needs at least 3 dimensions
# Let's create a tensor with shape (batch=2, seq=4, hidden=8)
# This allows us to slice along dimension 0 and concatenate along dimension 2

h = torch.randn(4, 2, 8)  # shape: (4, 2, 8) - even/odd slicing on dim 0, cat on dim 2

ARGS = {
    "h": h
}
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 3, dtype family float, shape (2, 2, 16) — shape (2, 2, 16) 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
gather_last Ran
ran on a synthesized input
StonyBrookNLP/SLDS-Stories/EncDec.py
code served (permissive licence) · get_code("592535cda1dd181c")
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 2, dtype family float, shape (2, 4) 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
from torch.autograd import Variable

torch.manual_seed(0)

# Create a padded batched sequence tensor
# Shape: [batch=2, seq_len=5, feature_dim=4]
input_tensor = torch.randn(2, 5, 4)

# Create lengths tensor indicating actual sequence length for each batch element
# Shape: [batch=2]
lengths_tensor = torch.LongTensor([3, 4])

ARGS = {
    "input": input_tensor,
    "lengths": lengths_tensor,
    "use_cuda": 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 2, dtype family float, shape (2, 4) — shape (2, 4) 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
gumbel_sample Ran
ran on a synthesized input
StonyBrookNLP/SLDS-Stories/utils.py
code served (permissive licence) · get_code("509f852bce1cc974")
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 2, dtype family float, shape (2, 4) 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
from torch.autograd import Variable

torch.manual_seed(0)

ARGS = {
    "shape": (2, 4),
    "use_cuda": False,
    "eps": 1e-20,
}
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 2, dtype family float, shape (2, 4) — shape (2, 4) 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
load_vocab Ran
ran on a synthesized input
StonyBrookNLP/SLDS-Stories/data_utils.py
code served (permissive licence) · get_code("a127d4e3ccc2f275")
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 dict. 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 pickle
import tempfile
import os

# Create a temporary vocabulary file
temp_dir = tempfile.mkdtemp()
vocab_file = os.path.join(temp_dir, "vocab.pkl")

# Create a sample vocabulary (simple dict)
sample_vocab = {
    "word1": 0,
    "word2": 1,
    "word3": 2,
    "<pad>": 3,
    "<unk>": 4
}

# Save the vocabulary to a pickle file
with open(vocab_file, 'wb') as f:
    pickle.dump(sample_vocab, f)

ARGS = {
    "filename": vocab_file
}
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 dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict 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
normal_sample Ran
ran on a synthesized input
StonyBrookNLP/SLDS-Stories/utils.py
code served (permissive licence) · get_code("2cf3bf1f6ea37ceb")
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 2, dtype family float, shape (2, 4) 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
from torch.autograd import Variable

torch.manual_seed(0)

# Create small tensors for mu and logvar
# mu: mean of the normal distribution
mu = Variable(torch.randn(2, 4))

# logvar: log variance of the normal distribution
logvar = Variable(torch.randn(2, 4))

# use_cuda: boolean flag for CUDA usage (keep as False for CPU-only)
use_cuda = False

ARGS = {
    "mu": mu,
    "logvar": logvar,
    "use_cuda": use_cuda,
}
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 2, dtype family float, shape (2, 4) — shape (2, 4) 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
normal_sample_deterministic Ran
ran on a synthesized input
StonyBrookNLP/SLDS-Stories/utils.py
code served (permissive licence) · get_code("ebe372d67b34074e")
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 2, dtype family float, shape (2, 4) 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

torch.manual_seed(0)

# Create tensors with distinct sizes for different dimensions
# mu: mean of normal distribution (batch_size=2, dim=4)
mu = torch.randn(2, 4)

# logvar: log variance of normal distribution (batch_size=2, dim=4)
logvar = torch.randn(2, 4)

# eps: noise sample (batch_size=2, dim=4)
eps = torch.randn(2, 4)

# use_cuda: boolean flag (CPU only as per requirements)
use_cuda = False

ARGS = {
    "mu": mu,
    "logvar": logvar,
    "eps": eps,
    "use_cuda": use_cuda,
}
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 2, dtype family float, shape (2, 4) — shape (2, 4) 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
sequence_mask Ran
ran; our contract draft was wrong, not the code
StonyBrookNLP/SLDS-Stories/EncDec.py
code served (permissive licence) · get_code("639a7a37520aaba6")
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 2, dtype family float, shape (2, 4) 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 tensor of sequence lengths
# batch_size=2, each element represents the length of a sequence
lengths = torch.tensor([3, 2], dtype=torch.long)

# max_len is optional, can be None or an integer
max_len = 4

ARGS = {
    "lengths": lengths,
    "max_len": max_len,
}
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 2, dtype family float, shape (2, 4) — shape (2, 4) 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
transform Ran
ran on a synthesized input
StonyBrookNLP/SLDS-Stories/data_utils.py
code served (permissive licence) · get_code("92918efb0313ba75")
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 str. 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)

# The function takes an output (iterable of indices) and a dict that maps indices to strings
# It iterates through output and concatenates the corresponding dict values with spaces

# Create a simple dictionary mapping integers to strings
lookup_dict = {
    0: "hello",
    1: "world",
    2: "python",
    3: "code"
}

# Create output as a list of indices that exist in the dictionary
output = [0, 1, 2, 1, 3]

ARGS = {
    "output": output,
    "dict": lookup_dict
}
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 str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str 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
compute_loss_supervised Not yet run
unverified (harvested, no recorded run)
StonyBrookNLP/SLDS-Stories/masked_cross_entropy.py
code served (permissive licence) · get_code("6b72610a3dde3fa2")
How it ran

no invocation recorded.

compute_loss_unsupervised Not yet run
unverified (harvested, no recorded run)
StonyBrookNLP/SLDS-Stories/masked_cross_entropy.py
code served (permissive licence) · get_code("bc810b7c58cfa2e5")
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, 1 are also present in other papers whose code we hold (1 with at least one paper dated earlier, 0 the same month, 1 later) and 10 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
sequence_mask 6 other papers
4 dated earlier, 2 later
1808.09588 (2018-08)
Mapping Language to Code in Programmatic Context
1810.09995 (2018-10)
Deep Graph Convolutional Encoders for Structured Data to Text Generation
1905.13164 (2019-05)
Hierarchical Transformers for Multi-Document Summarization
and 3 more not named here

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

Early work on narrative modeling used explicit plans and goals to generate stories, but the language generation itself was restricted and inflexible. Modern methods use language models for more robust generation, but often lack an explicit representation of the scaffolding and dynamics that guide a coherent narrative. This paper introduces a new model that integrates explicit narrative structure with neural language models, formalizing narrative modeling as a Switching Linear Dynamical System (SLDS). A SLDS is a dynamical system in which the latent dynamics of the system (i.e. how the state vector transforms over time) is controlled by top-level discrete switching variables. The switching variables represent narrative structure (e.g., sentiment or discourse states), while the latent state vector encodes information on the current state of the narrative. This probabilistic formulation allows us to control generation, and can be learned in a semi-supervised fashion using both labeled and unlabeled data. Additionally, we derive a Gibbs sampler for our model that can fill in arbitrary parts of the narrative, guided by the switching variables. Our filled-in (English language) narratives outperform several baselines on both automatic and human evaluations.

For agents

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

get_harvested_code_for_paper("2004.03762")
get_code_for_paper("2004.03762")
have("2004.03762")

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

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

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

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

Connect an agent — have() is free.