{'fraction_non_alphanumeric': 0.04208470212199236, 'fraction_numerical': 0.02074639675634082, 'mean_word_length': 4.639185580774366, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Unsupervised Recurrent Neural Network Grammars

Recurrent neural network grammars (RNNG) are generative models of language which jointly model syntax and surface structure by incrementally generating a syntax tree and sentence in a top-down, left-to-right order. Supervised RNNGs achieve strong language modeling and parsing performance, but require an annotated corpus of parse trees. In this work, we experiment with unsupervised learning of RNNGs. Since directly marginalizing over the space of latent trees is intractable, we instead apply amortized variational inference. To maximize the evidence lower bound, we develop an inference network parameterized as a neural CRF constituency parser. On language modeling, unsupervised RNNGs perform as well their supervised counterparts on benchmarks in English and Chinese. On constituency grammar induction, they are competitive with recent neural language models that induce tree structures from words through attention mechanisms.


Introduction
Recurrent neural network grammars (RNNGs) (Dyer et al., 2016) model sentences by first generating a nested, hierarchical syntactic structure which is used to construct a context representation to be conditioned upon for upcoming words. Supervised RNNGs have been shown to outperform standard sequential language models, achieve excellent results on parsing (Dyer et al., 2016;Kuncoro et al., 2017), better encode syntactic properties of language , and correlate with electrophysiological responses in the human brain . However, these all require annotated syntactic trees for training. In this work, we explore unsupervised learning of recurrent neural network grammars for language modeling and grammar induction.
Work done while the first author was an intern at DeepMind. Code available at https://github.com/harvardnlp/urnng The standard setup for unsupervised structure learning is to define a generative model p θ (x, z) over observed data x (e.g. sentence) and unobserved structure z (e.g. parse tree, part-of-speech sequence), and maximize the log marginal likelihood log p θ (x) = log z p θ (x, z). Successful approaches to unsupervised parsing have made strong conditional independence assumptions (e.g. context-freeness) and employed auxiliary objectives (Klein and Manning, 2002) or priors (Johnson et al., 2007). These strategies imbue the learning process with inductive biases that guide the model to discover meaningful structures while allowing tractable algorithms for marginalization; however, they come at the expense of language modeling performance, particularly compared to sequential neural models that make no independence assumptions.
Like RNN language models, RNNGs make no independence assumptions. Instead they encode structural bias through operations that compose linguistic constituents. The lack of independence assumptions contributes to the strong language modeling performance of RNNGs, but make unsupervised learning challenging. First, marginalization is intractable. Second, the biases imposed by the RNNG are relatively weak compared to those imposed by models like PCFGs. There is little pressure for non-trivial tree structure to emerge during unsupervised RNNG (URNNG) learning.
In this work, we explore a technique for handling intractable marginalization while also injecting inductive bias. Specifically we employ amortized variational inference (Kingma and Welling, 2014;Rezende et al., 2014;Mnih and Gregor, 2014) with a structured inference network. Variational inference lets us tractably optimize a lower bound on the log marginal likelihood, while employing a structured inference network encourages non-trivial structure. In particular, a con-ditional random field (CRF) constituency parser (Finkel et al., 2008;Durrett and Klein, 2015), which makes significant independence assumptions, acts as a guide on the generative model to learn meaningful trees through regularizing the posterior (Ganchev et al., 2010).
We experiment with URNNGs on English and Chinese and observe that they perform well as language models compared to their supervised counterparts and standard neural LMs. In terms of grammar induction, they are competitive with recently-proposed neural architectures that discover tree-like structures through gated attention (Shen et al., 2018). Our results, along with other recent work on joint language modeling/structure learning with deep networks (Shen et al., 2018(Shen et al., , 2019Wiseman et al., 2018;Kawakami et al., 2018), suggest that it is possible learn generative models of language that model the underlying data well (i.e. assign high likelihood to held-out data) and at the same time induce meaningful linguistic structure.

Unsupervised Recurrent Neural Network Grammars
We use x = [x 1 , . . . , x T ] to denote a sentence of length T , and z ∈ Z T to denote an unlabeled binary parse tree over a sequence of length T , represented as a a binary vector of length 2T − 1. Here 0 and 1 correspond to SHIFT and REDUCE actions, explained below. 1 Figure 1 presents an overview of our approach.

Generative Model
An RNNG defines a joint probability distribution p θ (x, z) over sentences x and parse trees z. We consider a simplified version of the original RNNG (Dyer et al., 2016) by ignoring constituent labels and only considering binary trees. The RNNG utilizes an RNN to parameterize a stack data structure (Dyer et al., 2015) of partiallycompleted constituents to incrementally build the parse tree while generating terminals. Using the current stack representation, the model samples an action (SHIFT or REDUCE): SHIFT generates a terminal symbol, i.e. word, and shifts it onto the stack, 2 REDUCE pops the last two elements off 1 The cardinality of ZT ⊂ {0, 1} 2T −1 is given by the (T − 1)-th Catalan number, |ZT | = (2T −2)! T !(T −1)! . 2 A better name for SHIFT would be GENERATE (as in Dyer et al. (2016)), but we use SHIFT to emphasize similarity with the shift-reduce parsing. Figure 1: Overview of our approach. The inference network q φ (z | x) (left) is a CRF parser which produces a distribution over binary trees (shown in dotted box). Bij are random variables for existence of a constituent spanning i-th and j-th words, whose potentials are the output from a bidirectional LSTM (the global factor ensures that the distribution is only over valid binary trees). The generative model p θ (x, z) (right) is an RNNG which consists of a stack LSTM (from which actions/words are predicted) and a tree LSTM (to obtain constituent representations upon REDUCE). Training involves sampling a binary tree from q φ (z | x), converting it to a sequence of shift/reduce actions (z = [SHIFT, SHIFT, SHIFT, REDUCE, REDUCE, SHIFT, REDUCE] in the above example), and optimizing the log joint likelihood log p θ (x, z). the stack, composes them, and shifts the composed representation onto the stack.
Formally, let S = [(0, 0)] be the initial stack. Each item of the stack will be a pair, where the first element is the hidden state of the stack LSTM, and the second element is an input vector, described below. We use top(S) to refer to the top pair in the stack. The push and pop operations are defined imperatively in the usual way. At each time step, the next action z t (SHIFT or REDUCE) is sampled from a Bernoulli distribution parameterized in terms of the current stack representation. Letting (h prev , g prev ) = top(S), we have Subsequent generation depend on z t : • If z t = 0 (SHIFT), the model first generates a terminal symbol via sampling from a categorical distribution whose parameters come from an affine transformation and a softmax, Then the generated terminal is shifted onto the stack using a stack LSTM, where e x is the word embedding for x.
• If z t = 1 (REDUCE), we pop the last two elements off the stack, and obtain a new representation that combines the left/right constituent representations using a tree LSTM (Tai et al., 2015;Zhu et al., 2015), g new = TreeLSTM(g l , g r ).
Note that we use g l and g r to obtain the new representation instead of h l and h r . 3 We then update the stack using g new , The generation process continues until an end-ofsentence symbol is generated. The parameters θ of the generative model are w, b, W, b, and the parameters of the stack/tree LSTMs. For a sentence x = [x 1 , . . . , x T ] of length T , the binary parse tree is given by the binary vector z = [z 1 , . . . , z 2T −1 ]. 4 The joint log likelihood decomposes as a sum of terminal/action log likelihoods, where z <n(t) refers to all actions before generating the t-th word, and similarly x <m(j) refers to all words generated before taking the j-th action. For brevity, from here on we will use log p θ (x | z) to refer to the first term (terminal log likelihood) and log p θ (z | x <z ) to refer to the second term (action log likelihood) in the above decomposition. 5 3 The update equations for the tree LSTM (and the stack LSTM) also involve cell states in addition to the hidden states. To reduce notational clutter we do not explicitly show the cell states and instead subsume them into g. If one (or both) of the inputs to the tree LSTM is a word embedding, the associated cell state is taken to be zero. See Tai et al. (2015) for the exact parameterization. 4 As it stands, the support of z is {0, 1} 2T −1 , all binary vectors of length 2T − 1. To restrict our distribution to ZT (binary vectors which describe valid trees), we constrain zt to be valid at each time step, which amounts to deterministically choosing zt = 0 (SHIFT) if there are fewer than two elements (not counting the initial zero tuple) on the stack. 5 The action log likelihood is the sum of log conditional priors, which is obviously different from the unconditional log prior log p θ (z) = log x p θ (x, z).
In the supervised case where ground-truth z is available, we can straightforwardly perform gradient-based optimization to maximize the joint log likelihood log p θ (x, z). In the unsupervised case, the standard approach is to maximize the log marginal likelihood, However this summation is intractable because z t fully depends on all previous actions [z 1 , . . . , z t−1 ]. Even if this summation were tractable, it is not clear that meaningful latent structures would emerge given the lack of explicit independence assumptions in the RNNG (e.g. it is clearly not context-free). We handle these issues with amortized variational inference.

Amortized Variational Inference
Amortized variational inference (Kingma and Welling, 2014) defines a trainable inference network φ that parameterizes q φ (z | x), a variational posterior distribution, in this case over parse trees z given the sentence x. This distribution is used to form an evidence lower bound (ELBO) on the log marginal likelihood, We maximize the ELBO with respect to both model parameters θ and inference network parameters φ. The ELBO is still intractable to calculate exactly, but this formulation will allow us to obtain unbiased gradient estimators based on Monte Carlo sampling.
Observe that rearranging the ELBO gives the following optimization problem, Thus, φ is trained to match the variational posterior q φ (z | x) to the true posterior p θ (z | x), but θ is also trained to match the true posterior to the variational posterior. Indeed, there is some evidence to suggest that generative models trained with amortized variational inference (i.e. variational autoencoders) learn posterior distributions that are close to the variational family (Cremer et al., 2018).
We can use this to our advantage with an inference network that injects inductive bias. We propose to do this by using a context-free model for the inference network, in particular, a neural CRF parser (Durrett and Klein, 2015). This choice can seen as a form of posterior regularization that limits posterior flexibility of the overly powerful RNNG generative model. 6,7 The parameterization of span scores is similar to recent works (Wang and Chang, 2016;Kitaev and Klein, 2018): we add position embeddings to word embeddings and run a bidirectional LSTM over the input representations to obtain the forward The score s ij ∈ R for a constituent spanning x i to x j is given by, Letting B be the binary matrix representation of a tree (B ij = 1 means there is a constituent spanning x i and x j ), the CRF parser defines a distribution over binary trees via the Gibbs distribution, and φ denotes the parameters of the inference network (i.e. the bidirectional LSTM and the MLP).
Calculating Z T (x) requires a summation over an exponentially-sized set B T ⊂ {0, 1} T ×T , the set of all binary trees over a length T sequence. However we can perform the summation in O(T 3 ) using the inside algorithm (Baker, 1979), shown in 6 While it has a similar goal, this formulation differs the from posterior regularization as formulated by Ganchev et al. (2010), which constrains the distributional family via linear constraints on posterior expectations. In our case, the conditional independence assumptions in the CRF lead to a curved exponential family where the vector of natural parameters has fewer dimensions than the vector of sufficient statistics of the full exponential family. This curved exponential family is a subset of the marginal polytope of the full exponential family, but it is an intersection of both linear and nonlinear manifolds, and therefore cannot be characterized through linear constraints over posterior expectations. 7 In preliminary experiments, we also attempted to learn latent trees with a transition-based parser (which does not make explicit independence assumptions) that looks at the entire sentence. However we found that under this setup, the inference network degenerated into a local minimum whereby it always generated left-branching trees despite various optimization strategies. Williams et al. (2018) observe a similar phenomenon in the context of learning latent trees for classification tasks. However Li et al. (2019) find that it is possible use a transition-based parser as the inference network for dependency grammar induction, if the inference network is constrained via posterior regularization (Ganchev et al., 2010) based on universal syntactic rules (Naseem et al., 2010).
Algorithm 1 Inside algorithm for calculating ZT (x) 1: procedure INSIDE(s) scores sij for i ≤ j 2: for i := 1 to T do length-1 spans 3: β[i, i] = sii 4: for := 1 to T − 1 do span length 5: for i := 1 to T − do span start 6: Algorithm 1. This computation is itself differentiable and amenable to gradient-based optimization. Finally, letting f : B T → Z T be the bijection between the binary tree matrix representation and a sequence of SHIFT/REDUCE actions, the inference network defines a distribution over

Optimization
For optimization, we use the following variant of the ELBO, is the entropy of the variational posterior. A Monte Carlo estimate for the gradient with respect to θ is . Sampling uses the intermediate values calculated during the inside algorithm to sample split points recursively (Goodman, 1998;Finkel et al., 2006), as shown in Algorithm 2. The gradient with respect to φ involves two parts. The entropy term H[q φ (z | x)] can be calculated exactly in O(T 3 ), again using the intermediate values from the inside algorithm (see Algorithm 3). 8 Since each step of this dynamic program is differentiable, we can obtain the gradient ∇ φ H[q φ (z | x)] using automatic differentation. 9 An estimator for the gra- is obtained via the score function gradient estimator (Glynn, 1987;Williams, 1992), Algorithm 2 Top-down sampling a tree from q φ (z | x) queue of constituents 4: while Q is not empty do 5: for k := i to j − 1 do get distribution over splits 8: sample a split point 10: if k > i then if left child has width > 1 12: push(Q, (i, k)) add to queue 13: if k + 1 < j then if right child has width > 1 14: push(Q, (k + 1, j)) add to queue 15: z = f (B) f : BT → ZT maps matrix representation of tree to sequence of actions. 16: return z The above estimator is unbiased but typically suffers from high variance. To reduce variance, we use a control variate derived from an average of the other samples' joint likelihoods (Mnih and Rezende, 2016), yielding the following estimator, ). This control variate worked better than alternatives such as estimates of baselines from an auxiliary network (Mnih and Gregor, 2014;Deng et al., 2018) or a language model (Yin et al., 2018).

Data
For English we use the Penn Treebank (Marcus et al., 1993, PTB) with splits and preprocessing from Dyer et al. (2016) which retains punctuation and replaces singleton words with Berkeley parser's mapping rules, resulting in a vocabulary of 23,815 word types. 10 Notably this is much larger than the standard PTB LM setup from Mikolov et al. (2010) which uses 10K types. 11 Also different from the LM setup, we model each sentence separately instead of carrying information across sentence boundaries, as the RNNG is a generative model of sentences. Hence our perplexity numbers are not comparable to the PTB LM results (Melis et al., 2018;Merity et al., 2018;.
Since the PTB is rather small, and since the URNNG does not require annotation, we also test our approach on a subset of the one billion word for l := 1 to T − 1 do span length 5: for i := 1 to T − l do span start 6: j = i + l span end 7: corpus (Chelba et al., 2013). We randomly sample 1M sentences for training and 2K sentences for validation/test, and limit the vocabulary to 30K word types. While still a subset of the full corpus (which has 30M sentences), this dataset is two orders of magnitude larger than PTB. Experiments on Chinese utilize version 5.1 of the Chinese Penn Treebank (CTB) (Xue et al., 2005), with the same splits as in Chen and Manning (2014). Singleton words are replaced with a single UNK token, resulting in a vocabulary of 17,489 word types.

Training and Hyperparameters
The stack LSTM has two layers with input/hidden size equal to 650 and dropout of 0.5. The tree LSTM also has 650 units. The inference network uses a one-layer bidirectional LSTM with 256 hidden units, and the MLP (to produce span scores s ij for i ≤ j) has a single hidden layer with a ReLU nonlinearity followed by layer normalization (Ba et al., 2016) and dropout of 0.5. We share word embeddings between the generative model and the inference network, and also tie weights between the input/output word embeddings (Press and Wolf, 2016). Optimization of the model itself required standard techniques for avoiding posterior collapse in VAEs. 12 We warm-up the ELBO objective by linearly annealing (per batch) the weight on the conditional prior log p θ (z | x <z ) and the entropy H[q φ (z | x)] from 0 to 1 over the first two epochs (see equation (1) for definition of log p θ (z | x <z )). This is analogous to KL-annealing in VAEs with continuous latent variables (Bowman et al., 2016;Sønderby et al., 2016). We train for 18 epochs (enough for convergence for all models) with a batch size of 16 and K = 8 samples for the Monte Carlo gradient estimators. The generative model is optimized with SGD with learning rate equal to 1, except for the affine layer that produces a distribution over the actions, which has learning rate 0.1. Gradients of the generative model are clipped at 5. The inference network is optimized with Adam (Kingma and Ba, 2015) with learning rate 0.0001, β 1 = 0.9, β 2 = 0.999, and gradient clipping at 1. As Adam converges significantly faster than SGD (even with a much lower learning rate), we stop training the inference network after the first two epochs. Initial model parameters are sampled from U[−0.1, 0.1]. The learning rate starts decaying by a factor of 2 each epoch after the first epoch at which validation performance does not improve, but this learning rate decay is not triggered for the first eight epochs to ensure adequate training. We use the same hyperparameters/training setup for both PTB and CTB. For experiments on (the subset of) the one billion word corpus, we use a smaller dropout rate of 0.1. The baseline RNNLM also uses the smaller dropout rate.
All models are trained with an end-of-sentence token, but for perplexity calculation these tokens are not counted to be comparable to prior work (Dyer et al., 2016;Kuncoro et al., 2017;Buys and Blunsom, 2018). To be more precise, the inference network does not make use of the end-of-sentence token to produce parse trees, but the generative model is trained to generate the end-of-sentence token after the final REDUCE operation.

Baselines
We compare the unsupervised RNNG (URNNG) against several baselines: (1) RNNLM, a standard RNN language model whose size is the same as URNNG's stack LSTM; (2) Parsing Reading Predict Network (PRPN) (Shen et al., 2018), a neural language model that uses gated attention layers to embed soft tree-like structures into a neural network (and among the current state-of-the-art in grammar induction from words on the full corpus); (3) RNNG with trivial trees (left branching, right branching, random); (4) supervised RNNG trained on unlabeled, binarized gold trees. 13 Note that the supervised RNNG also trains a discriminative parser q φ (z | x) (alongside the generative model p θ (x, z)) in order to sample parse forests for perplexity evaluation (i.e. importance sampling). This discriminative parser has the same ar- 13 We use right branching binarization- Matsuzaki et al. (2005) find that differences between various binarization schemes have marginal impact. Our supervised RNNG therefore differs the original RNNG, which trains on nonbinarized trees and does not ignore constituent labels.  Table 1 shows perplexity for the different models on PTB/CTB. As a language model URNNG outperforms an RNNLM and is competitive with the supervised RNNG. 14 The left branching baseline performs poorly, implying that the strong performance of URNNG/RNNG is not simply due to the additional depth afforded by the tree LSTM composition function (a left branching tree, which always performs REDUCE when possible, is the "deepest" model). The right branching baseline is essentially equivalent to an RNNLM and hence performs similarly. We found PRPN with default hyperparameters (which obtains a perplexity of 62.0 in the PTB setup from Mikolov et al. (2010)) to not perform well, but tuning hyperparameters improves performance. 15 The supervised RNNG performs well as a language model, despite being trained on the joint (rather than marginal) likelihood objective. 16 This indicates that explicit 14 For RNNG and URNNG we estimate the log marginal likelihood (and hence, perplexity) with K = 1000 importance-weighted samples, log p θ (x) ≈ . During evaluation only, we also flatten q φ (z | x) by dividing span scores sij by a temperature term 2.0 before feeding it to the CRF. 15 Using the code from https://github.com/yikangshen/ PRPN, we tuned model size, initialization, dropout, learning rate, and use of batch normalization. 16 RNNG is trained to maximize log p θ (x, z) while URNNG is trained to maximize (a lower bound on) the language modeling objective log p θ (x). modeling of syntax helps generalization even with richly-parameterized neural models. Encouraged by these observations, we also experiment with a hybrid approach where we train a supervised RNNG first and continue fine-tuning the model (including the inference network) on the URNNG objective (RNNG → URNNG in Table 1). 17 This approach results in nontrivial perplexity improvements, and suggests that it is potentially possible to improve language models with supervision on parsed data. In Figure 2 we show perplexity by sentence length. We find that a standard language model (RNNLM) is better at modeling short sentences, but underperforms models that explicitly take into account structure (RNNG/URNNG) when the sentence length is greater than 10. Table 2 (top) compares our results against prior work on this version of the PTB, and Table 2 (bottom) shows the results on a 1M sentence subset of the one billion word corpus, which is two orders of magnitude larger than PTB. On this larger dataset URNNG still improves upon the RNNLM. We also trained an RNNG (and RNNG → URNNG) on this dataset by parsing the training set with the self-attentive parser from Kitaev and Klein (2018). 18 These models improve upon the RNNLM but not the URNNG, potentially highlighting the limitations of using predicted trees for supervising RNNGs.

Grammar Induction
Table 1 also shows the F 1 scores for grammar induction. Note that we induce latent trees directly from words on the full dataset. 19 For 17 We fine-tune for 10 epochs and use a smaller learning rate of 0.1 for the generative model. 18 To parse the training set we use the benepar en2 model from https://github.com/nikitakit/self-attentive-parser, which obtains an F1 score of 95.17 on the PTB test set. 19 Past work on grammar induction usually train/evaluate on short sentences and also assume access to gold POS tags (Klein and Manning, 2002;Smith and Eisner, 2004;Bod, 2006). However more recent works do train directly words (Jin et al., 2018;Shen et al., 2018;Drozdov et al., 2019).
RNNG/URNNG we obtain the highest scoring tree from q φ (z | x) through the Viterbi inside (i.e. CKY) algorithm. 20 We calculate unlabeled F 1 using evalb, which ignores punctuation and discards trivial spans (width-one and sentence spans). 21 Since we compare F 1 against the original, non-binarized trees (per convention), F 1 scores of models using oracle binarized trees constitute the upper bounds. We confirm the replication study of Htut et al. (2018) and find that PRPN is a strong model for grammar induction. URNNG performs on par with PRPN on English but PRPN does better on Chinese; both outperform right branching base-20 Alternatively, we could estimate arg maxz p θ (z | x) by sampling parse trees from q φ (z | x) and using p θ (x, z) to rerank the output, as in Dyer et al. (2016). 21 Available at https://nlp.cs.nyu.edu/evalb/. We evaluate with COLLINS.prm parameter file and LABELED option equal to 0. We observe that the setup for grammar induction varies widely across different papers: lexicalized vs. unlexicalized; use of punctuation vs. not; separation of train/test sets; counting sentence-level spans for evaluation vs. ignoring them; use of additional data; length cutoff for training/evaluation; corpus-level F1 vs. sentence-level F1; and, more. In our survey of twenty or so papers, almost no two papers were identical in their setup. Such variation makes it difficult to meaningfully compare models across papers. Hence, we report grammar induction results mainly for the models and baselines considered in the present work.   lines. Table 3 further analyzes the learned trees and shows the F 1 score of URNNG trees against other trees (left), and the recall of URNNG/PRPN trees against ground truth constituents (right). We find that trees induced by URNNG and PRPN are quite different; URNNG is more sensitive to SBAR and VP, while PRPN is better at identifying NP. While left as future work, this naturally suggests a hybrid approach wherein the intersection of constituents from URNNG and PRPN is used to create a corpus of partially annotated trees, which can be used to guide another model, e.g. via posterior regularization (Ganchev et al., 2010) or semisupervision (Hwa, 1999). Finally, Table 4 compares our results using the same evaluation setup as in Drozdov et al. (2019), which differs considerably from our setup. Table 5 shows some standard metrics related to the learned generative model/inference network. The "reconstruction" perplexity based on

Distributional Metrics
is much lower than regular perplexity, and further, the Kullback-Leibler divergence between the conditional prior and the variational posterior, given by  Recon. PPL is the reconstruction perplexity based on , and KL is the Kullback-Leibler divergence. Prior entropy is the entropy of the conditional prior p θ (z | x<z), and uniform entropy is the entropy of the uniform distribution over all binary trees. The KL/entropy metrics are averaged across sentences.
is highly nonzero. (See equation (1) for definitions of log p θ (x | z) and log p θ (z | x <z )). This indicates that the latent space is being used in a meaningful way and that there is no posterior collapse (Bowman et al., 2016). As expected, the entropy of the variational posterior is much lower than the entropy of the conditional prior, but there is still some uncertainty in the posterior.

Syntactic Evaluation
We perform a syntactic evaluation of the different models based on the setup from Marvin and Linzen (2018): the model is given two minimally different sentences, one grammatical and one ungrammatical, and must identify the grammatical sentence by assigning it higher probability. 22 Table 6 shows the accuracy results. Overall the supervised RNNG significantly outperforms the other models, indicating opportunities for further work in unsupervised modeling. While the URNNG does slightly outperform an RNNLM, the distribution of errors made from both models are similar, and thus it is not clear whether the outperformance is simply due to better perplexity or learning different structural biases.

Limitations
There are several limitations to our approach. For one, the URNNG takes considerably more time/memory to train than a standard language model due to the O(T 3 ) dynamic program in the inference network, multiple samples to obtain low-variance gradient estimators, and dynamic  Table 6: Syntactic evaluation based on the setup from Marvin and Linzen (2018). Subj. is subject-verb agreement in sentential complement, across prepositional phrase/subjective relative clause, and VP coordination; Obj. Rel. refers to subject-verb agreement in/across an objective relative clause; Refl. refers to reflexive pronoun agreement with antecedent; NPI is negative polarity items. computation graphs that make efficient batching nontrivial. 23 The model is sensitive to hyperparameters and required various optimization strategies (e.g. separate optimizers for the inference network and the generative model) to avoid posterior collapse. Finally, the URNNG also seemed to learn to rely heavily on punctuation to identify constituents and we were unable to improve upon a right-branching baseline when training the URNNG on a version of PTB where punctuation is removed. 24 In contrast, recent works still perform well on corpus where punctuation is removed (Shen et al., 2018(Shen et al., , 2019Drozdov et al., 2019).

Related Work
There has been much work on incorporating tree structures into deep models for syntax-aware language modeling, both for unconditional (Emami and Jelinek, 2005;Buys and Blunsom, 2015;Dyer et al., 2016) and conditional (Yin and Neubig, 2017;Alvarez-Melis and Jaakkola, 2017;Rabinovich et al., 2017;Aharoni and Goldberg, 2017;Eriguchi et al., 2017;Wang et al., 2018;Gu et al., 2018) cases. These approaches generally rely on annotated parse trees during training and maximizes the joint likelihood of sentence-tree pairs. Prior work on combining language modeling and unsupervised tree learning typically embed soft, tree-like structures as hidden layers of a deep net- 23 The main time bottleneck is the dynamic compution graph, since the dynamic programming algorithm can be batched (however the latter is a significant memory bottleneck). We manually batch the SHIFT and REDUCE operation as much as possible, though recent work on auto-batching  could potentially make this easier/faster. 24 Many prior works that induce trees directly from words often employ additional heuristics based on punctuation (Seginer, 2007;Ponvert et al., 2011;Spitkovsky et al., 2013;Parikh et al., 2014), as punctuation (e.g. comma) is usually a reliable signal for start/end of constituent spans. In contrast the URNNG still has to learn to rely on punctuation. We also reiterate that punctuation is used during training but ignored during evaluation (except in Table 4), as with the prior works mentioned above. work (Cho et al., 2014;Chung et al., 2017;Shen et al., 2018Shen et al., , 2019. In contrast, Buys and Blunsom (2018) make Markov assumptions and perform exact marginalization over latent dependency trees. Our work is also related to the recent line of work on learning latent trees as part of a deep model through supervision on other tasks, typically via differentiable structured hidden layers (Kim et al., 2017;Bradbury and Socher, 2017;Tran and Bisk, 2018;Peng et al., 2018;Niculae et al., 2018;, policy gradient-based approaches (Yogatama et al., 2017;Williams et al., 2018;Havrylov et al., 2019), or differentiable relaxations (Choi et al., 2018;Maillard and Clark, 2018).

Conclusion
It is an open question as to whether explicit modeling of syntax significantly helps neural models. Strubell et al. (2018) find that supervising intermediate attention layers with syntactic heads improves semantic role labeling, while Shi et al. (2018) observe that for text classification, syntactic trees only have marginal impact. Our work suggests that at least for language modeling, incorporating syntax either via explicit supervision or as latent variables does provide useful inductive biases and improves performance. Finally, in modeling child language acquisition, the complex interaction of the parser and the grammatical knowledge being acquired is the object of much investigation (Trueswell and Gleitman, 2007); our work shows that apparently grammatical constraints can emerge from the interaction of a constrained parser and a more general grammar learner, which is an intriguing but underexplored hypothesis for explaining human linguistic biases.