On the Linguistic Capacity of Real-time Counter Automata

1 INTRODUCTION . It is often taken for granted that modeling natural language syntax well requires a hierarchically structured grammar formalism . Early work in linguistics established that finite-state models are insufficient for describing the dependencies in natural language data ( Chomsky , 1956 ) . Instead , a formalism capable of expressing the relations in terms of hierarchical constituents ought to be necessary . Recent advances in deep learning and NLP , however , challenge this long-held belief . Neural network formalisms like the long short-term memory network ( LSTM ) ( Hochreiter & Schmidhuber , 1997 ) have been shown to perform well on tasks requiring structure sensitivity ( Linzen et al. , 2016 ) , even though it is not obvious that such models have the capacity to represent hierarchical structure . This mismatch raises interesting questions for both linguists and practitioners of NLP . It is unclear what about the LSTM ’ s structure lends itself towards good linguistic representations , and under what conditions these representations might fall short of grasping the structure and meaning of language . Recent work has suggested that the expressive capacity of LSTMs resembles that of counter machines ( Merrill , 2019 ; Suzgun et al. , 2019 ; Weiss et al. , 2018 ) . Weiss et al . ( 2018 ) studied LSTMs with fully saturated weights ( i.e . the activation functions evaluate to their asymptotic values instead of intermediate rational values ) and showed that such models can express simplified counter languages . Merrill ( 2019 ) , on the other hand , showed that the general counter languages are an upper bound on the expressive capacity of saturated LSTMs . Thus , there seems to be a strong theoretical connection between LSTMs and the counter automata . Merrill ( 2019 ) ; Suzgun et al . ( 2019 ) ; Weiss et al . ( 2018 ) also all report experimental results suggesting that some class of counter languages matches the learnable capacity of LSTMs trained by gradient descent . Taking the counter machine as a simplified formal model of the LSTM , we study the formal properties of counter machines as grammars . We do this with the hope of understanding to what degree counter machines , and LSTMs by extension , have computational properties well-suited for representing the structure of natural language . The contributions of this paper are as follows : • We prove that general counter machines , incremental counter machines , and stateless counter machines have equivalent expressive capacity , whereas simplified counter machines ( Weiss et al. , 2018 ) are strictly weaker than the general class . • We demonstrate that counter languages are closed under complement , union , intersection , and many other common operations . • We show that counter machines are incapable of representing the deep syntactic structure or semantics of boolean expressions , even though they can validate whether a boolean expression is well-formed . • We prove that a certain subclass of the counter languages are semilinear , and conjecture that this result holds for all counter languages . 2 DEFINITIONS . 2.1 GENERAL COUNTER MACHINE . Informally , we can think of counter automata as finite-state automata that have been augmented by a finite number of integer-valued counters . While processing a string , the machine can update the values of the counters , and the counters can in turn inform the machine ’ s state transitions . Early results in theoretical computer science established that a 2-counter machine with unbounded computation time is Turing-complete ( Fischer , 1966 ) . However , restricting computation to be realtime ( i.e . one iteration of computation per input ) severely limits the counter machine ’ s computational capacity ( Fischer et al. , 1968 ) . A similar fact holds for recurrent neural networks like LSTMs ( Weiss et al. , 2018 ) . We study the capabilities of several types of real-time counter automata . The first counter automaton we introduce is the general counter machine . This machine can manipulate the counters by adding or subtracting from them . The other variants that we will go on to define are special cases of this general machine . For m ∈ Z , we write +m to denote the function λx.x + m. By ×0 , we denote the constant zero function λx.0 . Definition 2.1 ( General counter machine ) . A k-counter machine is a tuple 〈Σ , Q , q0 , u , δ , F 〉 with 1 . A finite alphabet Σ 2 . A finite set of states Q 3 . An initial state q0 4 . A counter update function u : Σ×Q× { 0 , 1 } k → ( { +m : m ∈ Z } ∪ { ×0 } ) k 5 . A state transition function δ : Σ×Q× { 0 , 1 } k → Q 6 . An acceptance mask F ⊆ Q× { 0 , 1 } k Given an input string x and a counter machine , we perform computation by processing x one token at a time . For each token , we use u to update the counters and δ to update the state according to the current input token , the current state , and a finite mask of the current counter values . We formalize this in Definition 2.2 . As a preliminary remark on notation , we use z ( x ) to denote the zero check function z ( x ) = { 0 if x = 0 1 otherwise . ( 1 ) Given a vector x , we use z ( x ) to represent this function broadcasted over each element of the vector . Definition 2.2 ( Counter machine computation ) . Let 〈q , c〉 ∈ Q×Zk be a configuration of machine M . Upon reading input xt ∈ Σ , we define the transition 〈q , c〉 →xt 〈δ ( xt , q , z ( c ) ) , u ( xt , q , z ( c ) ) ( c ) 〉 . Definition 2.3 ( Real-time acceptance ) . For any string x ∈ Σ∗ with length n , a counter machine accepts x if there exist states q1 , .. , qn and counter configurations c1 , .. , cn such that 〈q0,0〉 →x1 〈q1 , c1〉 →x2 .. →xn 〈qn , cn〉 ∈ F. Definition 2.4 ( Real-time language acceptance ) . A counter machines accepts a language L if , for each x ∈ Σ∗ , it accepts x if and only if x ∈ L. We denote the set of languages that are acceptable in real time by a general counter machine as CL . We will use the terms “ accept ” and “ decide ” interchangeably , as accepting and deciding a language are equivalent for real-time automata . 2.2 COUNTER MACHINE VARIANTS . Now , we can can consider various restrictions of the general counter machine , and the corresponding classes of languages acceptable by such automata . First , we present the simplified counter machine discussed by Weiss et al . ( 2018 ) . The counter update function in the simplified counter machine has two important constraints compared to the general machine . First , it can only be conditioned by the input symbol at each time step . Second , it can only increment or decrement its counters instead of being able to add or subtract arbitrary constants . Definition 2.5 ( Simplified counter machine ) . A counter machine is simplified if u has the form u : Σ→ { −1 , +0 , +1 , ×0 } k. Another variant that we consider is the incremental counter machine . This machine also is constrained to have only increments and decrements on its counters , but the counter update function is allowed to depend on the state and counter value . Definition 2.6 ( Incremental counter machine ) . An counter machine is incremental if u has the form u : Σ×Q× { 0 , 1 } k → { −1 , +0 , +1 , ×0 } k. Finally , we define a stateless variant of the counter machine . Removing state from the counter machine is equivalent to allowing it to only have one state q0 . Definition 2.7 ( Stateless counter machine ) . A counter machine is stateless if Q = { q0 } . 3 COUNTER LANGUAGE HIERARCHY . 3.1 SIMPLIFIED COUNTER LANGUAGES . Our first result relating counter classes is to show that the simplified counter languages are a proper subset of the general counter languages . The weakness of the simplified machine is that the update function is conditioned only by the input symbol . Thus , languages like amb2m , which require switching counting behavior , can not be decided correctly . We formalize this in Theorem 3.1 . Theorem 3.1 ( Weakness of SCL ) . Let SCL be the set of languages acceptable in real time by a simplified counter machine . Then , SCL ⊂ CL . Proof . Consider the language amb2m . This is trivially acceptable by a 1-counter machine that adds 2 for each a and subtracts 1 for each b . On the other hand , we shall show that it can not be accepted by any simplified machine . Assume by way of contradiction that such a simplified machine M exists . Tracking the ratio between a ’ s and b ’ s requires infinite state . Thus , the counters of M , as opposed to the finite state , must encode whether 2m = l for strings of the form ambl . Let c be the value of some counter in M . We can decompose c into the update contributed by a ’ s and the the update contributed by b ’ s as follows : c = mua + lub , ( 2 ) ua , ub ∈ { −1 , 0 , 1 } . ( 3 ) Exhausting all the possible functions that c can compute , we get c ∈ { 0 , ±m , ±l , ± ( m+ l ) , ± ( m− l ) } ( 4 ) z ( c ) ∈ { 0,1m > 0,1l > 0,1m+l > 0,1m−l 6=0 } . ( 5 ) We ignore the first four options for z ( c ) , as they clearly do not relate m to l. The final option checks whether the ratio is 1 , not 2 . Thus , z ( c ) can not distinguish whether 2m = l. Note that this argument breaks down if we allow the counter update to depend on the state . In that case , we can build a machine that has two counters and two states : q0 adds 1 to the first counter while it reads a , and then decrements the first counter and increments the second counter when it reads b . When the first counter is empty and the second counter is not empty , q0 transitions to q1 , which decrements the second counter . We accept if and only if both counters are 0 after xn . 3.2 INCREMENTAL COUNTER LANGUAGES . Unlike the simplified counter machine , the incremental machine has the same linguistic capacity as the general machine . We can simulate each counter on a general machine with a finite amount of overhead . This provides a reduction from general to incremental machines . Theorem 3.2 ( Generality of ICL ) . Let ICL be the set of languages acceptable in real time by an incremental counter machine . Then , ICL = CL . Proof . Let d be the maximum that is ever added or subtracted from a counter c in M . We simulate c in M ′ using a counter c′ and a value q ∈ Z mod d encoded in finite state . We will implement a “ ring-counter ” encoding of c such that c′ = bc/dc q = c mod d. To simulate a ×0 update on c , we apply ×0 to c′ , and transition state such that q : = 0 . To simulate a +m update on c for some m ∈ Z , we first change state such that q : = ( q + m ) mod d. Next , we apply the following update to c′ : +1 if q +m ≥ d −1 if q +m < 0 +0 otherwise . ( 6 ) We can compute z ( c ) by checking whether z ( c′ ) = 0 and q = 0 .

Summary: Motivated by a link between LSTMs and counter machines (suggested by recent work, e.g. Merrill, 2019 et al.), this paper studies the formal properties of counter machines (and LSTMs by extension) as grammars, in hopes of discovering why LSTMs perform particularly well in language tasks despite having no obvious hierarchical structure.