Rational Recurrences

Hao Peng, Roy Schwartz, Sam Thomson, Noah A. Smith

Introduction

Neural models, and in particular gated variants of recurrent neural networks (RNNs, e.g., Hochreiter and Schmidhuber, 1997; Cho et al., 2014), have become a core building block for state-of-the-art approaches in NLP Goldberg (2016). While these models empirically outperform classical NLP methods on many tasks (Zaremba et al., 2014; Bahdanau et al., 2015; Dyer et al., 2016; Peng et al., 2017, inter alia), they typically lack the intuition offered by classical models, making it hard to understand the roles played by each of their components. In this work we show that many neural models are more interpretable than previously thought, by drawing connections to weighted finite state automata (WFSAs). We study several recently proposed RNN architectures and show that one can use WFSAs to characterize their recurrent updates. We call such models rational recurrences (§3). Where the term regular is used with unweighted FSAs (e.g., regular languages, regular expressions), rational is the weighted analog (e.g., rational series, Sakarovitch, 2009; rational kernels, Cortes et al., 2004). Analyzing recurrences in terms of WFSAs provides a new view of existing models and facilitates the development of new ones.

In recent work, Schwartz et al. (2018) introduced SoPa, an RNN constructed from WFSAs, and thus rational by our definition. They also showed that a single-layer max-pooled CNN LeCun (1998) can be simulated by a set of simple WFSAs (one per output dimension), and accordingly are also rational. In this paper we broaden such efforts, and show that rational recurrences are in frequent use (Mikolov et al., 2014; Balduzzi and Ghifary, 2016; Lei et al., 2016, 2017a, 2017b; Bradbury et al., 2017; Foerster et al., 2017). For instance, we will show in §4 that the WFSA diagrammed in Figure 1 has strong connections to several of the models mentioned above.

Based on these observations, we then discuss potential approaches to deriving novel neural architectures from WFSAs (§5). As a case study, we present a new model motivated by the interpolation of a two-state WFSA and a three-state one, capturing (soft) unigram and bigram features, respectively. Our experiments show that in two tasks—language modeling and text classification—the proposed model outperforms recently proposed rational models (§6). Further extensions might lead to larger gains, and the rational recurrence view could facilitate easier exploration of such extensions. To promote such exploration, we publicly release our implementation at https://github.com/Noahs-ARK/rational-recurrences.

Background: Weighted Finite State Automata (WFSAs)

This section reviews weighted finite-state automata and semirings, which underly our analyses in §3. WFSAs extend nondeterministic unweighted finite-state automata by assigning weights to transitions, start states, and final states. Instead of simply accepting or rejecting a string, a WFSA returns a score for the string, and this score summarizes the weights along all paths through the WFSA that consume the string. In order for this summary score to be efficiently computable, weights are taken from a semiring.

ε∉Σ\varepsilon\notin\Sigma marks special ε\varepsilon/̄transitions that may be taken without consuming any input. A\mathscr{A} assigns a score A⟦x⟧\mathscr{A}\llbracket\mathbf{x}\rrbracket to a string x=x1…xn∈Σ∗\mathbf{x}=x_{1}\ldots x_{n}\in\Sigma^{\ast} by summing over the scores of all possible paths deriving x\mathbf{x}. The score of each individual path is the product of the weights of the transitions it consists of. Formally:

Let π=π1…πn\bm{\pi}=\pi_{1}\ldots\pi_{n} be a sequence of adjacent transitions in A\mathscr{A}, with each transition πi=(qi,qi+1,zi)∈Q×Q×(Σ∪{ε})\pi_{i}=(q_{i},q_{i+1},z_{i})\in\mathcal{Q}\times\mathcal{Q}\times\left(\Sigma\cup\{\varepsilon\}\right). The path π\bm{\pi} derives string x∈Σ∗\mathbf{x}\in\Sigma^{*}, which is the substring of z=z1z2…zn\mathbf{z}=z_{1}z_{2}\dots z_{n} that excludes ε\varepsilon symbols (for example, if z=aεbcεεεd\mathbf{z}=a\varepsilon bc\varepsilon\varepsilon\varepsilon d, then x=abcd\mathbf{x}=abcd). π\bm{\pi}’s score in A\mathscr{A} is given by

Let Π(x)\Pi(\mathbf{x}) denote the set of all paths in A\mathscr{A} that derive x\mathbf{x}. Then the score assigned by A\mathscr{A} to x\mathbf{x} is defined to be

Ωi(q)\Omega_{i}(q) gives the total score of all paths that derive x1…xix_{1}\ldots x_{i} and end in state qq.

Figure 1 diagrams a WFSA B\mathscr{B}, consisting of two states. A path starts from the initial state q0q_{0} (with λ(q0)=1ˉ\lambda(q_{0})=\bar{1}); it then takes any number of “self-loop” transitions, each consuming an input without changing the path score (since it’s weighted by 1ˉ\bar{1}); it then consumes an input symbol α\alpha and takes a transition weighted by μ(α)\mu(\alpha), and reaches the final state q1q_{1} (with ρ(q1)=1ˉ\rho(q_{1})=\bar{1}); it may further consume more input by taking self-loops at q1q_{1}, updating the path score by multiplying it by ϕ(α)\phi(\alpha) for each symbol α\alpha. Then from Definition 4, we can calculate that B\mathscr{B} gives the empty string score 0ˉ\bar{0}, and gives any nonempty string x=x1…xn∈Σ+\mathbf{x}=x_{1}\dots x_{n}\in\Sigma^{+} score B⟦x⟧=\mathscr{B}\llbracket\mathbf{x}\rrbracket=

B\mathscr{B} can be seen as capturing soft unigram patterns (Davidov et al., 2010), in the sense that it consumes one input symbol to reach the final state from the initial state. It is straightforward to design WFSAs capturing longer patterns by including more states (Schwartz et al., 2018), as we will discuss later in §4 and §5.

Rational Recurrences

Before formally defining rational recurrences in §3.2, we highlight the connection between WFSAs and RNNs using a motivating example (§3.1).

We describe a simplified RNN which strips away details of some recent RNNs, in order to highlight the behaviors of the forget gate and the input.

For an input sequence x=x1…xn\mathbf{x}=x_{1}\dots x_{n}, let the word embedding vector for xtx_{t} be vt\mathbf{v}_{t}. As in many gated RNN variants (Hochreiter and Schmidhuber, 1997; Cho et al., 2014), we use a forget gate ft\mathbf{f}_{t}, which is computed with an affine transformation followed by an elementwise sigmoid function σ\bm{\sigma}. The current input representation ut\mathbf{u}_{t} is similarly computed, but with an optional nonlinearity (e.g., tanh⁡\tanh) g\bm{g}. The hidden state ct\mathbf{c}_{t} can be seen as a weighted sum of the previous state and the new input, controlled by the forget gate.

The hidden state ct\mathbf{c}_{t} can then be used in downstream computation, e.g., to calculate output state ht=tanh⁡(ct)\mathbf{h}_{t}=\tanh(\mathbf{c}_{t}), which is then fed to an MLP classifier. We focus only on the recurrent computation.

In Example 6, both ft\mathbf{f}_{t} and ut\mathbf{u}_{t} depend only on the current input token xtx_{t} (through vt\mathbf{v}_{t}), and not the previous state. Importantly, the interaction with the previous state ct−1\mathbf{c}_{t-1} is not via affine transformations followed by nonlinearities, as in, e.g., an Elman network (Elman, 1990), where ct=tanh⁡(Wcct−1+Wvvt+bc)\mathbf{c}_{t}=\tanh(\mathbf{W}_{c}\mathbf{c}_{t-1}+\mathbf{W}_{v}\mathbf{v}_{t}+\mathbf{b}_{c}). As we will discuss later, this is important in relating this recurrent update function to WFSAs.

Since the recurrent update in Equation 5c is elementwise, for simplicity we focus on just the iith dimension. Unrolling it in time steps, we get

where [⋅]i[\cdot]_{i} denotes the iith dimension of a vector. As noted by Lee et al. (2017), the hidden state at time step tt can be seen as a sum of previous input representations, weighted by the forget gate; longer histories typically get a smaller weight, since the forget gate values are between 0 and 1 due to the sigmoid function.

Denote the resulting WFSA by Bi\mathscr{B}_{i}, and we have:

Running a single layer RNN in Example 6 over any nonempty input string x∈Σ+\mathbf{x}\in\Sigma^{+}, the iith dimension of its hidden state at time step tt equals the score assigned by Bi\mathscr{B}_{i} to x:t\mathbf{x}_{:t}:

In other words, the iith dimension of the RNN in Example 6 can be seen as a WFSA structurally equivalent to B\mathscr{B}. Its weight functions are implemented as the iith dimension of Equations 5, and the learned parameters are the iith row of W\mathbf{W} and b\mathbf{b}. Then it is straightforward to recover the full dd-dimensional RNN, by collecting dd such WFSAs, each of which is parametrized by a row in the W\mathbf{W}s and b\mathbf{b}s. Based on this observation, we are now ready to formally define rational recurrences.

2 Recurrences and Rationality

It directly follows from Proposition 7 that

Relationship to Existing Neural Models

This section studies several recently proposed neural architectures, and relates them to rational recurrences. §4.1 begins by relating some of them to the RNN defined in Example 6, and then to the WFSA B\mathscr{B} (Example 5). We then describe a WFSA similar to B\mathscr{B}, but with one additional state, and discuss how it provides a new view of RNN models motivated by nn-gram features (§4.2). In §4.3 we study rational recurrences that are not elementwise, using an existing model.

In the following discussion, we shall assume the real seimiring, unless otherwise noted.

Despite its simplicity, Example 6 corresponds to several existing neural architectures. For instance, quasi-RNN (QRNN; Bradbury et al., 2017) and simple recurrent unit (SRU; Lei et al., 2017b) aim to speed up the recurrent computation. To do so, they drop the matrix multiplication dependence on the previous hidden state, resulting in similar recurrences to that in Example 6.The SRU architecture discussed through this work is based on Lei et al. (2017b). In a later updated version, Lei et al. (2018) introduce diagonal matrix multiplication interaction in the hidden state updates, inspired by (Li et al., 2018), which yields a recurrence not obviously rational. Other works start from different motivations, but land on similar recurrences, e.g., strongly-typed RNNs (T-RNN; Balduzzi and Ghifary, 2016) and its gated variants (T-LSTM and T-GRU), and structurally constrained RNNs (SCRN; Mikolov et al., 2014).

The analysis in §3.1 directly applies to SRU, T-RNN, and SCRN. In fact, Example 6 presents a slightly more complicated version of them. In these models, input representations are computed without the bias term or any nonlinearity: ut=Wuvt\mathbf{u}_{t}=\mathbf{W}_{u}\mathbf{v}_{t}. By Proposition 7 and Corollary 9:

The recurrences of single-layer SRU, T-RNN, and SCRN architectures are rational.

It is slightly more complicated to analyze the recurrences of the QRNN, T-LSTM, and T-GRU. Although their hidden states ct\mathbf{c}_{t} are updated in the same way as Equation 5c, the input representations and gates may depend on previous inputs. For example, in T-LSTM and T-GRU, the forget gate is a function of two consecutive inputs:

QRNNs are similar, but may depend on up to KK tokens, due to the KK-window convolutions. Eisner (2002) discuss finite state machines for second (or higher) order probabilistic sequence models. Following the same intuition, we sketch the construction of WFSAs corresponding to QRNNs with 2-window convolutions in Appendix A, and summarize the key results here:

The recurrences of single-layer T-GRU, T-LSTM, and QRNN are rational. In particular, a single-layer dd-dimensional QRNN using KK-window convolutions can be recovered by a set of dd WFSAs, each with O(2 ∣Σ∣K−1)O(2\,\lvert\Sigma\rvert^{K-1}) states.

The size of WFSAs needed to recover QRNN grows exponentially in the window size. Therefore, at least for QRNNs, Proposition 11 has more conceptual value than practical.

2 More than Two States

So far our discussion has centered on B\mathscr{B}, a two-state WFSA capturing unigram patterns (Example 5). In the same spirit as going from unigram to nn-gram features, one can use WFSAs with more states to capture longer patterns (Schwartz et al., 2018). In this section we augment B\mathscr{B} by introducing more states, and explore its relationship to some neural architectures motivated by nn-gram features. We start with a three-state WFSA as an example, and then discuss more general cases.

Figure 2 diagrams a WFSA C\mathscr{C}, augmenting B\mathscr{B} with another state. To reach the final state q2q_{2}, at least two transitions must be taken, in contrast to one in B\mathscr{B}. History information is decayed by the self-loop at the final state q2q_{2}, assuming ϕ2\phi_{2} is between 0 and 1. C\mathscr{C} has another self-loop over q1q_{1}, weighted by ϕ1∈(0,1)\phi_{1}\in(0,1). The motivation is to allow (but down-weight) nonconsecutive bigrams, as we will soon show.

The scores assigned by C\mathscr{C} can be inductively computed by applying the Forward algorithm (§2). Given input sequence x\mathbf{x} longer than one, let C⟦x:0⟧=0\mathscr{C}\llbracket\mathbf{x}_{:0}\rrbracket=0, then C⟦x:t+1⟧=\mathscr{C}\llbracket\mathbf{x}_{:t+1}\rrbracket=

and β0=0\beta_{0}=0. Unrolling βt\beta_{t} in time, we get βt=\beta_{t}=

Due to the self-loop over state q1q_{1}, βt\beta_{t} can be seen as a weighted sum of the μ1\mu_{1} terms up to xtx_{t} (Equaltion 14). The second product term in Equation 12 then provides multiplicative interactions between μ2\mu_{2}, and the weighted sum of μ1\mu_{1}s. In this sense, it captures nonconsecutive bigram features.

At a first glance, Equations 12 and 13 resemble recurrent convolutional neural networks (RCNN; Lei et al., 2016). RCNN is inspired by nonconsecutive nn-gram features and low rank tensor factorization. It is later studied from a string kernel perspective (Lei et al., 2017a). Here we review its nonlinear bigram version:

where the ut(j)\mathbf{u}_{t}^{(j)}s are computed similarly to Equation 5b, and ct(2)\mathbf{c}_{t}^{(2)} is used as output for onward computation. Different strategies to computing λt\bm{\lambda}_{t} were explored (Lei et al., 2015, 2016). When λt\bm{\lambda}_{t} is a constant, or depends only on xtx_{t}, e.g., λt=σ(Wλvt+bλ)\bm{\lambda}_{t}=\bm{\sigma}(\mathbf{W}_{\lambda}\mathbf{v}_{t}+\mathbf{b}_{\lambda}), the iith dimension of Equations 15 can be recovered from Equation 12, by letting

It is straightforward to generalize the above discussion to higher order cases: nn-gram RCNN corresponds to WFSAs with n+1n+1 states, constructed similarly to how we build C\mathscr{C} from B\mathscr{B} (Appendix B).

For a single-layer RCNN with λt\bm{\lambda}_{t} being a constant or depending only on xtx_{t}, the recurrence is rational.

As noted later in §4.3, its recurrence may not be rational when λt=σ(Wcct−1+Wλvt+bλ)\bm{\lambda}_{t}=\bm{\sigma}(\mathbf{W}_{c}\mathbf{c}_{t-1}+\mathbf{W}_{\lambda}\mathbf{v}_{t}+\mathbf{b}_{\lambda}).

3 Beyond Elementwise Operations

So far we have discussed rational recurrences for models using elementwise recurrent updates (e.g., Equation 5c). This section uses an existing model as an example, to study a rational recurrence that is not elementwise. We focus on the input switched affine network (ISAN; Foerster et al., 2017). Aiming for efficiency and interpretability, it does not use any explicit nonlinearity; its affine transformation parameters depend only on the input:

Due to the matrix multiplication, the recurrence of a single-layer ISAN is not elementwise. Yet, we argue that it is rational. We will sketch the proof for a 2-dimensional case, and it is straightforward to generalize to higher dimensions (Appendix C).

We define two WFSAs, each recovering one dimension of ISAN’s recurrent updates. Figure 3 diagrams one of them, D1\mathscr{D}_{1}. The other one, D2\mathscr{D}_{2}, is identical (including shared weights), except using q3q_{3} instead of q2q_{2} as the final state. For any nonempty input sequence x∈Σ+\mathbf{x}\in\Sigma^{+}, the scores assigned by D1\mathscr{D}_{1} and D2\mathscr{D}_{2} can be inductively computed by applying the Forward algorithm. Letting D1⟦x:0⟧=D2⟦x:0⟧=0\mathscr{D}_{1}\llbracket\mathbf{x}_{:0}\rrbracket=\mathscr{D}_{2}\llbracket\mathbf{x}_{:0}\rrbracket=0, for t≥1t\geq 1

Then Equation 17, in the case of hidden size 2, is recovered by letting Wxt=W~xt\mathbf{W}_{x_{t}}=\widetilde{\mathbf{W}}_{x_{t}} and bxt=b~xt\mathbf{b}_{x_{t}}=\widetilde{\mathbf{b}}_{x_{t}}.

The recurrence of a single-layer ISAN is rational.

For a single-layer Elman network, in the absence of any nonlinearity, the recurrence is rational.

It is known that an Elman network can approximate any recursively computable partial function (Siegelmann and Sontag, 1995). On the other hand, in their single-layer cases, WFSAs (and thus models with rational recurrences) are restricted to rational series (Schützenberger, 1961). Therefore, we hypothesize that models like Elman networks, LSTMs, and GRUs, where the recurrences depend on previous states through affine transformations followed by nonlinearities, are not rational.

This work does not intend to propose rational recurrences as a concept general enough to include most existing RNNs. Rather, we wish to study a more constrained class of methods to better understand the connections between WFSAs and RNNs. Therefore in Definition 8, we restrict the semirings to be “simple,” in the sense that both operations take constant time and space. Such a restriction aims to exclude the possibility of hiding arbitrarily complex computations inside the semiring, which might allow RNNs to satisfy the definition in a trivial and unilluminating way.

Such theoretical limitations might be less severe than they appear, since it is not yet entirely clear what they correspond to in practice, especially when multiple vertical layers of these models are used (Leshno and Schocken, 1993). We defer to future work the further study of the connections between WFSAs and Elman-style RNNs.

Closing this section, Table 1 summarizes the discussed recurrent neural architectures and their corresponding WFSAs.

Deriving Neural Models from WFSAs

Rational recurrences provide a new view of several recently proposed neural models. Based on such observations, this section aims to explore potential approaches to designing neural architectures in a more interpretable and intuitive way: by deriving them from WFSAs. §5.1 studies an interpolation of unigram and bigram features by combining 2-state and 3-state WFSAs (Figures 1 and 2). We then explore alternative semirings (§5.2), an approach orthogonal to what we’ve discussed so far.

We note that our goal is not to devise new state-of-the-art architectures. Rather, we illustrate a new design process for neural architectures that draws inspiration from WFSAs. That said, in our experiments (§6), one of our new architectures performs as well as or better than strong baselines.

We start by presenting a straightforward extension to 2-state and 3-state rational models: one combining both. It is inspired by many classical NLP models, where unigram features and higher-order ones are interpolated.

Figure 4 diagrams a 4-state WFSA F\mathscr{F}. Compared to C\mathscr{C} (Figure 2), F\mathscr{F} uses q1q_{1} as a second final state, aiming to capture both unigram and bigram patterns, since a path is allowed to stop at q1q_{1} after consuming one input. The final states are weighted by ρ1\rho_{1} and ρ2\rho_{2} respectively. Another notable modification is the additional state q3q_{3}, which is used to create a “shortcut” to reach q2q_{2}, together with an ε\varepsilon-transition. Specifically, starting from q0q_{0}, a path can now take the ε\varepsilon-transition and reach q3q_{3}, and then take a transition with weight μ2\mu_{2} to reach q2q_{2}. Recall from §2, that ε\varepsilon-transitions do not consume any input, yet they can still be weighted by a (parameterized) function γ\gamma not depending on the inputs. The ε\varepsilon-transition allows for skipping the first word in a bigram. It can be discouraged by using γ∈(0,1)\gamma\in(0,1), just as we do in our experiments.

As in §3, we relate hidden states of an RNN to the scores assigned by WFSAs to input strings. We then derive the neural architecture with a dynamic program. Here we keep the discussion self-contained by explicitly overviewing the procedure. It is a direct application of the Forward algorithm (§2), though now in a form that deals with the ε\varepsilon-transition. Such an approach applies, of course, to more general cases, as noted by Schwartz et al. (2018).

Given an input string x∈Σ+\mathbf{x}\in\Sigma^{+}, let zt(j)z^{(j)}_{t} denote the total score of all paths landing in state qjq_{j} just after consuming xtx_{t}. Let z0(j)=0z^{(j)}_{0}=0, then for t≥1t\geq 1,

We now collect dd of these WFSAs to construct an RNN, and we parameterize their weight functions with the technique we’ve been using:

The p\mathbf{p} vectors correspond to the final state weights ρ1\rho_{1} and ρ2\rho_{2}. Despite the similarities, p\mathbf{p} are different from output gates (Bradbury et al., 2017), since the former do not depend on the input, and are parameterized (through a sigmoid) by two leanred vectors bp(j)\mathbf{b}_{p}^{(j)}. The same applies to r\mathbf{r} and br\mathbf{b}_{r}, which correspond to the weights for ε\varepsilon-transitions γ\gamma.

2 Alternative Semirings

Example 15 does not use the forget gate when computing ut\mathbf{u}_{t} (Equation 22b), which is different from its plus-times counterpart, where \mathbf{u}_{t}=(\mathbf{1}-\mathbf{f}_{t})\odot\bm{g}\bigl{(}\mathbf{W}_{u}\mathbf{v}_{t}+\mathbf{b}_{u}\bigr{)}. The reason is that, unlike the real semiring, the max-plus semiring lacks a well-defined negation. Possible alternatives include taking the log⁡\log of a separate input gate, or using log⁡(1−ft)\log(\mathbf{1}-\mathbf{f}_{t}), which we leave for future work.

Example 15 can be seen as replacing sum-pooling with max-pooling. Both max and sum-pooling have been used successfully in vision and NLP models. Intuitively, max-pooling “detects” the occurrence of a pattern while sum-pooling “counts” the occurrence of a pattern. One advantage of max operator is that the model’s decisions can be back-traced and interpreted, as argued by Schwartz et al. (2018). Such a technique is applicable to all the models with rational recurrences.

Experiments

This section evaluates four rational RNNs on language modeling (§6.2) and text categorization (§6.3). Our goal is to compare the behaviors of models derived from different WFSAs, showing that our understanding of WFSAs allows us to improve existing rational models.

Our comparisons focus on the recurrences of the models, i.e., how the hidden states ct\mathbf{c}_{t} are computed (e.g., Equations 5c and 20c). Therefore we follow Lei et al. (2017b) and use ut(j)=Wu(j)vt(j)\mathbf{u}_{t}^{(j)}=\mathbf{W}_{u}^{(j)}\mathbf{v}_{t}^{(j)} across all compared models, listed below and as well as in Table 2:

rrnn(B\mathscr{B}), with real semiring (§4.1);

rrnn(B\mathscr{B})m+{}_{\text{m+}}, with max-plus semiring (§5.2);

rrnn(C\mathscr{C}), with real semiring (§4.2);

rrnn(F\mathscr{F}), with real semiring (§5.1).

We also compare to an LSTM baseline. Aiming to control for comfounding factors, we do not use highway connections in any of the models.Thus rrnn(B\mathscr{B}) is essentially an SRU without highway connections. We denote it differently, to note its differences from the original implementation Lei et al. (2017b). Similarly, we do not denote rrnn(C\mathscr{C}) as RCNN (Lei et al., 2016). In the interest of space, the full architectures and hyperparameters are detailed in Appendices D and E.

2 Language Modeling

We experiment with the Penn Treebank corpus (PTB; Marcus et al., 1993). We use the preprocessing and splits from Mikolov et al. (2010), resulting in a vocabulary size of 10K and 1M tokens.

Following standard practice, we treat the training data as one long sequence, split into mini batches, and train using BPTT truncated to 35 time steps (Williams and Peng, 1990). The input embeddings and output softmax weights are tied (Press and Wolf, 2017).

Results.

Following Collins et al. (2017) and Melis et al. (2018), we compare models controlling for parameter budget. Table 3 summarizes language modeling perplexities on PTB test set. The middle block compares all models with two layers and 10M trainable parameters. rrnn(B\mathscr{B}) and rrnn(C\mathscr{C}) achieve roughly the same performance; interpolating both unigram and bigram features, rrnn(F\mathscr{F}) outperforms others by more than 2.9 test perplexity. For the three-layer and 24M setting (the bottom block), we observe similar trends, except that rrnn(C\mathscr{C}) slightly underperforms rrnn(B\mathscr{B}). Here rrnn(F\mathscr{F}) outperforms others by more than 2.1 perplexity.

Using a max-plus semiring, rrnn(B\mathscr{B})m+{}_{\text{m+}} underperforms rrnn(B\mathscr{B}) under both settings. Possible reasons could be the suboptimal design choice for computing input representations in the former (§5.2). Finally, most compared models outperform the LSTM baselines, whose numbers are taken from Lei et al. (2017b).Melis et al. (2018) point out that carefully tuning LSTMs can achieve much stronger performance, at the cost of exceptionally large amounts of computational resources for tuning.

3 Text Classification

We use unidirectional 2-layer architectures for all compared models. To build the classifiers, we feed the final RNN hidden states into a 2-layer tanh⁡\tanh-MLP. Further implementation details are described in Appendix E.

Datasets.

We experiment with four binary text classification datasets, described below.

Amazon (electronic product review corpus; McAuley and Leskovec, 2013).http://riejohnson.com/cnn_data.html We focus on the positive and negative reviews.

SST (Stanford sentiment treebank; Socher et al., 2013).nlp.stanford.edu/sentiment/index.html We focus on the binary classification task. SST provides labels for syntactic phrases; we experiment with a more realistic setup, and consider only complete sentences at either training or evaluating time.

subj (Subjectivity dataset; Pang and Lee, 2004). As subj doesn’t come with official splits, we randomly split it to train (80%), development (10%), and test (10%) sets.

CR (customer reviews dataset; Hu and Liu, 2004).http://www.cs.uic.edu/?liub/FBS/sentiment-analysis.html As with subj, we randomly split this dataset using the same ratio.

Table 4 summarizes the sizes of the datasets.

Results.

Table 5 summarizes text classification test accuracy. We report the average performance of 5 trials different only in random seeds. rrnn(F\mathscr{F}) outperforms all other models on 3 out of the 4 datasets. For Amazon, the largest one, we do not observe significant differences between rrnn(F\mathscr{F}) and rrnn(C\mathscr{C}), while both outperform others. This may suggest that the interpolation of unigram and bigram features by rrnn(F\mathscr{F}) is especially useful in small data setups. As in the language modeling experiments, rrnn(B\mathscr{B})m+{}_{\text{m+}} underperforms all other models in most cases, and in particular rrnn(B\mathscr{B}). These results provide evidence that replacing the real semiring in rational models might be challenging. We leave further exploration to future work.

Related Work

WFSAs were once popular among many sequential tasks (Mohri et al., 2002; Kumar and Byrne, 2003; Cortes et al., 2004; Pardo and Birmingham, 2005; Moore et al., 2006, inter alia), and are still successful in morphology (Dreyer, 2011; Cotterell et al., 2015; Rastogi et al., 2016, inter alia). Compared to neural networks, WFSAs are better understood theoretically and arguably more interpretable. They were recently revisited in combination with the former in, e.g., text generation (Ghazvininejad et al., 2016, 2017; Lin et al., 2017) and automatic music accompaniment (Forsyth, 2016).

Recurrent neural networks.

RNNs (Elman, 1990; Jordan, 1989) prove to be strong models for sequential data (Siegelmann and Sontag, 1995). Besides the perhaps most notable gated variants (Hochreiter and Schmidhuber, 1997; Cho et al., 2014), extensive efforts have been devoted to developing alternatives (Balduzzi and Ghifary, 2016; Miao et al., 2016; Zoph and Le, 2017; Lee et al., 2017; Lei et al., 2017a; Vaswani et al., 2017; Gehring et al., 2017, inter alia). Departing from the above approaches, this work derives RNN architectures drawing inspiration from WFSAs.

Another line of work studied the connections between WFSAs and RNNs in terms of modeling capacity, both empirically (Kolen, 1993; Giles et al., 1992; Weiss et al., 2018, inter alia) and theoretically (Cleeremans et al., 1989; Visser et al., 2001; Chen et al., 2018, inter alia).

Conclusion

We presented rational recurrences, a new construction to study the recurrent updates in RNNs, drawing inspiration from WFSAs. We showed that rational recurrences are in frequent use by several recently proposed recurrent neural architectures, providing new understanding of them. Based on such connections, we discussed approaches to deriving novel neural architectures from WFSAs. Our empirical results demonstrate the potential of doing so. We publicly release our implementation at https://github.com/Noahs-ARK/rational-recurrences.

Acknowledgments

We thank Jason Eisner, Luheng He, Tao Lei, Omer Levy, members of the ARK lab at the University of Washington, and researchers at the Allen Institute for Artificial Intelligence for their helpful comments on an early version of this work, and the anonymous reviewers for their valuable feedback. We also thank members of the Aristo team at the Allen Institute for Artificial Intelligence for their support with the Beaker experimentation system. This work was supported in part by NSF grant IIS-1562364 and by the NVIDIA Corporation through the donation of a Tesla GPU.

References

Appendix A Proof of Proposition 11

Let’s consider a single-layer QRNN with 2-window convolutions:

A similar analysis applies to T-GRUs and T-LSTMs directly, and it should be straightforward to generalize the discussion to QRNNs with larger convolution windows.

Let Σ\Sigma denote the alphabet, and let x=x1x2…xn∈Σ+\mathbf{x}=x_{1}x_{2}\dots x_{n}\in\Sigma^{+} be a nonempty input string. consider a WFSA over the real semiring with 2 ∣Σ∣+12\,\lvert\Sigma\rvert+1 states, where q0q_{0} is the initial state with λ(q0)=1\lambda(q_{0})=1; ∣Σ∣\lvert\Sigma\rvert of them are final states Q2={qα}α∈Σ\mathcal{Q}_{2}=\{q_{\alpha}\}_{\alpha\in\Sigma}, with ρ(qα)=1\rho(q_{\alpha})=1, and the remaining ∣Σ∣\lvert\Sigma\rvert states are denoted by Q1={pα}α∈Σ\mathcal{Q}_{1}=\{p_{\alpha}\}_{\alpha\in\Sigma}.

The transition weights τ\tau are constructed by

τ=0\tau=0 otherwise. Then one dimension of the reccurent updates of a 2-window QRNN is recovered by parameterizing the weight functions as

The recurrent computation of a 2-window QRNN of hidden size dd can then be recovered by collecting dd such WFSAs. ∎

Appendix B Proof of Proposition 12

We present the construction of WFSAs for a single layer nn-gram RCNNs of hidden size dd.

Let’s assume a given input sequence x∈Σ+\mathbf{x}\in\Sigma^{+}, with ∣x∣>n\lvert\mathbf{x}\rvert>n, since otherwise one only needs include paddings, just as in a RCNN. Consider a WFSA with n+1n+1 states Q={qi}i=0n\mathcal{Q}=\{q_{i}\}_{i=0}^{n} over the real semiring. Use q0q_{0} as the initial state with λ(q0)=1\lambda(q_{0})=1, and qnq_{n} as the final state with ρ(qn)=1\rho(q_{n})=1. The transition weight function is defined by

Let zt(j)z^{(j)}_{t} denote the total score of all paths landing in state qjq_{j} just after consuming xtx_{t}. Let zt(j)=0,j=0,…,nz^{(j)}_{t}=0,j=0,\dots,n. By the forward algorithm

Applying similar parametrization to that in §4.2, zt(n)z^{(n)}_{t} recovers one dimension of the recurrence. Collecting dd such WFSAs we recover the recurrence of a single layer nn-gram RCNNs, with λt\bm{\lambda}_{t} being a constant, or depending only on xtx_{t}. ∎

Appendix C Proof of Proposition 13

Closely following the 2-dimensional case in §4.3, let’s discuss a single layer ISAN of hidden size dd.

Consider a WFSA over the real semiring with 2d2d states. Let dd of them, denoted by Q2={qi}i=d+12d\mathcal{Q}_{2}=\{q_{i}\}_{i=d+1}^{2d} be the initial states, with λ(qi)=1,i=1,…,d\lambda(q_{i})=1,i=1,\dots,d. Denote the other half {qi}i=1d\{q_{i}\}_{i=1}^{d} by Q1\mathcal{Q}_{1}. Define transition weight τ\tau by:

Using qi∈Q1q_{i}\in\mathcal{Q}_{1} as the final state with ρ(qi)=1\rho(q_{i})=1, and denote the resulting WFSA by Gi\mathscr{G}_{i}. By Forward algorithm, Gi\mathscr{G}_{i} recovers the iith dimension of the single layer ISAN by letting [Wxt]i,j=μi,j(xt)[\mathbf{W}_{x_{t}}]_{i,j}=\mu_{i,j}(x_{t}), and [bxt]i=ηi(xt)[\mathbf{b}_{x_{t}}]_{i}=\eta_{i}(x_{t}); the dd-dimensional recurrent computation is recovered by a set of WFSAs {Gi}i=1d\{\mathscr{G}_{i}\}_{i=1}^{d} constructed similarly. ∎

Appendix D Compared Models

This section formally describes the models compared in the experiments (§6.1).

rrnn(B\mathscr{B}) is derived from B\mathscr{B} (§4.1).

rrnn(ℬℬ\mathscr{B})m+m+{}_{\text{m+}}.

Also derived from B\mathscr{B}, but uses the max-plus semiring (§5.2).

rrnn(𝒞𝒞\mathscr{C}).

rrnn(C\mathscr{C}) is derived from C\mathscr{C} (§4.2):

rrnn(ℱℱ\mathscr{F}).

The output gates (Equations 25d, 26d, 27e, and 28h) are optional. They are only used in language modeling experiments, where we empirically find that they improve performance.

Appendix E Experimental Setup

Our implementation is based on Lei et al. (2017b)https://github.com/taolei87/sru and Peng et al. (2018),https://github.com/Noahs-ARK/SPIGOT using PyTorch.https://pytorch.org/

E.2 Language Modeling

For hyperparameters, we do not deviate much from the language modeling experiments in Lei et al. (2017b). We change the hidden sizes for all compared models based on the trainable parameter budget, and adjust the dropout probabilities accordingly to keep the number of remaining hidden units is roughly the same in expectation. Besides, we observe that rrnn(C\mathscr{C}) and rrnn(F\mathscr{F}) fail to converge when optimized with the SGD algorithm using 1.0 initial learning rate. And thus we use 0.5 for both models. Other hyperparameters are kept the same as Lei et al. (2017b).

E.3 Text classification

We tune the hyperparameters of our model on the development set by running 20 epochs of random search. We then take the best development configuration, and train five models with it using different random seeds. We report the average test results. The hyperparameters values explored are summarized in Table 6. We train all models for 500 epochs, stopping early if development accuracy does not improve for 30 epochs. During training, we halve the learning rate if development accuracy does not improve for 10 epochs.