Jonathan May Information Sciences Institute University of Southern California jonmay@isi.edu Kevin Knight Information Sciences Institute University of Southern California knight@isi.edu Abstract We investigate the computational complexity of various problems for simple recurrent neural networks (RNNs) as formal models for recognizing weighted languages. We focus on the single-layer, ReLU-activation, rational-weight RNNs with softmax, which are commonly used in natural language processing applications. We show that most problems for such RNNs are undecidable, including consistency, equivalence, minimization, and the determination of the highest-weighted string. However, for consistent RNNs the last problem becomes decidable, although the solution length can surpass all computable bounds. If additionally the string is limited to polynomial length, the problem becomes NP-complete. In summary, this shows that approximations and heuristic algorithms are necessary in practical applications of those RNNs. Recurrent neural networks (RNNs) are an attractive apparatus for probabilistic language modeling (Mikolov and Zweig, 2012). Recent experiments show that RNNs significantly outperform other methods in assigning high probability to held-out English text (Jozefowicz et al., 2016). Roughly speaking, an RNN works as follows. At each time step, it consumes one input token, updates its hidden state vector, and predicts the next token by generating a probability distribution over all permissible tokens. The probability of an input string is simply obtained as the product of the predictions of the tokens constituting the string followed by a terminating token. In this manner, each RNN defines a weighted language ; i.e. a total function from strings to weights. Siegelmann and Sontag (1995) showed that single-layer rational-weight RNNs with saturated linear activation can compute any computable function. To this end, a specific architecture with 886 hidden units can simulate any Turing machine in real-time (i.e., each Turing machine step is simulated in a single time step). However, their RNN encodes the whole input in its internal state, performs the actual computation of the Turing machine when reading the terminating token, and then encodes the output (provided an output is produced) in a particular hidden unit. In this way, their RNN allows thinking time (equivalent to the computation time of the Turing machine) after the input has been encoded. We consider a different variant of RNNs that is commonly used in natural language processing applications. It uses ReLU activations, consumes an input token at each time step, and produces softmax predictions for the next token. It thus immediately halts after reading the last input token and the weight assigned to the input is simply the product of the input token predictions in each step. Other formal models that are currently used to implement probabilistic language models such as finite-state automata and context-free grammars are by now well-understood. A fair share of their utility directly derives from their nice algorithmic properties. For example, the weighted languages computed by weighted finite-state automata are closed under intersection (pointwise product) and union (pointwise sum), and the corresponding unweighted languages are closed under intersection, union, difference, and complementation (Droste et al., 2013). Moreover, toolkits like OpenFST (Allauzen et al., 2007) and Carmel 1 implement efficient algorithms on automata like minimization, intersection, finding the highest-weighted path and the highest-weighted string. based machine translation system should extract the highest-weighted output string (i.e., the most likely translation) generated by an RNN, (Sutskever et al., 2014; Bahdanau et al., 2014). Currently this task is solved by approximation techniques like heuristic greedy and beam searches. To facilitate the deployment of large RNNs onto limited memory devices (like mobile phones) minimization techniques would be bene-ficial. Again currently only heuristic approaches like knowledge distillation (Kim and Rush, 2016) are available. Meanwhile, it is unclear whether we can determine if the computed weighted language is consistent; i.e., if it is a probability distribution on the set of all strings. Without a determination of the overall probability mass assigned to all finite strings, a fair comparison of language models with regard to perplexity is simply impossible. The goal of this paper is to study the above problems for the mentioned ReLU-variant of RNNs. More specifically, we ask and answer the following questions:  Consistency: Do RNNs compute consistent weighted languages? Is the consistency of the computed weighted language decidable? Highest-weighted string: Can we (efficiently) determine the highest-weighted string in a computed weighted language? Equivalence: Can we decide whether two given RNNs compute the same weighted language? Minimization: Can we minimize the number of neurons for a given RNN? Before we introduce our RNN model formally, we recall some basic notions and notation. An alphabet  is a finite set of symbols, and we write |  | for the number of symbols in  . A string s over the alphabet  is a finite sequence of zero or more symbols drawn from  , and we write   for the set of all strings over  , of which (cid:15) is the empty string. The length of the string s    is denoted | s | and coincides with the number of symbols constituting the string. As usual, we write AB for the set of functions { f | f : B  A } . A weighted language L is a total function L :    R from strings to real-valued weights. For example, L ( a n ) = e  n for all n  0 is such a weighted language. We restrict the weights in our RNNs to the rational numbers Q . In addition, we reserve the use of a special symbol $ to mark the start and end of an input string. To this end, we assume that $ /   for all considered alphabets, and we let  $ =  { $ } . Definition 1. A single-layer RNNR is a 7 -tuple h  , N, h  1 , W, W 0 , E, E 0 i , in which   is an input alphabet ,  N is a finite set of neurons ,  h  1  QN is an initial activation vector ,  W  QN  N is a transition matrix ,  W 0 = ( W 0 a ) a   $ is a  $ -indexed family of bias vectors W 0 a  QN ,  E  Q  $  N is a prediction matrix , and  E 0  Q  $ is a prediction bias vector . Next, let us define how such an RNN works. We first prepare our input encoding and the effect of our activation function. For an input string s = s 1 s 2    s n    with s 1 , . . . , s n   , we encode this input as $ s $ and thus assume that s 0 = $ and s n +1 = $ . Our RNNs use ReLUs (Rectified Linear Units), so for every v  QN we let  h v i (the ReLU activation) be the vector  h v i  QN such that  h v i ( n ) = max (cid:0) 0 , v ( n ) (cid:1) for every n  N . In other words, the ReLUs act like identities on nonnegative inputs, but clip negative inputs to 0 . We use softmax-predictions, so for every vector p  Q  $ and a   $ we let softmax h p i ( a ) = e p ( a ) P a 0   $ e p ( a 0 ) . RNNs act in discrete time steps reading a single letter at each step. We now define the semantics of our RNNs. Definition 2. Let R = h  , N, h  1 , W, W 0 , E, E 0 i be an RNN, s an input string of length n and 0  t  n a time step. We define  the hidden state vector h s,t  QN given by h s,t =  h W  h s,t  1 + W 0 s t i , where h s,  1 = h  1 and we use standard matrix product and point-wise vector addition,  the next-token prediction vector E s,t  Q  $ E s,t = E  h s,t + E 0  the next-token distribution E 0 s,t  R  $ E 0 s,t = softmax h E s,t i . Finally, the RNNR computes the weighted language R :    R , which is given for every input s = s 1    s n as above by In other words, each component h s,t ( n ) of the hidden state vector is the ReLU activation applied to a linear combination of all the components of the previous hidden state vector h s,t  1 together with a summand W 0 s t that depends on the t -th input letter s t . Thus, we often specify h s,t ( n ) as linear combination instead of specifying the matrix W and the vectors W 0 a . The semantics is then obtained by predicting the letters s 1 , . . . , s n of the input s and the final terminator $ and multiplying the probabilities of the individual predictions. Let us illustrate these notions on an example. We consider the RNN h  , N, h  1 , W, W 0 , E, E 0 i with   Q and   = { a } and N = { 1 , 2 } ,  h  1 = (  1 , 0) T and W = (cid:18) 1 0 1 0 (cid:19) and W 0 $ = W 0 a = (cid:18) 1 0 (cid:19)  E ($ ,  ) = ( M + 1 ,  ( M + 1)) and E ( a,  ) = (1 ,  1) and  E 0 ($) =  M and E 0 ( a ) = 0 . In this case, we obtain the linear combinations h s,t =  * h s,t  1 (1) + 1 h s,t  1 (1) + computing the next hidden state components. Given the initial activation, we thus obtain h s,t =  h t, t  1 i . Using this information, we obtain E s,t ($) = ( M + 1)  ( t   h t  1 i )  M E s,t ( a ) = t   h t  1 i . Consequently, we assign weight e  M 1+ e  M to input  , weight 1 1+ e  M  e 1 e 1 + e 1 to a , and, more generally, weight 1 1+ e  M  12 n to a n . Clearly the weight assigned by an RNN is always in the interval (0 , 1) , which enables a probabilistic view. Similar to weighted finite-state automata or weighted context-free grammars, each RNN is a compact, finite representation of a weighted language. The softmax-operation enforces that the probability 0 is impossible as assigned weight, so each input string is principally possible. In practical language modeling, smoothing methods are used to change distributions such that impossibility (probability 0 ) is removed. Our RNNs avoid impossibility outright, so this can be considered a feature instead of a disadvantage. The hidden state h s,t of an RNN can be used as scratch space for computation. For example, with a single neuron n we can count symbols in s via: h s,t ( n ) =  h h s,t  1 ( n ) + 1 i . Here the letter-dependent summand W 0 a is universally 1 . Similarly, for an alphabet  = { a 1 , . . . , a m } we can use the method of Siegelmann and Sontag (1995) to encode the complete input string s in base m + 1 using: h s,t ( n ) =  h ( m + 1) h s,t  1 ( n ) + c ( s t ) i , where c :  $  { 0 , . . . , m } is a bijection. In principle, we can thus store the entire input string (of unbounded length) in the hidden state value h s,t ( n ) , but our RNN model outputs weights at each step and terminates immediately once the final delimiter $ is read. It must assign a probability to a string incrementally using the chain rule decomposition p ( s 1    s n ) = p ( s 1 )  . . .  p ( s n | s 1    s n  1 ) . Let us illustrate our notion of RNNs on some additional examples. They all use the alphabet  = { a } and are illustrated and formally specified in Figure 1. The first column shows an RNN R 1 that assigns R 1 ( a n ) = 2  ( n +1) . The next-token prediction matrix ensures equal values for a and $ at every time step. The second column shows the RNNR 2 , which we already discussed. In the beginning, it heavily biases the next symbol prediction towards a , but counters it starting at t = 1 . The third RNN R 3 uses another counting mechanism with h s,t =  h t  100 , t  101 , t i . The first two components are ReLU-thresholded to zero until t > 101 , at which point they overwhelm the bias towards a turning all future predictions to $ . We first investigate the consistency problem for an RNN R , which asks whether the recognized weighted language R is indeed a probability distribution. Consequently, an RNN R is consistent 2263 R 1 ( a n ) = 2  ( n +1) R 2 (  )  0 R 3 ( a 100 )  1 R 2 ( a n )  2  n ( n  1) R 3 ( a n )  0 ( n 6 = 100) N { 1 } { 1 , 2 } { 1 , 2 , 3 } h  1 (cid:0) 0 (cid:1) (cid:18)  1 0 (cid:19)   0 0 0   W (cid:0) 0 (cid:1) (cid:18) 1 0 1 0 (cid:19)   0 0 1 0 0 1 0 0 1   W 0 $ W 0 a (cid:0) 0 (cid:1) (cid:0) 0 (cid:1) (cid:18) 1 0 (cid:19) (cid:18) 1 0 (cid:19)    99  100 1      99  100 1   E $ E a (cid:0) 0 (cid:1) (cid:0) 0 (cid:1) (cid:18) M + 1  ( M + 1) (cid:19) (cid:18) 1  1 (cid:19)   M  M 0      M M 0   E 0 $ E 0 a 0 0  M 0  M 0 Figure 1: Sample RNNs over single-letter alphabets, and the weighted languages they recognize. if P s    R ( s ) = 1 . We first show that there is an inconsistent RNN, which together with our examples shows that consistency is a nontrivial property of RNNs. 2 We immediately use a slightly more complex example, which we will later reuse. Example 3. Let us consider an arbitrary RNNR = h  , N, h  1 , W, W 0 , E, E 0 i with the single-letter alphabet  = { a } , the neurons { 1 , 2 , 3 , n, n 0 }  N , initial activation h  1 ( i ) = 0 for all i  { 1 , 2 , 3 , n, n 0 } , and the following linear combinations: h s,t (1) =  h h s,t  1 (1) + h s,t  1 ( n )  h s,t  1 ( n 0 ) i 2 For comparison, all probabilistic finite-state automata are consistent, provided no transitions exit final states. Not all probabilistic context-free grammars are consistent; necessary and sufficient conditions for consistency are given by Booth and Thompson (1973). However, probabilistic context-free grammars obtained by training on a finite corpus using popular methods (such as expectation-maximization) are guaranteed to be consistent (Nederhof and Satta, 2006). h s,t (2) =  h h s,t  1 (2) + 1 i h s,t (3) =  h h s,t  1 (3) + 3 h s,t  1 (1) i E s,t ($) = h s,t (3)  h s,t (2) E s,t ( a ) = h s,t (2) Now we distinguish two cases: Case 1: If h s,t ( n )  h s,t ( n 0 ) = 0 for all t  N , then h s,t (1) = 0 and h s,t (2) = t + 1 and h s,t (3) = 0 . Hence we have E s,t ($) =  ( t + 1) and E s,t ( a ) = t + 1 . In this case the termination probability E 0 s,t ($) = e  ( t +1) e  ( t +1) + e t +1 = 1 1 + e 2( t +1) (i.e., the likelihood of predicting $ ) shrinks rapidly towards 0 , so the RNN assigns less than 15% of the probability mass to the terminating sequences (i.e., the finite strings), so the RNN is inconsistent (see Lemma 15 in the appendix). Case 2: Suppose that there exists a time 2264 point T  N such that for all t  N h s,t ( n )  h s,t ( n 0 ) = ( 1 if t = T 0 otherwise. Then h s,t (1) = 0 for all t  T and h s,t (1) = 1 otherwise. In addition, we have h s,t (2) = t + 1 and h s,t (3) =  h 3( t  T  1) i . Hence we have E s,t ($) =  h 3( t  T  1) i  ( t + 1) = (  ( t + 1) if t  T 2 t  3 T  4 otherwise E s,t ( a ) = t + 1 , which shows that the probability E 0 s,t ($) =   1 1+ e 2( t +1) if t  T e t  3 T  5 1+ e t  3 T  5 otherwise of predicting $ increases over time and eventually (for t (cid:29) 3 T ) far outweighs the probability of predicting a . Consequently, in this case the RNN is consistent (see Lemma 16 in the appendix). We have seen in the previous example that consistency is not trivial for RNNs, which takes us to the consistency problem for RNNs: Consistency: Given an RNN R , return yes if R is consistent and no otherwise. We recall the following theorem, which, combined with our example, will prove that consistency is unfortunately undecidable for RNNs. with saturated linear activation, input alphabet  = { a } , and 1 designated neuron n  N such that for all s    and 0  t  | s |  h s,t ( n ) = 0 if M does not halt on  , and  if M does halt on empty input after T steps, then h s,t ( n ) = 1 if t = T In other words, such RNNs with saturated linear activation can semi-decide halting of an arbitrary Turing machine in the sense that a particular neuron achieves value 1 at some point during the evolution if and only if the Turing machine halts on empty input. An RNN with saturated linear activation is an RNN following our definition with the only difference that instead of our ReLU-activation  the following saturated linear activation  0 : QN  QN is used. For every vector v  QN and n  N , let  0 h v i ( n ) =   0 if v ( n ) < 0 v ( n ) if 0  v ( n )  1 1 if v ( n ) > 1 . Since  0 h v i =  h v i   h v  ~ 1 i for all v  QN , and the right-hand side is a linear transformation, we can easily simulate saturated linear activation in our RNNs. To this end, each neuron n  N of the original RNN R = h  , N, h  1 , U, U 0 , E, E 0 i is replaced by two neurons n 1 and n 2 in the new RNN R 0 = h  , N 0 , h 0  1 , V, V 0 , F, F 0 i such that h s,t ( n ) = h 0 s,t ( n 1 )  h 0 s,t ( n 2 ) for all s    and 0  t  | s | , where the evaluation of h 0 s,t is performed in the RNN R 0 . More precisely, we use the transition matrix V and bias function V 0 , which is given by V ( n 1 , n 0 1 ) = V ( n 2 , n 0 1 ) = U ( n, n 0 ) V ( n 1 , n 0 2 ) = V ( n 2 , n 0 2 ) =  U ( n, n 0 ) V 0 a ( n 1 ) = U 0 a ( n ) V 0 a ( n 2 ) = U 0 a ( n )  1 h 0 1 ( n 1 ) = h  1 ( n ) h 0 1 ( n 2 ) = 0 for all n, n 0  N and a    { $ } , where n 1 and n 2 are the two neurons corresponding to n and n 0 1 and n 0 2 are the two neurons corresponding to n 0 (see Lemma 17 in the appendix). Corollary 5. Let M be an arbitrary deterministic Turing machine. There exists an RNN R = h  , N, h  1 , W, W 0 , E, E 0 i with input alphabet  = { a } and 2 designated neurons n 1 , n 2  N such that for all s    and 0  t  | s |  h s,t ( n 1 )  h s,t ( n 2 ) = 0 if M does not halt on  , and  if M does halt on empty input after T steps, then h s,t ( n 1 )  h s,t ( n 2 ) = ( 1 if t = T 0 otherwise. We can now use this corollary together with the RNN R of Example 3 to show that the consistency problem is undecidable. To this end, we simulate a given Turing machine M and identify the two designated neurons of Corollary 5 as n and n 0 in Example 3. It follows that M halts if and only if R is consistent. Hence we reduced the undecidable halting problem to the consistency problem, which shows the undecidability of the consistency problem. Theorem 6. The consistency problem for RNNs is undecidable. As mentioned in Footnote 2, probabilistic context-free grammars obtained after training on a finite corpus using the most popular methods are guaranteed to be consistent. At least for 2-layer RNNs this does not hold. Theorem 7. A two-layer RNN trained to a local optimum using Back-propagation-through-time (BPTT) on a finite corpus is not necessarily consistent. Proof. The first layer of the RNN R with a single alphabet symbol a uses one neuron n 0 and has the following behavior: h  1 ( n 0 ) = 0 h s,t ( n 0 ) =  h h s,t  1 ( n 0 ) + 1 i The second layer uses neuron n and takes h s,t ( n 0 ) as input at time t : h s,t ( n ) =  h h s,t ( n 0 )  2 i E s,t ( a ) = h s,t ( n ) E s,t ($) = 0 E 0 s,t ( a ) = ( 12 if t  1 e ( t  1) 1+ e ( t  1) otherwise. Let the training data be { a } . Then the objective we wish to maximize is simply R ( a ) . The derivative of this objective with respect to each parameter is 0 , so applying gradient descent updates does not change any of the parameters and we have converged to an inconsistent RNN. model or the most likely translation for a decoder RNN in machine translation. For deterministic probabilistic finite-state automata or context-free grammars only one path or derivation exists for any given string, so the identification of the highest-weighted string is the same task as the identification of the most probable path or derivation. However, for nondeterministic devices, the highest-weighted string is often harder to identify, since the weight of a string is the sum of the probabilities of all possible paths or derivations for that string. A comparison of the difficulty of identifying the most probable derivation and the highest-weighted string for various models is summarized in Table 1, in which we marked our results in bold face. We present various results concerning the difficulty of identifying the highest-weighted string in a weighted language computed by an RNN. We also summarize some available algorithms. We start with the formal presentation of the three studied problems. 1. Best string: Given an RNNR and c  (0 , 1) , does there exist s    with R ( s ) > c ? 2. Consistent best string: Given a consistent RNN R and c  (0 , 1) , does there exist s    with R ( s ) > c ? 3. Consistent best string of polynomial length: Given a consistent RNN R , polynomial P with P ( x )  x for x  N + , and c  (0 , 1) , does there exist s    with | s |  P ( | R | ) and R ( s ) > c ? As usual the corresponding optimization problems are not significantly simpler than these decision problems. Unfortunately, the general problem is also undecidable, which can easily be shown using our example. Theorem 8. The best string problem for RNNs is undecidable. Proof. Let M be an arbitrary Turing machine and again consider the RNN R of Example 3 with the neurons n and n 0 identified with the designated neurons of Corollary 5. We note that R (  ) = 1 1+ e 2 < 0 . 12 in both cases. If M does not halt, then R ( a n )  1 1+ e 2( n +1)  1 1+ e 2 < 0 . 12 for all n  N . On the other hand, if M halts after T steps, then R ( a 3 T  5 ) = (cid:16) TY t =0 e 2( t +1) 1 + e 2( t +1) (cid:17)  (cid:16) 3 T  6 Y t = T +1 1 1 + e t  3 T  5 (cid:17)  1 2  2 (  1 , e  2 )   (cid:16) 3 T  6 Y t = T +1 e 3 T +5  t e 3 T +5  t +1 (cid:17)  1 2  2 (  1 , e  2 )   (  1 , e  1 )   0 . using Lemma 14 in the appendix. Consequently, a string with weight above 0 . 12 exists if and only if M halts, so the best string problem is also undecidable. If we restrict the RNNs to be consistent, then we can easily decide the best string problem by simple enumeration. Theorem 9. The consistent best string problem for RNNs is decidable. Proof. Let R be the RNN over alphabet  and c  (0 , 1) be the bound. Since   is countable, we can enumerate it via f : N    . In the algorithm we compute S n = P ni =0 R ( f ( i )) for increasing values of n . If we encounter a weight R ( f ( n )) > c , then we stop with answer yes. Otherwise we continue until S n > 1  c , at which point we stop with answer no. Since R is consistent, lim i  S i = 1 , so this algorithm is guaranteed to terminate and it obviously decides the problem. Next, we investigate the length | w max R | of the shortest string w max R of maximal weight in the weighted language R generated by a consistent RNN R in terms of its (binary storage) size | R | . As already mentioned by Siegelmann and Sontag (1995) and evidenced here, only small precision rational numbers are needed in our constructions, so we assume that | R |  c  | N | 2 for a (reasonably small) constant c , where N is the set of neurons of R . We show that no computable bound on the length of the best string can exist, so its length can surpass all reasonable bounds. Theorem 10. Let f : N +  N be the function with f ( n ) = max consistent RNN R | R | n | w max R | for all n  N + . Proof. In the previous section (before Theorem 6) we presented an RNN RM that simulates an arbitrary (single-track) Turing machine M with n states. By Siegelmann and Sontag (1995) we have | RM |  c  (4 n + 16) . Moreover, we observed that this RNN RM is consistent if and only if the Turing machine M halts on empty input. In the proof of Theorem 8 we have additionally seen that the length | w max R | of its best string exceeds the number TM of steps required to halt. For every n  N , let BB ( n ) be the n -th Busy Beaver number (Rado, 1962), which is BB ( n ) = max normalized n -state Turing machine M with 2 tape symbols that halts on empty input TM It is well-known that BB : N +  N cannot be bounded by any computable function. However, BB ( n )  max normalized n -state Turing machine M with and 2 tape symbols that halts on empty input | w max RM |  max consistent RNN R | R | c  (4 n +16) | w max R | = f (4 nc + 16 c ) , so f clearly cannot be computable and no computable function g can provide bounds for f . Finally, we investigate the difficulty of the best string problem for consistent RNN restricted to solutions of polynomial length. Theorem 11. Identifying the best string of polynomial length in a consistent RNN is NP-complete. be a formula in conjunctive normal form, where  ij  { x 1 , . . . , x m ,  x 1 , . . . ,  x m } . 3-SAT asks whether there is a setting of x i s that makes F true. We initialize h  1 ( n ) = 0 ,  n  N = { x 1 , . . . , x m , c 1 , . . . , c k , c 0 1 , . . . , c 0 k , F, n 1 , n 2 , n 3 , ? } . Let s  { 0 , 1 }  be the input string. Denote the value of F when x j = s j for all j  [ m ] as F ( s ) . Let t  N with t  | s | . Set h s,t ( x m ) =  h I ( s t ) i , where I (0) = I ($) = 0 and I (1) = 1 . This stores the current input symbol in neuron x m , so h s,t ( x m ) = I ( s t ) . In addition, we let h s,t ( x j ) =  h h s,t  1 ( x j +1 ) i for all j  [ m  1] . Consequently, for all j  [ m ] h s,t ( x j ) = ( I ( s t  ( m  j ) ) if m  j  t 0 otherwise. Next, we evaluate the clauses. For each i  [ k ] , we use two neurons c i and c 0 i such that h s,t ( c i ) =  h f s,t (  i 1 ) + f s,t (  i 2 ) + f s,t (  i 3 ) i h s,t ( c 0 i ) =  h f s,t (  i 1 ) + f s,t (  i 2 ) + f s,t (  i 3 )  1 i , where f s,t ( x m ) = I ( s t ) , f s,t (  x m ) = 1  I ( s t ) , and  j  [ m  1] , f s,t ( x j ) = h s,t  1 ( x j +1 ) , f s,t (  x j ) = 1  h s,t  1 ( x j +1 ) . Note that h s,t ( c i )  h s,t ( c 0 i ) contains the evaluation of the clause  i 1   i 2   i 3 . Let h s,t ( F ) =  D k X i =1 (cid:16) h s,t  1 ( c i )  h s,t  1 ( c 0 i ) (cid:17)  k +1 E , so h s,t ( F ) = F ( s ) contains the evaluation of the formula F using the values in neurons x 1 , . . . , x m . We use three counters n 1 , n 2 , n 3 to ensure that the only relevant inputs are of length m + 2 : h s,t ( n 1 ) =  h h s,t  1 ( n 3 )  ( m + 2) i h s,t ( n 2 ) =  h h s,t  1 ( n 3 )  ( m + 1) i h s,t ( n 3 ) =  h h s,t  1 ( n 3 ) + 1 i , which yields h s,t ( n 3 ) = t + 1 , h s,t ( n 2 ) =  h t  ( m + 1) i , and h s,t ( n 1 ) =  h t  ( m + 2) i . Our goal neuron is ? , which we set to h s,t ( ? ) =  h h s,t  1 ( F )  h s,t  1 ( n 1 )+ h s,t  1 ( n 2 )  1 i so that h s,t ( ? ) = ( h s,t  1 ( F ) if t = m + 2 0 otherwise, so h s,t ( ? ) = 1 if and only if t = m + 2 and F ( s ) = 1 . Let m 0 = m + 4 . The output is set as follows: E s,t (0) = E s,t (1) = m 0 (cid:0) 1  2 h s,t ( ? ) (cid:1) E s,t ($) =  m 0 (cid:0) 1  2 h s,t ( ? ) (cid:1) , This yields E s,t (0) = E s,t (1) =  E s,t ($) =  m 0 if t = m +2 and F ( s ) = 1 , and m 0 otherwise. For a  { 0 , 1 } , E 0 s,t ( a )=   e  m 0 2 e  m 0 + e m 0 if t = m +2 and F ( s )=1 e m 0 2 e m 0 + e  m 0 otherwise E 0 s,t ($)=   e m 0 2 e  m 0 + e m 0 if t = m +2 and F ( s )=1 e  m 0 2 e m 0 + e  m 0 otherwise. Finally, we set the threshold  = 3  m 0 . When | s | 6 = m + 2 , s m +3 6 = $ , so the weight of s contains the factor e  m 0 2 e  m 0 + e m 0 = 1 2+ e 2 m 0 and thus is upper-bounded by 1 2+ e 2 m 0 <  . Hence no input of length different from m + 2 achieves a weight that exceeds  . A string s of length m + 2 achieves the weight w s given by w s =   e m 0 2 e  m 0 + e m 0  Q m +2 i =1 e m 0 2 e m 0 + e  m 0 if F ( s )=1 e  m 0 2 e m 0 + e  m 0  Q m +2 i =1 e m 0 2 e m 0 + e  m 0 otherwise. When F ( s ) = 0 , w s < e  m 0 2 e m 0 + e  m 0 <  , so if F is unsatisfiable, no input string achieves a weight above the threshold  . When F ( s ) = 1 , w s = e m 0 2 e  m 0 + e m 0  (cid:16) e m 0 2 e m 0 + e  m 0 (cid:17) m +2 > . An input string with weight above  exists if and only if F is satisfiable. Obviously, the reduction can be computed in polynomial time since all constants can be computed in logarithmic space. The constructed RNN is consistent, since the output prediction is constant after m + 3 steps. We prove that equivalence of two RNNs is undecidable. For comparison, equivalence of two deterministic WFSAs can be tested in time O ( |  | ( | QA | + | QB | ) 3 ) , where | QA | , | QB | are the number of states of the two WFSAs and |  | is the size of the alphabet (Cortes et al., 2007); equivalence of nondeterministic WFSAs are undecidable (Griffiths, 1968). The decidability of language equivalence for deterministic probabilistic push-downtown automata (PPDA) is still open (Forejt et al., 2014), although equivalence for deterministic unweighted push-downtown automata (PDA) is decidable (Senizergues, 1997). The equivalence problem is formulated as follows: Theorem 12. The equivalence problem for RNNs is undecidable. Proof. We prove by contradiction. Suppose Turing machine M decides the equivalence problem. Given any deterministic Turing Machine M 0 , construct the RNN R that simulates M 0 on input (cid:15) as described in Corollary 5. Let E s,t ( a ) = 0 and E s,t ($) = h s,t ( n 1 )  h s,t ( n 2 ) . If M 0 does not halt on (cid:15) , for all t  N , E 0 s,t ( a ) = E 0 s,t ($) = 1 / 2 ; if M 0 halts after T steps, E 0 s,T ( a ) = 1 / ( e + 1) , E s,T ($) = e/ ( e + 1) . Let R 0 be the trivial RNN that computes { a n : P ( a n ) = 2  ( n +1) , n  0 } . We run M on input h R, R 0 i . If M returns no, M 0 halts on x , else it does not halt. Therefore the Halting Problem would be decidable if equivalence is decidable. Therefore equivalence is undecidable. We look next at minimization of RNNs. For comparison, state-minimization of a deterministic PFSA is O ( | E | log | Q | ) where | E | is the number of transitions and | Q | is the number of states (Aho et al., 1974). Minimization of a non-deterministic PFSA is PSPACE-complete (Jiang and Raviku-mar, 1993). We focus on minimizing the number of hidden neurons ( | N | ) in RNNs: Minimization: Given RNNR and non-negative integer n , return yes if  RNN R 0 with number of hidden units | N 0 |  n such that R ( s ) = R 0 ( s ) for all s    , and no otherwise. Theorem 13. RNN minimization is undecidable. Proof. We reduce from the Halting Problem. Suppose Turing Machine M decides the minimization problem. For any Turing Machine M 0 , construct the same RNN R as in Theorem 12. We run M on input h R, 0 i . Note that an RNN with no hidden unit can only output constant E 0 s,t for all t . Therefore the number of hidden units in R can be minimized to 0 if and only if it always outputs E 0 s,t ( a ) = E 0 s,t ($) = 1 / 2 . If M returns yes, M 0 does not halt on (cid:15) , else it halts. We proved the following hardness results regarding RNN as a recognizer of weighted languages: 1. Consistency: (a) Inconsistent RNNs exist. (b) Consistency of RNNs is undecidable. 2. Highest-weighted string: (a) Finding the highest-weighted string for an arbitrary RNN is undecidable. (b) Finding the highest-weighted string for a consistent RNN is decidable, but the solution length can surpass all computable bounds. (c) Restricting to solutions of polynomial length, finding the highest-weighted string is NP-complete. 3. Testing equivalence of RNNs and minimizing the number of neurons in an RNN are both undecidable. Although our undecidability results are upshots of the Turing-completeness of RNN (Siegelmann and Sontag, 1995), our NP-completeness result is original, and surprising, since the analogous hardness results in PFSA relies on the fact that there are multiple derivations for a single string (Casacu-berta and de la Higuera, 2000). The fact that these results hold for the relatively simple RNNs we used in this paper suggests that the case would be the same for more complicated models used in NLP, such as long short term memory networks (LSTMs; Hochreiter and Schmidhuber 1997). Our results show the non-existence of (effi-cient) algorithms for interesting problems that researchers using RNN in natural language processing tasks may have hoped to find. On the other hand, the non-existence of such efficient or exact algorithms gives evidence for the necessity of approximation, greedy or heuristic algorithms to solve those problems in practice. In particular, since finding the highest-weighted string in RNN is the same as finding the most-likely translation in a sequence-to-sequence RNN decoder, our NP-completeness result provides some justification for employing greedy and beam search algorithms in practice. This work was supported by DARPA (W911NF-15-1-0543 and HR0011-15-C-0115). Andreas Maletti was financially supported by DFG Graduiertenkolleg 1763 (QuantLA).
abstain abstain abstain objective method result abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain method abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain method abstain objective method objective method abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain method other method objective method method abstain method abstain method abstain method abstain abstain abstain abstain abstain method abstain abstain abstain abstain abstain abstain abstain abstain method abstain abstain abstain method abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain other abstain abstain method method abstain abstain other abstain other abstain abstain abstain other abstain abstain method abstain abstain method abstain method other other abstain abstain other abstain method abstain abstain abstain abstain abstain abstain other abstain abstain abstain abstain abstain abstain abstain abstain abstain method abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain other abstain abstain abstain abstain abstain abstain abstain abstain method abstain abstain abstain abstain method abstain abstain abstain method abstain abstain abstain abstain abstain abstain abstain abstain abstain method abstain abstain abstain abstain abstain abstain abstain abstain method method abstain other method abstain other abstain other other abstain abstain abstain other abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain method abstain abstain abstain method abstain method abstain abstain abstain result abstain abstain abstain abstain abstain abstain abstain abstain result result result abstain result other other