Question: Represent the article for finding a single-sentence TLDR.

Question: Alternatives to recurrent neural networks, in particular, architectures based on attention or convolutions, have been gaining momentum for processing input sequences. In spite of their relevance, the computational properties of these alternatives have not yet been fully explored. We study the computational power of two of the most paradigmatic architectures exemplifying these mechanisms: the Transformer and the Neural GPU . We show both models to be Turing complete exclusively based on their capacity to compute and access internal dense representations of the data. In particular, neither the Transformer nor the Neural GPU requires access to an external memory to become Turing complete. Our study also reveals some minimal sets of elements needed to obtain these completeness . There is an increasing interest in designing neural network architectures capable of learning algorithms from examples BID6 BID7 BID10 BID11 BID13 BID4. A key requirement for any such an architecture is thus to have the capacity of implementing arbitrary algorithms, that is, to be Turing complete. Turing completeness often follows for these networks as they can be seen as a control unit with access to an unbounded memory; as such, they are capable of simulating any Turing machine. On the other hand, the work by has established a different way of looking at the Turing completeness of neural networks. In particular, their work establishes that recurrent neural networks (RNNs) are Turing complete even if only a bounded number of resources (i.e., neurons and weights) is allowed. This is based on two conditions: the ability of RNNs to compute internal dense representations of the data, and the mechanisms they use for accessing such representations. Hence, the view proposed by Siegelmann & Sontag shows that it is possible to release the full computational power of RNNs without arbitrarily increasing its model complexity. Most of the early neural architectures proposed for learning algorithms correspond to extensions of RNNs -e.g., Neural Turing Machines BID6 ) -, and hence they are Turing complete in the sense of Siegelmann & Sontag. However, a recent trend has shown the benefits of designing networks that manipulate sequences but do not directly apply a recurrence to sequentially process their input symbols. Architectures based on attention or convolutions are two prominent examples of this approach. In this work we look at the problem of Turing completenessà la Siegelmann & Sontag for two of the most paradigmatic models exemplifying these features: the Transformer and the Neural GPU BID11.The main contribution of our paper is to show that the Transformer and the Neural GPU are Turing complete based on their capacity to compute and access internal dense representations of the data. In particular, neither the Transformer nor the Neural GPU requires access to an external additional memory to become Turing complete. Thus the completeness holds for bounded architectures (bounded number of neurons and parameters). To prove this we assume that internal activations are represented as rational numbers with arbitrary precision. For the case of the Transformer we provide a direct simulation of a Turing machine, while for the case of the Neural GPU our follows by simulating standard sequence-to-sequence RNNs. Our study also reveals some minimal sets of elements needed to obtain these completeness . The computational power of Transformers and of Neural GPUs has been compared in the current literature BID4, but both are only informally used. Our paper provides a formal way of approaching this comparison. For the sake of space, we only include sketch of some proofs in the body of the paper. The details for every proof can be found in the appendix. Background work The study of the computational power of neural networks can be traced back to BID14 which established an analogy between neurons with hard-threshold activations and first order logic sentences, and BID12 that draw a connection between neural networks and finite automata. As mentioned earlier, the first work showing the Turing completeness of finite neural networks with linear connections was carried out by BID18 1995). Since being Turing complete does not ensure the ability to actually learn algorithms in practice, there has been an increasing interest in enhancing RNNs with mechanisms for supporting this task. One strategy has been the addition of inductive biases in the form of external memory, being the Neural Turing Machine (NTM) BID6 ) a paradigmatic example. To ensure that NTMs are differentiable, their memory is accessed via a soft attention mechanism. Other examples of architectures that extend RNNs with memory are the Stack-RNN BID10, and the (De)Queue-RNNs BID7. By Siegelmann & Sontag's , all these architectures are Turing complete. The Transformer architecture is almost exclusively based on the attention mechanism, and it has achieved state of the art on many language-processing tasks. While not initially designed to learn general algorithms, BID4 have advocated the need for enriching its architecture with several new features as a way to learn general procedures in practice. This enrichment is motivated by the empirical observation that the original Transformer architecture struggles to generalize to input of lengths not seen during training. We, in contrast, show that the original Transformer architecture is Turing complete, based on different considerations. These do not contradict each other, but show the differences that may arise between theory and practice. For instance, BID4 assume fixed precision, while we allow arbitrary internal precision during computation. We think that both approaches can be complementary as our theoretical can shed light on what are the intricacies of the original architecture, which aspects of it are candidates for change or improvement, and which others are strictly needed. For instance, our proof uses hard attention while the Transformer is often trained with soft attention . See Section 3.3 for a discussion on these differences. The Neural GPU is an architecture that mixes convolutions and gated recurrences over tridimensional tensors. It has been shown that NeuralGPUs are powerful enough to learn decimal multiplication from examples BID5, being the first neural architecture capable of solving this problem end-to-end. The similarity of Neural GPUs and cellular automata has been used as an argument to state the Turing completeness of the architecture BID11 BID16. Cellular automata are Turing complete (; BID15 and their completeness is established assuming an unbounded number of cells. In the Neural GPU architecture, in contrast, the number of cells that can be used during a computation is proportional to the size of the input sequence BID11 . One can cope with the need for more cells by padding the Neural GPU input with additional (dummy) symbols, as much as needed for a particular computation. Nevertheless, this is only a partial solution, as for a Turing-complete model of computation, one cannot decide a priori how much memory is needed to solve a particular problem. Our in this paper are somehow orthogonal to the previous argument; we show that one can leverage the dense representations of the Neural GPU cells to obtain Turing completeness without requiring to add cells beyond the ones used to store the input. We assume all weights and activations to be rational numbers of arbitrary precision. Moreover, we only allow the use of rational functions with rational coefficients. Most of our positive make use of the piecewise-linear sigmoidal activation function σ: Q → Q, which is defined as σ(x) = 0 x < 0, x 0 ≤ x ≤ 1, 1 x > 1.We are mostly interested in sequence-to-sequence (seq-to-seq) neural network architectures that we next formalize. A seq-to-seq network N receives as input a sequence X = (x 1, . . ., x n) of vectors x i ∈ Q d, for some d > 0, and produces as output a sequence Y = (y 1, . . ., y m) of vectors DISPLAYFORM0 Most of these types of architectures require a seed vector s and some stopping criterion for determining the length of the output. The latter is usually based on the generation of a particular output vector called an end of sequence mark. In our formalization instead, we allow a network to produce a fixed number r ≥ 0 of output vectors. Thus, for convenience we see a general seq-toseq network as a function N such that the value N (X, s, r) corresponds to an output sequence of the form Y = (y 1, y 2, . . ., y r). With this definition, we can view every seq-to-seq network as a language recognizer of strings as follows. Definition 2.1. A seq-to-seq language recognizer is a tuple A = (Σ, f, N, s, F), where Σ is a finite alphabet, f: Σ → Q d is an embedding function, N is a seq-to-seq network, s ∈ Q d is a seed vector, and F ⊆ Q d is a set of final vectors. We say that A accepts the string w ∈ Σ *, if there exists an integer r ∈ N such that N (f (w), s, r) = (y 1, . . ., y r) and y r ∈ F. The language accepted by A, denoted by L(A), is the set of all strings accepted by A.We impose two additional restrictions over recognizers. The embedding function f: Σ → Q d should be computed by a Turing machine in time linear w.r.t. the size of Σ. This covers the two most typical ways of computing input embeddings from symbols: the one-hot encoding, and embeddings computed by fixed feed-forward networks. Moreover, the set F should also be recognizable in lineartime; given a vector f, the membership f ∈ F should be decided by a Turing machine working in linear time with respect to the size (in bits) of f. This covers the usual way of checking equality with a fixed end-of-sequence vector. We impose these restrictions to disallow the possibility of cheating by encoding arbitrary computations in the input embedding or the stop condition, while being permissive enough to construct meaningful embeddings and stoping criterions. Finally, a class N of seq-to-seq neural network architectures defines the class L N composed of all the languages accepted by language recognizers that use networks in N. From these notions, the formalization of Turing completeness of a class N naturally follows. Given an input sequence X = (x 1, . . ., x n), a seed vector y 0, and r ∈ N, an encoder-decoder RNN is given by the following two recursions DISPLAYFORM1 where V, W, U, R are matrices, b 1 and b 2 are vectors, O(·) is an output function, and f 1 and f 2 are activations functions. Equation is called the RNN-encoder and the RNN-decoder. The next Theorem follows by inspection of the proof by BID18 1995) after adapting it to our formalization of encoder-decoder RNNs. BID18 1995) ). The class of encoder-decoder RNNs is Turing complete. Turing completeness holds even if we restrict to the class in which R is the zero matrix, b 1 and b 2 are the zero vector, O(·) is the identity function, and f 1 and f 2 are the piecewise-linear sigmoidal activation σ. In this section we present a formalization of the Transformer architecture , abstracting away from specific choices of functions and parameters. Our formalization is not meant to produce an efficient implementation of the Transformer, but to provide a simple setting over which its mathematical properties can be established in a formal way. The Transformer is heavily based on the attention mechanism introduced next. Consider a scoring function score: DISPLAYFORM0 Usually, q is called the query, K the keys, and V the values. We do not pose any restriction on the scoring and normalization functions, as some of our hold in general. We only require the normalization function to satisfy that there is a function f ρ from Q to Q + such that for each x = (x 1, . . ., x n) ∈ Q n it is the case that the i-th DISPLAYFORM1. Thus, a in Equation is a convex combination of the vectors in V. When proving possibility , we will need to pick specific scoring and normalization functions. A usual choice for the scoring function is a feed forward network with input (q, k i) sometimes called additive attention. Another possibility is to use the dot product q, k i called multiplicative attention . We use a combination of both: multiplicative attention plus a non linear function. For the normalization function, softmax is a standard choice. Nevertheless, in our proofs we use the hardmax function, which is obtained by setting f hardmax (x i) = 1 if x i is the maximum value, and f hardmax (x i) = 0 otherwise. Thus, for a vector x in which the maximum value occurs r times, we have that hardmax i (x) = 1 r if x i is the maximum value of x, and hardmax i (x) = 0 otherwise. We call it hard attention whenever hardmax is used as normalization function. As customary, for a function F: DISPLAYFORM2 Transformer Encoder and Decoder A single-layer encoder of the Transformer is a parametric function Enc(X; θ) receiving a sequence X = (x 1, . . ., x n) of vectors in Q d and returning a sequence Z = (z 1, . . ., z n) of the same length of vectors in Q d. In general, we consider the parameters in Enc(X; θ) as functions Q(·), K(·), V (·), and O(·), all of them from Q d to Q d. The single-layer encoder is then defined as follows DISPLAYFORM3 In practice Q(·), K(·), V (·) are typically matrix multiplications, and O(·) a feed-forward network. The + x i and + a i summands are usually called residual connections BID8 b). When the particular functions used as parameters are not important, we simply write Z = Enc(X).The Transformer encoder is defined simply as the repeated application of single-layer encoders (with independent parameters), plus two final transformation functions K(·) and V (·) applied to every vector in the output sequence of the final layer. Thus the L-layer Transformer encoder is defined by the following recursion (with 1 ≤ ≤ L − 1 and X 1 = X). DISPLAYFORM4 to denote an L-layer Transformer encoder over the sequence X.A single-layer decoder is similar to a single-layer encoder but with additional attention to an external pair of key-value vectors (K e, V e). The input for the single-layer decoder is a sequence Y = (y 1, . . ., y k) plus the external pair (K e, V e), and the output is a sequence Z = (z 1, . . ., z k). When defining a decoder layer we denote by Y j the sequence (y 1, . . ., y j), for 1 ≤ j ≤ k. The layer is also parameterized by four functions Q(·), K(·), V (·) and O(·) and is defined as follows. DISPLAYFORM5 considers the subsequence of Y only until index i and is used to generate a query p i to attend the external pair (K e, V e). We denote the single-decoder layer by Dec((K e, V e), Y; θ).The Transformer decoder is a repeated application of single-layer decoders, plus a transformation function F: Q d → Q d applied to the final vector of the decoded sequence. Thus, the output of the decoder is a single vector z ∈ Q d. Formally, the L-layer Transformer decoder is defined as DISPLAYFORM6 We use z = TDec L ((K e, V e), Y ) to denote an L-layer Transformer decoder. The complete Tansformer A Transformer network receives an input sequence X, a seed vector y 0, and a value r ∈ N. Its output is a sequence Y = (y 1, . . ., y r) defined as y t+1 = TDec(TEnc(X), (y 0, y 1, . . ., y t)), for 0 ≤ t ≤ r − 1. We denote the output sequence of the transformer as Y = (y 1, y 2, . . ., y r) = Trans(X, y 0, r). The Transformer, as defined above, is order-invariant: two input sequences that are permutations of each other produce exactly the same output. This is a consequence of the following property of the attention function: if K = (k 1, . . ., k n), V = (v 1, . . ., v n), and π: {1, . . ., n} → {1, . . ., n} is a permutation, then Att(q, K, V) = Att(q, π(K), π(V)) for every query q. This weakness has motivated the need for including information about the order of the input sequence by other means; in particular, this is often achieved by using the so-called positional encodings (; BID17, which we study below. But before going into positional encodings, a natural question is what languages the Transformer can recognize without them. As a standard yardstick we use the well-studied class of regular languages, i.e., languages recognized by finite automata. Order-invariance implies that not every regular language can be recognized by a Transformer network. As an example, there is no Transformer network that can recognize the regular language (ab) *, as the latter is not order-invariant. A reasonable question then is whether the Transformer can express all regular languages which are order-invariant. It is possible to show that this is not the case by proving that the Transformer actually satisfies a stronger invariance property, which we call proportion invariance. For a string w ∈ Σ * and a symbol a ∈ Σ, we use prop(a, w) to denote the ratio between the number of times that a appears in w and the length of w. Consider now the set PropInv(w) = {u ∈ Σ * | prop(a, w) = prop(a, u) for every a ∈ Σ}. Proposition 3.1. Let Trans be a Transformer, s a seed, r ∈ N, and f: Σ → Q d an embedding function. Then Trans(f (w), s, r) = Trans(f (u), s, r), for each u, w ∈ Σ * with u ∈ PropInv(w).As an immediate corollary we obtain the following. Corollary 3.2. Consider the order-invariant regular language L = {w ∈ {a, b} * | w has an even number of a symbols}. Then L cannot be recognized by a Transformer network. On the other hand, languages recognized by Transformer networks are not necessarily regular. Proposition 3.3. There is a Transformer network that recognizes the non-regular language S = {w ∈ {a, b} * | w has strictly more symbols a than symbols b}.That is, the computational power of Transformer networks without positional encoding is both rather weak (they do not even contain order-invariant regular languages) and not so easy to capture (as they can express counting properties that go beyond regularity). As we show in the next section, the inclusion of positional encodings radically changes the picture. Thus, given an input string w = a 1 a 2 · · · a n ∈ Σ, the of the embedding function f pos (w) provides a "new" input f pos (a 1, 1), f pos (a 2, 2),..., f pos (a n, n) to the Transformer encoder. Similarly, the Transformer decoder instead of receiving the sequence Y = (y 0, y 1, . . ., y t) as input, it receives now the sequence Y = y 0 + pos, y 1 + pos,..., y t + pos(t + 1)As for the case of the embedding functions, we require the positional encoding pos(i) to be computable by a Turing machine working in linear time w.r.t. the size (in bits) of i. The main of this section is the completeness of Transformers with positional encodings. DISPLAYFORM0. DISPLAYFORM1... DISPLAYFORM2 attends to the encoder and copies the corresponding symbol uses self attention to compute next state and the next symbol under M's head Proof Sketch. We show that for every Turing machine M = (Q, Σ, δ, q init, F) there exists a transformer that simulates the complete execution of M. We represent a string w = s 1 s 2 · · · s n ∈ Σ * as a sequence X of one-hot vectors with their corresponding positional encodings. Denote by q (t) ∈ Q the state of M at time t when processing w, and s (t) ∈ Σ the symbol under M's head at time t. Similarly, v (t) ∈ Σ is the symbol written by M and m (t) ∈ {←, →} the head direction. We next describe how to construct a transformer Trans M that with input X produces a sequence y 0, y 1, y 2,... such that y i contains information about q (i) and s (i) (encoded as one-hot vectors). DISPLAYFORM3 The construction and proof goes by induction. Assume the decoder receives y 0,..., y t such that y i contains q (i) and s (i). To construct y t+1, in the first layer we just implement M's transition function δ; note that δ((t+1) which is the index to which M is going to be pointing to in the next time step. By using the residual connections we also store q (i+1) and v (i) in z 2 i. The final piece of our construction is to compute the symbol that the tape holds at index c (t+1), that is, the symbol under M's head at time t + 1. For this we use the following observation: the symbol at index c (t+1) in time t + 1 coincides with the last symbol written by M at index c (t+1). Thus, we need to find the maximum value i ≤ t such that c (i) = c (t+1) and then copy v (i) which is the symbol that was written by M at time step i. This last computation can also be done with a self-attention layer. Thus, we attend directly to position i (hard attention plus positional encodings) and copy v (i) which is exactly s (t+1). We finally copy q (t+1) and s (t+1) into the output to construct y t+1. FIG2 shows a high-level diagram of the decoder computation. DISPLAYFORM4 There are several other details in the construction, in particular, at the beginning of the computation (first n steps), the decoder needs to attend to the encoder and copy the input symbols so they can later be processed as described above. Another detail is when M reaches a cell that has not been visited before, then the symbol under the head has to be set as # (the blank symbol). We show that all these decisions can be implemented with feed-forward networks plus attention. The complete construction uses one encoder layer, three decoder layers and vectors of dimension d = 2|Q| + 4|Σ| + 11 to store one-hot representations of states, symbols and some additional working space. All details can be found in the appendix. Although the general architecture that we presented closely follows that of , some choices for functions and parameters in our positive are different to the usual choices in practice. For instance, we use hard attention which allow us to attend directly to specific positions. In contrast, use softmax to attend, plus sin-cos functions as positional encodings. The softmax, sin and cos are not rational functions, and thus, are forbidden in our formalization. An interesting line for future work is to consider arbitrary functions but with additional restrictions, such as finite precision as done by. Another difference is that for the function O(·) in Equation The need of arbitrary precision Our Turing-complete proof relies on having arbitrary precision for internal representations, in particular, for storing and manipulating positional encodings. Although having arbitrary precision is a standard assumption when studying the expressive power of neural networks BID3 ) practical implementations rely on fixed precision hardware. If fixed precision is used, then positional encodings can be seen as functions of the form pos: N → A where A is a finite subset of Q d. Thus, the embedding function f pos can be seen as a regular embedding function f: Σ → Q d where Σ = Σ × A. Thus, whenever fixed precision is used, the net effect of having positional encodings is to just increase the size of the input alphabet. Then from Proposition 3.1 we obtain that the Transformer with positional encodings and fixed precision is not Turing complete. Although no longer Turing complete, one can still study the computational power of fixed-precision Transformers. We left this as future work. The Neural GPU BID11 is an architecture that mixes convolutions and gated recurrences over tridimensional tensors. It is parameterized by three functions U (·) (update function), R(·) (reset function), and F (·). Given a tensor S ∈ Q h×w×d and a value r ∈ N, it produces a sequence S 1, S 2,..., S r given by the following recursive definition (with S 0 = S). DISPLAYFORM0 where denotes the element-wise product, and 1 is a tensor with only 1's. Neural GPUs force functions U (·) and R(·) to produce a tensor of the same shape as its input with all values in. Thus, a Neural GPU resembles a gated recurrent unit, with U working as the update gate and R as the reset gate. Functions U (·), R(·), and F (·) are defined as a convolution of its input with a 4-dimensional kernel bank with shape (k H, k W, d, d) plus a bias tensor, followed by a point-wise transformation DISPLAYFORM1 with different kernels and biases for U (·), R(·), and F (·).To have an intuition on how the convolution K * S works, it is illustrative to think of S as an (h × w)-grid of (row) vectors and DISPLAYFORM2, and K ij = K i,j,:,:, then K * S is a regular two-dimensional convolution in which scalar multiplication has been replaced by vector-matrix multiplication as in the following expression DISPLAYFORM3 where DISPLAYFORM4 This intuition makes evident the similarity between Neural GPUs and cellular automata: S is a grid of cells, and in every iteration each cell is updated considering the values of its neighbors according to a fixed rule given by K BID11. As customary, we assume zero-padding when convolving outside S. To study the computational power of Neural GPUs, we cast them as a standard seq-to-seq architecture. Given an input sequence, we put every vector in the first column of the tensor S. We also need to pick a special cell of S as the output cell from which we read the output vector in every iteration. We pick the last cell of the first column of S. Formally, given a sequence X = (x 1, . . ., x n) with x i ∈ Q d, and a fixed value w ∈ N, we construct the tensor S ∈ Q n×w×d by leting S i,1,: = x i and S i,j,: = 0 for j > 1. The output of the Neural GPU, denoted by NGPU(X, r), is the sequence of vectors Y = (y 1, y 2, . . ., y r) such that y t = S t n,1,:. Given this definition, we can naturally view the Neural GPUs as language recognizers (as formalized in Section 2).Since the bias tensor B in Equation FORMULA15 is of the same size than S, the number of parameters in a Neural GPU grows with the size of the input. Thus, a Neural GPU cannot be considered as a fixed architecture. To tackle this issue we introduce the notion of uniform Neural GPU, as one in which for every bias B there exists a matrix B ∈ Q w×d such that B i,:,: = B for each i. Thus, uniform Neural GPUs can be finitely specified (as they have a constant number of parameters, not depending on the length of the input). We now establish the Turing completeness of this model. Theorem 4.1. The class of uniform Neural GPUs is Turing complete. Proof sketch. The proof is based on simulating a seq-to-seq RNN; thus, completeness follows from Theorem 2.3. Consider an RNN encoder-decoder language recognizer, such that N is of dimension d and its encoder and decoder are defined by the equations h i = σ(x i W + h i−1 V) and g t = σ(g t−1 U), respectively, where g 0 = h n and n is the length of the input. We use a Neural GPU with input tensor S ∈ Q n×1×3d+3. Let E i = S i,1,1:d and D i = S i,1,d+1:2d. The idea is to use E for the encoder and D for the decoder. We use kernel banks of shape (2, 1, 3d + 3, 3d + 3) with uniform bias tensors to simulate the following computation. In every step t, we first compute the value of σ(E t W + E t−1 V) and store it in E t, and then reset E t−1 to zero. Similarly, in step t we update the vector in position D t−1 storing in it the value σ(D t−1 U + E t−1 U) (for the value of E t−1 before the reset). We use the gating mechanism to ensure a sequential update of the cells such that at time t we update only positions E i and D j for i ≤ t and j ≤ t − 1. Thus the updates on the D are always one iteration behind the update of E. Since the vectors in D are never reset to zero, they keep being updated which allows us to simulate an arbitrary long computation. In particular we prove that at iteration t it holds that E t = h t, and at iteration n + t it holds that D n = g t. We require 3d + 3 components, as we need to implement several gadgets for properly using the update and reset gates. In particular, we need to store the value of E t−1 before we reset it. The detailed construction and the correctness proof can be found in the appendix. The proof above makes use of kernels of shape (2, 1, d, d) to obtain Turing completeness. This is, in a sense, optimal, as one can easily prove that Neural GPUs with kernels of shape (1, 1, d, d) are not Turing complete, regardless of the size of d. In fact, for kernels of this shape the value of a cell of S at time t depends only on the value of the same cell in time t − 1.Zero padding vs circular convolution The proof of Theorem 4.1 requires the application of zero padding in convolution. This allows us to clearly differentiate internal cells from cells corresponding to the endpoints of the input sequence. Interestingly, Turing-completeness is lost if we replace zero padding with circular convolution. Formally, given S ∈ Q h×w×d, a circular convolution is obtained by defining S h+n,:,: = S n,:,: for n ∈ Z. One can prove that uniform Neural GPUs with circular convolutions cannot differentiate among periodic sequences of different length; in particular, they cannot check if a periodic input sequence is of even or odd length. This yields the following: Proposition 4.2. Uniform Neural GPUs with circular convolutions are not Turing complete. Related to this last is the empirical observation by BID16 that Neural GPUs that learn to solve hard problems, e.g., binary multiplication, and which generalize to most of the inputs, struggle with highly symmetric (and nearly periodic) inputs. Actually, BID16 exhibit examples of the form 11111111 × 11111111 failing for all inputs with eight or more 1s. We leave as future work to explore the implications of our theoretical on this practical observation. BID5 simplified Neural GPUs and proved that, by considering piecewise linear activations and bidimensional input tensors instead of the original smooth activations and tridimensional tensors used by BID11, it is possible to achieve substantially better in terms of training time and generalization. Our Turing completeness proof also relies on a bidimensional tensor and uses piecewise linear activations, thus providing theoretical evidence that these simplifications actually retain the full expressiveness of Neural GPUs while simplifying its practical applicability. We have presented an analysis of the Turing completeness of two popular neural architectures for sequence-processing tasks; namely, the Transformer, based on attention, and the Neural GPU, based on recurrent convolutions. We plan to further refine this analysis in the future. For example, our proof of Turing completeness for the Transformer requires the presence of residual connections, i.e., the +x i, +a i, +y i, and +p i summands in Equations, while our proof for Neural GPUs heavily relies on the gating mechanism. We will study whether these features are actually essential to obtain completeness. We presented general abstract versions of both architectures in order to prove our theoretical . Although we closely follow their original definitions, some choices for functions and parameters in our positive are different to the usual choices in practice, most notably, the use of hard attention for the case of the Transformer, and the piecewise linear activation functions for both architectures. As we have mentioned, BID5 showed that for Neural GPUs piecewise linear activations actually help in practice, but for the case of the Transformer architecture more experimentation is needed to have a conclusive response. This is part of our future work. Although our are mostly of theoretical interest, they might lead to observations of practical interest. For example, BID1 have established the undecidability of several practical problems related to probabilistic language modeling with RNNs. This means that such problems can only be approached in practice via heuristics solutions. Many of the in BID1 are, in fact, a consequence of the Turing completeness of RNNs as established by. We plan to study to what extent our analogous undecidability for Transformers and Neural GPUs imply undecidability for language modeling problems based on these architectures. Finally, our rely on being able to compute internal representations of arbitrary precision. It would be interesting to perform a theoretical study of the main properties of both architectures in a setting in which only finite precision is allowed, as have been recently carried out for RNNs . We also plan to tackle this problem in our future work. We first sketch the main idea of Siegelmann & Sontag's proof. We refer the reader to the original paper for details. Siegelmann & Sontag show how to simulate a two-stack machine M (and subsequently, a Turing machine) with a single RNN N with σ as activation. They first construct a network N 1 that, with 0 as initial state (h N1 0 = 0) and with a binary string w ∈ {0, 1} * as input sequence, produces a representation of w as a rational number and stores it as one of its internal values. Their internal representation of strings encodes every w as a rational number between 0 and 1. In particular, they use base 4 such that, for example, a string w = 100110 is encoded as (0.311331) 4 that is, its encoding is DISPLAYFORM0 This representation allows one to easily simulate stack operations as affine transformations plus σ activations. For instance, if x w is the value representing string w = b 1 b 2 · · · b n seen as a stack, then the top(w) operation can be defined as simply y = σ(4x w − 2), since y = 1 if and only if b 1 = 1, and y = 0 if and only if b 1 = 0. Other stack operations can de similarly simulated. Using this representation, they construct a second network N 2 that simulates the two-stacks machine by using one neuron value to simulate each stack. The input w for the simulated machine M is assumed to be at an internal value given to N 2 as an initial state (h N2 0). Thus, N 2 expects only zeros as input. Actually, to make N 2 work for r steps, an input of the form 0 r should be provided. Finally, they combine N 1 and N 2 to construct a network N which expects an input of the following form: It is clear that Siegelmann & Sontag's proof resembles a modern encoder-decoder RNN architecture, where N 1 is the encoder and N 2 is the decoder, thus it is straightforward to use the same construction to provide an RNN encoder-decoder N and a language recognizer A that uses N and simulates the two-stacks machine M. There are some details that is important to notice. Assume that N is given by the formulas in Equations and. First, since N 2 in the above construction expects no input, we can safely assume that R in Equation FORMULA1 is the null matrix. Moreover, since A defines its own embedding function, we can ensure that every vector that we provide for the encoder part of N has a 1 in a fixed component, and thus we do not need the bias b 1 in Equation since it can be simulated with one row of matrix V. We can do a similar construction for the bias b 2 (Equation FORMULA1). Finally, Siegelmann & Sontag show that its construction can be modified such that a particular neuron of N 2, say n, is always 0 except for the first time an accepting state of M is reached, in which case n = 1. Thus, one can consider O(·) (Equation FORMULA1) as the identity function and add to A the stopping criterion that just checks if n is 1. We extend the definition of the function PropInv to sequences of vectors. Given a sequence X = (x 1, . . ., x n) we use vals(X) to denote the set of all vectors occurring in X. Similarly as for strings, we use prop(v, X) as the number of times that v occurs in X divided by the length of X. Now we are ready to extend PropInv with the following definition: DISPLAYFORM1 PropInv(X) = {X | vals(X) = vals(X) and prop(v, X) = prop(v, X) for all v ∈ vals(X)} Notice that for every embedding function f: Σ → Q d and string w ∈ Σ *, we have that if u ∈ PropInv(w) then f (u) ∈ PropInv(f (w)). Thus in order to prove that Trans(f (w), s, r) = Trans(f (u), s, r) for every u ∈ PropInv(w), it is enough to prove that Trans(X, s, r) = Trans(X, s, r) for every X ∈ PropInv(X)To further simplify the exposition of the proof we introduce another notation. We denote by p X v as the number of times that vector v occurs in X. Thus we have that X ∈ PropInv(X) if and only if, there exists a value γ ∈ Q + such that for every v ∈ vals(X) it holds that p DISPLAYFORM2 We now have all the necessary to proceed with the proof of Proposition 3.1. We will prove it by proving the property in. Let X = (x 1, . . ., x n) be an arbitrary sequence of vectors, and let X = (x 1, . . ., x m) ∈ PropInv(X). Moreover, let Z = (z 1, . . ., z n) = Enc(X; θ) and Z = (z 1, . . ., z m) = Enc(X ; θ). We first prove the following property:For every pair of indices (i, j) ∈ {1, . . ., n} × {1, . . ., m}, if DISPLAYFORM3 Lets (i, j) be a pair of indices such that x i = x j. From Equations we have that DISPLAYFORM4. By equations and the restriction over the form of normalization functions we have that DISPLAYFORM5 where α = n =1 f ρ (score(Q(x), K(x))). The above equation can be rewritten as DISPLAYFORM6. By a similar reasoning we can write DISPLAYFORM7 ). Now, since X ∈ PropInv(X) we know that vals(X) = vals(X) and there exists a γ ∈ Q + such that p X v = γp X v for every v ∈ vals(X). Finally, from this last property, plus the fact that x i = x j we have DISPLAYFORM8 Which completes the proof of Property FORMULA23 above. Consider now the complete encoder TEnc. Let (K, V) = TEnc(X) and (K, V) = TEnc(X), and let q be an arbitrary vector. We will prove now that Att(q, K, V) = Att(q, K, V). By following a similar reasoning as for proving Property (plus induction on the layers of TEnc) we obtain that if x i = x j then k i = k j and v i = v j, for every i ∈ {1, . . ., n} and j ∈ {1, . . ., m}. Thus, there exists a mapping DISPLAYFORM9 for every i ∈ {1, . . ., n} and j ∈ {1, . . ., m}. Lets focus now on Att(q, K, V). We have: DISPLAYFORM10. Similarly as before, we can rewrite this as DISPLAYFORM11 And finally using that X ∈ PropInv(X) we obtain DISPLAYFORM12 which is what we wanted. To complete the rest proof, consider Trans(X, y 0, r) which is defined by the recursion y k+1 = TDec(TEnc(X), (y 0, y 1, . . ., y k))To prove that Trans(X, y 0, r) = Trans(X, y 0, r) we use an inductive argument. We know that y 1 = TDec(TEnc(X), (y 0)) = TDec((K, V), (y 0)). Now TDec only access (K, V) via attentions of the form Att(q, K, V) and for the case of y 1 the vector q can only depend on y 0, thus, from Att(q, K, V) = Att(q, K, V) we have that DISPLAYFORM13 ). The rest of the steps follow by a simple induction on k. To obtain a contradiction, assume that there is a language recognizer A that uses a Transformer network and such that L = L(A). Now consider the strings w 1 = aabb and w 2 = aaabbb. Since w 1 ∈ PropInv(w 2) by Proposition 3.1 we have that w 1 ∈ L(A) if and only if w 2 ∈ L(A) which is a contradiction since w 1 ∈ L but w 2 / ∈ L. This completes the proof of the corollary. We construct a language recognizer A = (Σ, f, Trans, s, F) with Trans a very simple Transformer network with dimension d = 2 and using just one layer of encoder and one layer of decoder, such that L(A) = {w ∈ {a, b} * | w has strictly more symbols a than symbols b}. As embedding function, we use f (a) = and f (b) = [0, −1].Assume that the output for the encoder part of the transformer is X = (x 1, . . ., x n). First we use an encoder layer that implements the identity function. This can be trivially done using null functions for the self attention and through the residual connections this encoder layer shall preserve the original x i values. For the final V (·) and K(·) functions of the Transformer encoder (Equation For the decoder we use a similar approach. We consider the identity in the self attention plus the residual (which can be done by just using the null functions for the self attention). Considering the external attention, that is the attention over (K e, V e), we let score and ρ be arbitrary scoring and normalization functions. And finally for the function O(·) (Equation In order to complete the proof we introduce some notation. Lets denote by # a (w) as the number of a's in w, and similarly # b (w) for the number of b's in w. Lets call c w as the value #a(w)−# b (w) n. We now prove that, for any string w ∈ {a, b} * if we consider f (w) = X = (x 1, . . ., x n) as the input sequence for Trans and we use initial value s = for the decoder, the complete network shall compute a sequence y 1, y 2,..., y r such that: DISPLAYFORM0 We proceed by induction. The base case trivially holds since y 0 = s =. Assume now that we are at step r and the input for the decoder is (y 0, y 1, . . ., y r). We will show that y r+1 = [c w, 0]. Since we consider the identity in the self attention (Equation), we have that p i = y i for every i in {0, . . ., i}. Now considering the external attention, that is the attention over (K e, V e), Since all key vectors in K e are, the external attention will produce the same score value for all positions. That is, score(p i, k j1) = score(p i, k j2) for every j 1, j 2. Lets call this value s. Thus we have that DISPLAYFORM1 Then, since V e = X we have that DISPLAYFORM2 for every i ∈ {0, . . ., r}. The last equality holds since our embedding are f (a) = and f (b) = [0, −1], and so every a in w sums one and every b subtracts one. Thus, we have that DISPLAYFORM3 for every i ∈ {0, . . ., r}. In the next step, after the external attention plus the residual connection (Equation) we have DISPLAYFORM4 Finally, y r+1 = F (z r) = z r = [c w, 0] which is exactly what we wanted to prove. To complete the proof, notice that # a (w) > # b (w) if and only if c w > 0. If we define F as Q + × Q, the recognizer A = (Σ, f, Trans, s, F) will accept the string w exactly when c w > 0, that is, w ∈ L(A) if and only if # a (w) > # b (w). That is exactly the language S, and so the proof is complete. Let M = (Q, Σ, δ, q init, F) be a Turing machine with a infinite tape and assume that the special symbol # ∈ Σ is used to mark blank positions in the tape. We make the following assumptions about how M works when processing an input string:• M always moves its head either to the left or to the right (it never stays at the same cell).• M begins at state q init pointing to the cell immediately to the left of the input string.• M never makes a transition to the left of the initial position.• Q has a special state q read used to read the complete input.• Initially (time 0), M makes a transition to state q read and move its head to the right.• While in state q read it moves to the right until symbol # is read.• There are no transitions going out from accepting states (states in F).It is easy to prove that every general Turing machine is equivalent to one that satisfies the above assumptions. We prove that one can construct a transformer network Trans M that is able to simulate M on every possible input string. The construction is somehow involved and uses several helping values, sequences and intermediate . To make the reading more easy we divide the construction and proof in three parts. We first give a high-level view of the strategy we use. Then we give some details on the architecture of the encoder and decoder needed to implement our strategy, and finally we formally prove that every part of our architecture can be actually implemented. In the encoder part of Trans M we receive as input the string w = s 1 s 2... s n. We first use an embedding function to represent every s i as a one-hot vector and add a positional encoding for every index. The encoder produces output (K e, V e) where K e = (k In the decoder part of Trans M we simulate a complete execution of M over w = s 1 s 2 · · · s n . For this we define the following sequences (for i ≥ 0): DISPLAYFORM0: state of M at time i: head direction in the transition of M at time iFor the case of m (i) we assume that −1 represents a movement to the left and 1 represents a movement to the right. In our construction we show how to build a decoder that computes all the above values for every time step i using self attention plus attention over the encoder part. Since the above values contain all the needed information to reconstruct the complete history of the computation, we can effectively simulate M.In particular our construction produces the sequence of output vectors y 1, y 2,... such that, for every i, the vector y i contains information about q (i) and s (i) encoded as one-hot vectors. The construction and proof goes by induction. We begin with an initial vector y 0 that represents the state of the computation before it has started, that is q = q init and s = #. For the induction step we assume that we have already computed y 1,..., y r such that y i contains information about q (i) and s (i), and we show how with input (y 0, y 1, . . ., y r) the decoder produces the next vector y r+1 containing q (r+1) and s (r+1).The overview of the construction is as follows. First notice that the transition function δ relates the above values with the following equation: DISPLAYFORM1 We prove that we can use a two-layer feed-forward network to mimic the transition function δ (Lemma B.2). Thus, given that the input vector y i contains q (i) and s (i), we can produce the values q (i+1), v (i) and m (i) (and store them as values in the decoder). In particular, since y r is in the input, we can produce q (r+1) which is part of what we need for y r+1. In order to complete the construction we also need to compute the value s (r+1), that is, we need to compute the symbol under the head of machine M at the next time step (time r + 1). We next describe at a high level, how this symbol can be computed with two additional decoder layers. We first make some observations about s (i) that are fundamental in our computation. Assume that at time i the head of M is pointing to the cell at index k. Then we have three possibilities:1. If i ≤ n, then s (i) = s i since M is still reading its input string.2. If i > n and M has never written at index k, then s (i) = #, the blank symbol.3. In other case, that is, if i > n and time i is not the first time that M is pointing to index k, then s (i) is the last symbol written by M at index k. For the case we can produce s (i) by simply attending to position i in the encoder part. Thus, if r + 1 ≤ n to produce s (r+1) we can just attend to index r + 1 in the encoder and copy this value to y r+1. For cases and FORMULA1 the solution is a bit more complicated, but almost all the important work is to compute what is the index that M is going to be pointing to in time r + 1.To formalize this computation, lets denote by c (i) ∈ Z the following value: DISPLAYFORM2: the index of the cell to which the head of M is pointing to at time i DISPLAYFORM3. If we unroll this equation and assuming that c = 0 we obtain that DISPLAYFORM4 Then, at the step i in the decoder we have all the necessary to compute value c (i) but also the necessary to compute c (i+1). We actually show that the computation (of a representation) of c (i) and c (i+1) can be done by using one layer of self attention (Lemma B.3).We still need to define a final notion. With c (i) one can define the helping value (i) as follows: DISPLAYFORM5 Thus, (i) is a value such that c ((i)) = c (i), which means that at time i and at time (i) the head of M was pointing to the same cell. Moreover, (i) is the maximum value less than i that satisfies such condition. That is (i) is the last time (previous to i) in which M was pointing to position c (i). First notice that in every step, M moves its head either to the right or to the left (it never stays in the same cell). This implies that for every i it holds that c (i) = c (i−1), from which we obtain that (i) < i − 1. Moreover, in the case that c (i) is visited for the first time at time step i, the value (i) is ill-defined. In such a case we let (i) = i − 1. This makes (i) ≤ i − 1 for all i, and allows us to check that c (i) is visited for the first time at time step i by just checking that (i) = i − 1.We now have all the necessary to explain how we compute our desired s (r+1) value. Assume that r + 1 > n (the case r + 1 ≤ n was already covered before). We first note that if (r + 1) = r then s (r+1) = # since this is the first time that cell c (r+1) is visited. On the other hand, if (r + 1) < r then s (r+1) is the value written by M at time (r + 1) which is exactly v ((r+1)). Thus, in this case we only need to attend to position (r + 1) and copy the value v ((r+1)) to produce s (r+1). We show that all this can be done with an additional self-attention decoder layer (Lemma B.4).We have described at a high-level a decoder that, with input (y 0, y 1, . . ., y r), computes the values q (r+1) and s (r+1) which is what we need to produce y r+1. We next show all the details of this construction. In this section we give more details on the architecture of the encoder and decoder needed to implement our strategy. We let several intermediate claims as lemmas that we formally prove in Section B.4.3. For our attention mechanism we use the following non-linear function: DISPLAYFORM0 We note that ϕ(x) = −|x| and it can be implemented as ϕ(x) = − relu(x) − relu(−x). We use ϕ(·) to define a scoring function score ϕ: DISPLAYFORM1 Now, let q ∈ Q d, and K = (k 1, . . ., k n) and V = (v 1, . . ., v n) be tuples of elements in Q d. We now describe how Att(q, K, V) is generally computed when hard attention is considered. Assume first that there exists a single j ∈ {1, . . ., n} that maximizes score ϕ (q, k j). In that case we have that Att(q, K, V) = v j with DISPLAYFORM2 Thus, when computing hard attention with the function score ϕ (·) we essentially select the vector v j such that the dot product q, k j is as close to 0 as possible. If there is more than one index, say indexes j 1, j 2,..., j r, that minimizes the dot product q, k j then we have that DISPLAYFORM3 Thus, in the extreme case in which all dot products are equal q, k j for every index j, attention behaves just as an average of all value vectors, that is Att(q, K, V) = 1 n n j=1 v j. We use all these properties of the hard attention in our proof. We now describe the vectors that we use in the encoder and decoder parts of Trans M. The vectors that we use in the Trans M layers are of dimension d = 2|Q|+4|Σ|+11. To simplify the exposition, whenever we use a vector v ∈ Q d, we write it arranged in four groups of values as follows DISPLAYFORM0 where q i ∈ Q |Q|, s i ∈ Q |Σ|, and x i ∈ Q. Whenever in a vector of the above form any of the four groups of values is composed only of 0's, we just write'0,..., 0' where the length of this sequence is implicit in the length of the corresponding group. Finally, we denote by 0 q the vector in Q |Q| that has only 0's, and similarly 0 s the vector in Q |Σ| that has only 0's. For a symbol s ∈ Σ, we use s to denote a one-hot vector in Q |Σ| that represents s. That is, given an enumeration π: Σ → {1, . . ., |Σ|}, the vector s has a 1 in position π(s) and a 0 in all other positions. Similarly, for q ∈ Q, we use q to denote a one-hot vector in Q |Q| that represents q. We have the necessary to introduce the embedding and positional encoding used in our construction. We use an embedding function f: Σ → Q d defined as DISPLAYFORM0 Our construction uses the positional encoding pos: N → Q d such that DISPLAYFORM1 Thus, given an input sequence s 1 s 2 · · · s n ∈ Σ *, we have that DISPLAYFORM2 We denote this last vector by x i. That is, if M receives the input string w = s 1 s 2 · · · s n, then the input for Trans M is the sequence (x 1, x 2, . . ., x n). The need for using a positional encoding having values 1/i and 1/i 2 will be clear when we formally prove the correctness of our construction. We need a final preliminary notion. In the formal construction of Trans M we also use the following helping sequences: DISPLAYFORM3 These are used to identify when M is still reading the input string. The encoder part of Trans M is very simple. For TEnc M we use a single-layer encoder, such that DISPLAYFORM0 It is straightforward to see that these vectors can be produced with a single encoder layer by using a trivial self attention, taking advantage of the residual connections in Equations and, and then using linear transformations for V (·) and K(·) in Equation.When constructing the decoder we use the following property. Lemma B.1. Let q ∈ Q d be a vector such that q = [, . . .,, 1, j,,] where j ∈ N and'' denotes an arbitrary value. Then we have that DISPLAYFORM1 We next show how to construct the decoder part of Trans M to produce the sequence of outputs y 1, y 2,..., where y i is given by: DISPLAYFORM2 That is, y i contains information about the state of M at time i, the symbol under the head of M at time i, and the last direction followed by M (the direction of the head movement at time i − 1). The need to include m (i−1) will be clear in the construction. We consider as the starting vector for the decoder the vector DISPLAYFORM3 We are assuming that m (−1) = 0 to represent that previous to time 0 there was no head movement. Our construction resembles a proof by induction; we describe the architecture piece by piece and at the same time we show how for every r ≥ 0 our architecture constructs y r+1 from the previous vectors (y 0, . . ., y r).Thus, assume that y 0,..., y r satisfy the properties stated above. Since we are using positional encodings, the actual input for the first layer of the decoder is the sequence y 0 + pos, y 1 + pos,..., y r + pos(r + 1).We denote by y i the vector y i plus its positional encoding. Thus we have that DISPLAYFORM4 For the first self attention in Equation we just produce the identity which can be easily implemented with a trivial attention plus the residual connection. Thus, we produce the sequence of vectors (p DISPLAYFORM5 by Lemma B.1 we know that if we use p 1 i to attend over the encoder we obtain Att(p DISPLAYFORM6 Thus in Equation we finally produce the vector a DISPLAYFORM7 As the final piece of the first decoder layer we use a function O 1 (·) (Equation ) that satisfies the following lemma. Lemma B.2. There exists a two-layer feed-forward network DISPLAYFORM8 besides some other linear transformations. We finally produce as the output of the first decoder layer, the sequence (z DISPLAYFORM9 Notice that z 1 r already holds info about q (r+1) and m (r) which we need for constructing vector y r+1. The single piece of information that we still need to construct is s (r+1), that is, the symbol under the head of machine M at the next time step (time r + 1). We next describe how this symbol can be computed with two additional decoder layers. Recall that c (i) is the cell to which M is pointing to at time i, and that it satisfies that c DISPLAYFORM10. We can take advantage of this property to prove the following lemma. DISPLAYFORM11, and V 2 (·) defined by feed-forward networks such that DISPLAYFORM12 Lemma B.3 essentially shows that one can construct a representation for values c (i) and c (i+1) for every possible index i. In particular we will know the value c (r+1) that represents the cell to which the machine is pointing to in the next time step. Continuing with the decoder layer, when using the self attention above and after adding the residual in Equation we obtain the sequence of vectors (p DISPLAYFORM13 DISPLAYFORM14 We now describe how can we use a third and final decoder layer to produce our desired s (r+1) value (the symbol under the head of M in the next time step). Recall that (i) is the last time (previous to i) in which M was pointing to position c (i), or it is i − 1 if this is the first time that M is pointing to c (i). We can prove the following lemma. Lemma B.4. There exists functions Q 3 (·), K 3 (·), and V 3 (·) defined by feed-forward networks such that DISPLAYFORM15 We prove Lemma B.4 by just showing that, for every i one can attend exactly to position (i+1) and then just copy both values. We do this by taking advantage of the values c (i) and c (i+1) previously computed for every index i. Then we have that p Proof of Lemma B.1. Let q ∈ Q d be a vector such that q = [, . . .,, 1, j,,] where j ∈ N and'' is an arbitrary value. We next prove that DISPLAYFORM0 where α (j) and β (j) are defined as DISPLAYFORM1 Then we have that DISPLAYFORM2 Notice that, if j ≤ n, then the above expression is maximized when i = j. Otherwise, if j > n then the expression is maximized when i = n. Then Att(q, K e, V e) = v i where i = j if j ≤ n and i = n if j > n. We note that i as just defined is exactly β (j). Thus, given that v i is defined as DISPLAYFORM3 we obtain that DISPLAYFORM4 which is what we wanted to prove. Proof of Lemma B.2. In order to prove the lemma we need some intermediate notions and properties. Assume that the enumeration π 1: Σ → {1, . . ., |Σ|} is the one used to construct the one-hot vectors s for s ∈ Σ, and that π 2: Q → {1, . . ., |Q|} is the one used to construct q with q ∈ Q. Using π 1 and π 2 one can construct an enumeration for the pairs in Q × Σ and then construct one-hot vectors for pairs in this set. Formally, given (q, s) ∈ Q × Σ we denote by (q, s) a one-hot vector with a 1 in position (π 1 (s) − 1)|Q| + π 2 (q) and a 0 in every other position. To simplify the notation we use π(q, s) to denote (π 1 (s) − 1)|Q| + π 2 (q). One can similarly construct an enumeration π for Q × Σ × {−1, 1} such that π (q, s, m) = π(q, s) if m = −1 and π (q, s, m) = |Q||Σ| + π(q, s) if m = 1. We denote by (q, s, m) the corresponding one-hot vector for every (q, s, m) ∈ Q × Σ × {−1, 1}. We next prove three helping properties. In every case q ∈ Q, s ∈ Σ, m ∈ {−1, 1}, and δ(·, ·) is the transition function of machine M.1. There exists f 1: DISPLAYFORM5 2. There exists f δ: DISPLAYFORM6 3. There exists f 2: DISPLAYFORM7 Published as a conference paper at ICLR 2019To show, lets denote by S i, with i ∈ {1, . . ., |Σ|}, a matrix of dimensions |Σ| × |Q| such that S i has its i-th row with 1's and it is 0 everywhere else. We note that for every s ∈ Σ it holds that s S i = 1 if and only if i = π 1 (s) and it is 0 otherwise. Now, consider the vector v (q,s) DISPLAYFORM8 We first note that for every i ∈ {1, . . ., |Σ|}, if i = π 1 (s) then q + s S i = q + 0 = q. Moreover q + s S π1(s) = q + 1 is a vector that has a 2 exactly at index π 2 (q), and it is 1 in all other positions. Thus, the vector v (q,s) has a 2 exactly at position (π 1 (s) − 1)|Q| + π 2 (q) and it is either 0 or 1 in every other position. Now, lets denote by o a vector in Q |Q||Σ| that has a 1 in every position and consider the following affine transformation DISPLAYFORM9 Vector g 1 ([ q, s]) has a 1 only at position (π 1 (s) − 1)|Q| + π 2 (q) = π(q, s) and it is less than or equal to 0 in every other position. Thus, to construct f 1 (·) we apply the piecewise-linear sigmoidal activation σ(·) (see Equation ) to obtain DISPLAYFORM10 which is what we wanted. Now, to show, lets denote by M δ a matrix of dimensions (|Q||Σ|) × (2|Q||Σ|) constructed as follows. For (q, s) ∈ Q × Σ, if δ(q, s) = (p, r, m) then M δ has a 1 at position (π(q, s), π (p, r, m)) and it has a 0 in every other position, that is DISPLAYFORM11 It is straightforward to see that (q, s) M δ = δ(q, s), and thus we can define f 2 (·) as DISPLAYFORM12 To show, consider the matrix A of dimensions (2|Q||Σ|) × (|Q| + |Σ| + 1) such that DISPLAYFORM13 Then we define f 3 (·) as DISPLAYFORM14 We are now ready to begin with the proof of the lemma. Recall that a 1 i is given by a DISPLAYFORM15 We need to construct a function O 1: DISPLAYFORM16 We first use function h 1 (·) that works as follows. Lets denote bym (i−1) the value DISPLAYFORM17 where g 1 (·) is the function defined above in Equation FORMULA79. It is clear that h 1 (·) is an affine transformation. Moreover, we note that except for g 1 ([ DISPLAYFORM18) are between 0 and 1. Thus if we apply function σ(·) to h 1 (a DISPLAYFORM19 is the vector with only zeros, then score ϕ (Q 2 (z 1 i), K 2 (z 1 j)) = 0 for every j ∈ {0, . . ., i}. Thus, we have that the attention Att(Q 2 (z DISPLAYFORM20) that we need to compute is just the average of all the vectors in V 2 (Z DISPLAYFORM21 which is exactly what we wanted to show. Proof of Lemma B.4. Recall that z 2 i is the following vector z DISPLAYFORM22 We need to construct functions Q 3 (·), K 3 (·), and V 3 (·) such that DISPLAYFORM23 We first define the query function Q 3: DISPLAYFORM24 Now, for every j ∈ {0, 1, . . ., i} we define DISPLAYFORM25 ] It is clear that the three functions are linear transformations and thus they can be defined by feedforward networks. Consider now the attention Att(Q 3 (z DISPLAYFORM26 . In order to compute this value, and since we are considering hard attention, we need to find the value j ∈ {0, 1, . . ., i} that maximizes DISPLAYFORM27 ). Actually, assumming that such value is unique, lets say j, then we have that DISPLAYFORM28 We next show that given our definitions above, it always holds that j = (i + 1) and then V 3 (z 2 j) is exactly the vector that we wanted to obtain. To simplify the notation, we denote by χ Now, by our definition of Q 3 (·) and K 3 (·) we have that DISPLAYFORM29 where ε k = 1 (k+1). We next prove the following auxiliary property. If j 1 is such that c (j1) = c (i+1) and j 2 is such that DISPLAYFORM30 In order to prove, assume first that j 1 ∈ {0, . . ., i} is such that c (j1) = c (i+1). Then we have that |c (i+1) − c (j1) | ≥ 1 since c (i+1) and c (j1) are integer values. From this we have two possibilities for χ i j1: DISPLAYFORM31 Notice that 1 ≥ ε j1 ≥ ε i > 0. Then we have that ε i ε j1 ≥ (ε i ε j1) 2 > 1 3 (ε i ε j1) 2, and thus DISPLAYFORM32 Finally, and using again that 1 ≥ ε j1 ≥ ε i > 0, from the above equation we obtain that DISPLAYFORM33 Thus, we have that if DISPLAYFORM34 Now assume j 2 ∈ {0, . . ., i} is such that c (j2) = c (i+1). In this case we have that DISPLAYFORM35 We showed that if c DISPLAYFORM36 This completes the proof of the property in. We have now all the necessary to prove that arg min j |χ i j | = (i + 1). Recall first that (i + 1) is defined as DISPLAYFORM37 in other case. Assume first that there exists j ≤ i such that c (j) = c (i+1). By we know that arg min j∈{0,...,i} DISPLAYFORM38 On the contrary, assume that for every j ≤ i it holds that c (j) = c (i+1). We will prove that in this case |χ for every j ≤ i, then c (i+1) is a cell that has never been visited before by M. Given that M never makes a transition to the left of its initial cell, then cell c (i+1) is a cell to the right of every other previously visited cell. This implies that c (i+1) > c (j) for every j ≤ i. Thus, for every j ≤ i we have c DISPLAYFORM39 Moreover, notice that if j < i then ε j > ε i and thus, if j < i we have that DISPLAYFORM40 The formulas of the Neural GPU in detail are as follows (with S 0 the initial input tensor): DISPLAYFORM41 With U (·), R(·), and F (·) defined as DISPLAYFORM42 Consider now an RNN encoder-decoder N of dimension d and composed of the equations DISPLAYFORM43 with h 0 = 0 and g 0 = h n where n is the length of the input. We construct a Neural GPU network NGPU that simulates N as follows. Assume that the input of N is X = (x 1, . . ., x n). Then we first construct the sequence X = (x 1, . . ., x n) such that x i = [x i, 0, 0, 1, 1, 0] with 0 ∈ Q d the vector with all values as 0. Notice that x i ∈ Q 3d+3, moreover it is straightforward that if x i was constructed from an embedding function f: Σ → Q d applied to a symbol a ∈ Σ, then x i can also be constructed with an embedding function f: DISPLAYFORM0 We consider an input tensor S ∈ Q n×1×3d+3 such that for every i ∈ {1, . . ., n} it holds that S i,1,: = x i = [x i, 0, 0, 1, 1, 0]. Notice that since we picked w = 1, our tensor S is actually a 2D grid. Our proof shows that a bi-dimensional tensor is enough for simulating an RNN.We now describe how to construct the kernel banks K U, K R and K F of shape (2, 1, 3d + 3, 3d + 3).Notice that for each kernel K X we essentially have to define two matrices K X 1,1,:,: and K X 2,1,:,: each one of dimension (3d + 3) × (3d + 3). We begin by defining every matrix in K F as block matrices. When defining the matrices, all blank spaces are considered to be 0. DISPLAYFORM1 where F 1 and F 2 are 3 × 3 matrices defined by Before continuing with the proof we note that for every kernel K X and tensor S we have that We now prove that the following properties hold for every t ≥ 0: DISPLAYFORM0 where α k j is given by the recurrence α DISPLAYFORM1 That is, we are going to prove that our construction actually simulates N. By one can see that the intuition in our construction is to use the first d components to simulate the encoder part, the next d components to communicate data between the encoder and decoder simulation, and the next d components to simulate the decoder part. The last three components are needed as gadgets for the gates to actually simulate a sequencial read of the input, and to ensure that the hidden state of the encoder and decoder are updated properly. We prove the above statement by induction in t. First notice that the property trivially holds for S 0.Now assume that this holds for t − 1 and lets prove it for t. We know that U t is computed as DISPLAYFORM2 Thus we have that: DISPLAYFORM3 By the induction hypothesis we have DISPLAYFORM4 Now, notice that K for i = t − 1 σ FIG2 for i = t σ FIG2 for i > t We are almost done with the inductive step, we only need to compute σ((K F * (R t S t−1)) i,1,:).Given what we have for R t and S t−1 we have that R and then, T i,:,: = T i+p,:,:.Consider now an arbitrary uniform Neural GPU that processes tensor S above, and assume that S 1, S 2,..., S r is the sequence produced by it. Next we prove that for every t and for every i it holds that S t i,:,: = S t i+p,:,:. We prove it by induction in t. For the case S 0 it holds by definition. Thus assume that S t−1 satisfies the property. Let DISPLAYFORM5 Since we are considering uniform Neural GPUs, we know that there exist three matrices B U, B This completes the first part of the proof. We have shown that if the input of a uniform neural GPU is periodic, then the output is also periodic. We make a final observation. Let N be a uniform Neural GPU, and S ∈ Q kp×w×d be a tensor such that S i,:,: = S i+p,:,: for every i. Moreover, let T ∈ Q k p×w×d be a tensor such that T i,:,: = T i+p,:,:for every i, and assume that S 1:p,:,: = T 1:p,:,:. Lets S 1, S 2,... and T 1, T 2,... be the sequences produced by N. Then with a similar argument as above it is easy to prove that for every t it holds that S t 1:p,:,: = T t 1:p,:,:. From this it is easy to prove that uniform Neural GPUs will no be able to recognize the length of periodic inputs. Thus assume that there is a language recognizer A defined by of a uniform neural GPU N such that L(A) contains all strings of even length. Assume that u is an arbitrary string in Σ such that |u| = p with p an odd number, and let w = uu and w = uuu. Notice that |w| = 2p and thus w ∈ L(A), but |w | = 3p and thus w ∈ L(A).Let f: Σ → Q d and let X = f (w) = (x 1, x 2, . . ., x 2p) and X = f (w) = (x 1, x 2, . . ., x 3p).Consider now the tensor S ∈ Q 2p×w×d such that S i,1,: = x i for i ∈ {1, . . ., 2p}, thus S i,:,: = S i+p,:,:. Similarly, consider T ∈ Q 3p×w×d such that such that T i,1,: = x i for i ∈ {1, . . ., 3p}, and thus T i,:,: = T i+p,:,:. Notice that S 1:p,:,: = T 1:p,:,: then by the property above we have that for every t it holds that S. From this we conclude that the outputs of N for both inputs X and X are the same, and thus if A accepts w then A accepts w which is a contradiction.

Represent the short summary for finding the corresponding scientific article (long)!

We show that the Transformer architecture and the Neural GPU are Turing complete.

represent this text to find a much much longer article about it with say hundreds-thousands of words

This work aims to provide quantitative answers to the relative importance of concepts of interest via concept activation vectors (CAV). In particular, this framework enables non-machine learning experts to express concepts of interest and test hypotheses using examples (e.g., a set of pictures that illustrate  the concept). We show that CAV can be learned given a relatively small set of examples. Hypothesis testing with CAV can answer whether a particular concept (e.g., gender) is more important in predicting a given class (e.g., doctor) than other sets of concepts. Interpreting networks with CAV does not require any retraining or modification of the network.


Question: Represent the article for finding a single-sentence TLDR

Question: It is usually hard for a learning system to predict correctly on the rare events, and there is no exception for segmentation algorithms. Therefore, we hope to build an alarm system to set off alarms when the segmentation is possibly unsatisfactory. One plausible solution is to project the segmentation into a low dimensional feature space, and then learn classifiers/regressors in the feature space to predict the qualities of segmentation . In this paper, we form the feature space using shape feature which is a strong prior information shared among different data, so it is capable to predict the qualities of segmentation given different segmentation algorithms on different datasets. The shape feature of a segmentation is captured using the value of loss function when the segmentation is tested using a Variational Auto-Encoder(VAE). The VAE is trained using only the ground truth masks, therefore the bad segmentation with bad shapes become the rare events for VAE and will in large loss value. By utilizing this fact, the VAE is able to detect all kinds of shapes that are out of the distribution of normal shapes in ground truth (GT). Finally, we learn the representation in the one-dimensional feature space to predict the qualities of segmentation . We evaluate our alarm system on several recent segmentation algorithms for the medical segmentation task. The segmentation algorithms perform differently on different datasets, but our system consistently provides reliable prediction on the qualities of segmentation . A segmentation algorithm usually fails on the rare events, and it is hard to fully avoid such issue. The rare events may occur due to the limited number of training data. To handle it, the most intuitive way is to increase the number of training data. However, the labelled data is usually hard to collect, e.g., to fully annotate a 3D medical CT scan requires professional radiology knowledge and several hours of work. In addition, the human labelling is unable to cover all possible cases. Previously, various methods have been proposed to make better use of training data, like sampling strategies paying more attention to the rare events BID17. But still it may fail on the rare events which never occur in the training data. Another direction is to increase the robustness of the segmentation algorithm to the rare events. BID6 proposed the Bayesian neural network which can model the uncertainty as an additional loss to make the algorithm more robust to noisy data. These kinds of methods make the algorithm insensitive to certain types of perturbations, but the algorithms may still fail on other perturbations. Since it is hard to completely prevent the segmentation algorithm from failure, we consider to detect the failure instead: build up an alarm system cooperating with the segmentation algorithm, which will set off alarms when the system finds that the segmentation is not good enough. This task is also called as quality assessment. Several works have been proposed in this field. BID5 applied Bayesian neural network to capture the uncertainty of the segmentation and set off alarm based on that uncertainty. However, this system also suffers from rare events since the segmentation algorithms often make mistakes confidently on some rare events . BID8 provided an effective way by projecting the segmentation into a feature space and learn from this low dimension space. They manually design several heuristic features, e.g., size, intensity, and assume such features would indicate the quality of the segmentation . After projecting the segmentation into the feature space, they learned a classifier to CT image GT Recon-Prediction Recon-GT Prediction Entropy Alea-Uncertainty Epis-Uncertainty Figure 1: The visualize on an NIH CT dataset for pancreas segmentation. The figures ReconPrediction and Recon-GT are reconstruction from prediction and GT by VAE network respectively. The Dice score between the GT and prediction is 47.06 while the Dice score between the prediction and Recon-Prediction is 47.25. In our method, we use the later Dice score to predict the former real Dice score which is usually unknown at inference phase in real applications. This case shows how these two Dice scores are related to each other. On the other hand, for uncertainty based methods, different kinds of uncertainty distribute mainly on the boundary of predicted mask, which makes it a vague information when detecting the failure cases.predict its quality. Since the feature space is of relative low dimension now, it is able to distinguish good segmentation from bad ones directly. In a reasonable feature space, when the segmentation algorithm fails, the failure output will be far from the ground truth. So the main problems is what these good features are and how to capture them. Many features that BID8 selected are actually less related with the quality of segmentation , e.g., size. In our system, we choose a more representative feature, i.e., the shape feature. The shape feature is important because the segmenting objects (foreground in the volumetric mask) often have stable shapes among different cases, especially in 3D. So the shape feature is supposed to provide a strong prior information for judging the quality of a segmentation , i.e., bad segmentation tend to have bad shapes and vice versa. Furthermore, to model the prior from the segmentation mask space is much easier than in the image space and the shape prior can be shared among different datasets while the features like image intensity are affected by many factors. That means the shape feature can deal with not only rare events but also different data distributions in the image space, which shows great generalization power and potential in transfer learning. We propose to use the Variational Auto-Encoder(VAE) BID7 to capture the shape feature. The VAE is trained on the ground truth masks, and afterwards we define the value of the loss function as the shape feature of a segmentation when it is tested with VAE network. Intuitively speaking, after the VAE is trained, the bad segmentation with bad shapes are just rare events to VAE because it is trained using only the ground truth masks, which are under the distribution of normal shapes. Thus they will have larger loss value. In this sense we are utilizing the fact that the learning algorithms will perform badly on the rare events. Formally speaking, the loss function, known as the variational lower bound, is optimized to approximate the function log P (Y) during the training process. So after the training, the value of the loss function given a segmentation Ŷ is close to log P (Ŷ), thus being a good definition for the shape feature. In this paper, we proposed a VAE-based alarm system for segmentation algorithms. The qualities of the segmentation can be well predicted using our system. To validate the effectiveness of our alarm system, we test it on multiple segmentation algorithms. These segmentation algorithms are trained on one dataset and tested on several other datasets to simulate when the rare events occur. The performance for the segmentation algorithms on the other datasets (rather than the training dataset) drops quickly but our system can still predict the qualities accurately. We compare our system with other alarm systems on the above tasks and our system outperforms them by a large margin, which shows the importance of shape feature in alarm system and the great power of VAE in capturing the shape feature.2 RELATED WORK BID6 employed Bayesian neural network (BNN) to model the aleatoric and epistemic uncertainty. Afterwards, BID9 applied the BNN to calculate the aleatoric and epistemic uncertainty on medical segmentation tasks. BID5 utilized the BNN and model another kind of uncertainty based on the entropy of segmentation . They calculated a doubt score by summing over weighted pixel-vise uncertainty. However we can see from Figure 1 that when the segmentation algorithm fails to provide correct prediction, the uncertainty still distributes mainly on the boundary of the wrong segmentation , which means the algorithm is strongly confident on where it makes mistakes. Other method like Valindria et al. FORMULA0 used registration based method for quality assessment. It is a reliable method because it takes the prior of image by setting up a reference dataset. The problem of this method is inefficient testing. Every single case needs to do registration with all reference data to determine the quality but registration on 3D image is usually slow. Also the registration based method can hardly be transferred between datasets or modalities. Chabrier et al. FORMULA1 and BID3 use unsupervised method to estimate the segmentation quality using geometrical and other features. However the application in medical settings is not clear. Also BID14 tried a simple method using image-segmentation pair to directly regress the quality. Kohlberger et al. FORMULA0 introduced a feature space of shape and appearance to characterize a segmentation. The shape features in their system contain volume size, surface area, which are not necessarily related with the quality of the segmentation . In our work we choose to learn a statistical prior of the segmentation mask and then determine the quality by how well a mask fits the prior. This is related with Out-of-Distribution (OOD) detection. Previous works in this field BID4 ) BID10 ) made use of the softmax output in the last layer of a classifier to calculate the out-of-distribution level. In our case, however, for a segmentation method, we can only get a voxel-wise out-of-distribution level using these methods. How to calculate the out-of-distribution level for the whole mask becomes another problem. In addition, the segmentation algorithm can usually predict most of voxels correctly with a high confidence, making the out-of-distribution level on those voxels less representative. Auto-Encoder(AE), as a way of learning representation of data automatically, has been widely used in many areas such as anomaly detection BID21, dimension reduction, etc. Variational autoencoder(VAE) BID7, compared with AE, can better learn the representation for the latent space. We employ VAE to learn the shape representation from the volumetric mask. Unlike method of BID18 which needs to pre-train with RBM, VAE can be trained following an end-to-end fashion. BID13 learned the shape representation from point cloud form, while we choose the volumetric form as a more natural way to corporate with segmentation task. utilizes AE to evaluate difference between prediction and ground truth but not in an unsupervised way. We first define our task formally. Denote the datasets we have as (X, Y), where Y is the label set of X. We divide (X, Y) into training set (X t, Y t) and validation set (X v, Y v). Suppose we have a segmentation algorithms F trained on X t. Usually we validate the performance of F on X v using Y v. Now we are doing this task without Y v. Formally, we try to find a function L such that DISPLAYFORM0 where L is a function used to calculate the similarity of the segmentation F (X) respect to the ground truth Y, i.e., the quality of F (X). How to design L to take valuable information from F and X, is the main question. Recall that the failure may happen when X is a rare event. But to detect whether a image X is within the distribution of training data is very hard because of the complex structure of image space, and actually that is what F is trained to learn. In uncertainty based method BID5 and BID9, the properties of F is encoded by sampling the parameters of F and calculating the uncertainty of output. The uncertainty does help predict the quality but the performance strongly relies on F. It requires F to have Bayesian structure, which is not in our assumption and for a well-trained F. The uncertainty will mainly distribute on the boundary of segmentation prediction. So we change the formulation above to DISPLAYFORM1 By adding this constrain, we still take the information from F and X, but not in direct way. The most intuitive idea to do is directly applying a regression algorithm on the segmentation to predict the quality. But the main problem is that the regression parameters trained with a certain segmentation algorithm F highly relate with the distribution of F (X), which varies from different F.Following the idea of BID8, we apply a two-step method, where the first one is to encode the segmentation F (X) into the feature space, and the second one is to learn from the feature space to predict the quality of F (X). We propose a novel way of capturing the shape feature from F (X), denoting as S(F (X); θ). Finally it changes to DISPLAYFORM2 The shape feature is captured from Variational Autoencoder (VAE) trained with the ground masks Y ∈ Y t. Here we define the shape of the segmentation masks as the distribution of the masks in volumetric form. We assume the normal label Y obeys a certain distribution P (Y). For a predictive maskŷ, its quality should be related with P (Y =ŷ). Our goal is to estimate the function P (Y).Recall the theory of VAE, we hope to find an estimation function Q(z) minimizing the difference between Q(z) and P (z|Y), where z is the variable of the latent space we want encoding Y into, i.e. optimizing DISPLAYFORM0 KL is Kullback-Leibler divergence. By replacing Q(z) with Q(z|Y), finally it would be deduced to the core equation of VAE BID2. DISPLAYFORM1 where P (z) is the prior distribution we choose for z, usually Gaussian, and Q(z|Y), P (Y |z) correspond to encoder and decoder respectively. Once Y is given, log P (Y) is a constant. So by optimizing the RHS known as variational lower bound of log P (Y), we optimize for KL[Q(z)||P (z|Y)].Here however we are interested in P (Y). By exchanging the second term in LHS with all terms in RHS in equation FORMULA4, we rewrite the training process as minimizing DISPLAYFORM2 We denote DISPLAYFORM3 as S(Y ; θ) for brevity. It shows that the training process is actually learning a function to best fit log P (Y) over the distribution of Y. After training VAE, S(Y ; θ) becomes a natural approximation for log P (Y). So we just choose S(Y ; θ) as our shape feature. In this method we use Dice Loss BID11 when training VAE, which is widely used in medical segmentation task. The final form of S is DISPLAYFORM4 where encoder µ, Σ and decoder g are controlled by θ, and λ is a coefficient to balance the two terms. The first term is the Dice's coefficient between Y and g(z), ranging from 0 to 1 and equal to 1 if Y and g(z) are equal. If we look at the shape feature closely, it indicates that after VAE is trained using data with only normal shape, the predictive maskŷ tends to be more likely in the distribution of normal shape if it can achieve less reconstruction error and is closer to prior distribution in the latent space, since log P (ŷ) ≥ S(ŷ; θ) holds all the time. On the other hand, for cases with high P (ŷ) but low S(ŷ; θ), it would introduce a large penalty to the object function, and is less likely to occur for a well-trained VAE. We assume that the shape feature is good enough to obtain reliable quality assessment. Intuitively thinking, for a segmentation F (X), the higher log P (F (X)) is, the better shape F (X) is in and thus the higher L(F (X), Y ) is. Formally, taking the shape feature in section 3.1, we can predict the quality by fitting a function L such that DISPLAYFORM0 Here the parameter θ is learned by training the VAE, using labels in the training data Y t, and is then fixed during the step two. We choose L to be a simple linear model, so the energy function we want to optimize is DISPLAYFORM1 We only use linear regression model because the experiments show strong linear correlation between the shape features and the qualities of segmentation . L is the Dice's coefficient, i.e. DISPLAYFORM2 In step one, the VAE is trained only using labels in training data. Then in step two θ is fixed. To learn a, b, the standard way is to optimize the energy function in 3.2 using the segmentation on the training data, i.e. arg min DISPLAYFORM0 Here the segmentation algorithm F we use to learn a, b is called the preparation algorithm. If F is trained on X t, the quality of F (X) would be always high, thus providing less information to regress a, b. To overcome this, we use jackknifing training strategy for F on X t. We first divide X t into X 1 t and X 2 t. Then we train two versions of F on X t \ X 1 t and X t \ X 2 t respectively, say F 1 and F 2. The optimizing function is then changed to arg min DISPLAYFORM1 In this way we solve the problem above by simulating the performance of F on the testing set. The most accurate way is to do leave-one-out training for F, but the time consumption is not acceptable, Table 1: Comparison between our method and baseline methods. The BNN is trained on NIH and tested on all three other datasets. Then, the segmentation are evaluated by 4 methods automatically without using ground truth. Of the 4 methods, ours achieves the highest accuracy and the highest correlation between predicted Dice score and real Dice score.and two-fold split is effective enough according to experiments. When the training is done, we can test on any segmentation algorithm F and data X to predict the quality Q = aS(F (X); θ) + b. In this section we test our alarm system on several recent algorithms for automatic pancreas segmentation that are trained on a public medical dataset. Our system obtains reliable predictions for the qualities of segmentation . Furthermore the alarm system remains effective when the segmentation algorithms are tested on other datasets. We show better quality assessment capability and transferability compared with uncertainty-based methods and direct regression method. The quality assessment are evaluated using mean of absolute error (MAE), stand deviation of residual error (STD), pearson correlation (P.C.) and spearman correlation (S.C.) between the real quality (Dice's coefficient) and predictive quality. We adopt three public medical datasets and four recent segmentation algorithms in total. All datasets consist of 3D abdominal CT images in portal venous phase with pancreas region fully annotated. The CT scans have resolutions of 512 × 512 × h voxels with varying voxel sizes.• NIH Pancreas-CT Dataset (NIH). The NIH Clinical Center performed 82 abdominal 3D CT scans BID15 from 53 male and 27 female subjects. The subjects are selected by radiologist from patients without major abdominal pathologies or pancreatic cancer lesions.• Medical Segmentation Decathlon (MSD). Table 2: Different algorithms tested on different datasets are evaluated by our alarm system. Without tuning parameters, the system can be directly applied to evaluate other segmentation algorithms• Multi-atlas Labeling Challenge (MLC). The multi-atlas labeling challenge provides 50 (30 Training +20 Testing) abdomen CT scans randomly selected from a combination of an ongoing colorectal cancer chemotherapy trial and a retrospective ventral hernia study 2.The testing data for the last two datasets is not used in our experiment since we have no annotations for these cases. The segmentation algorithms we choose are V-Net BID11, 3D Coarse2Fine BID20, Deeplabv3, and 3D Coarse2Fine with Bayesian structure BID9. The first two algorithms are based on 3D networks while the Deeplab is 2D-based. The 3D Coarse2Fine with Bayesian structure is employed to compare with uncertainty based method and we denote it as Bayesian neural network (BNN) afterwards. We compare our method with three baseline methods. Two of them are based on uncertainty and the last one directly applies regression network on the prediction mask to regress quality in equation.• Entropy Uncertainty. BID5 calculated the pixel-vise predictive entropy using Bayesian inference. Then, the uncertainty is summed up over whole imagxe to get the doubt score and the doubt score would replace the shape feature in to regress the quality. They sum is weighed by the distance to predicted boundary, which somehow alleviates the bias distribution of uncertainty. Their method is done in 2D image and here we just transfer it to 3D image without essential difficulty.• Aleatoric and Epistemic Uncertainty. BID9 divided the uncertainty into two terms called aleatoric uncertainty and epistemic uncertainty. We implement both terms and calculate the doubt score in the same way as BID5 because the original paper does not provide a way. The two doubt scores are used in predicting the quality.• Direct Regression. A regression neural network is employed to directly learn the quality of predictive mask. The training data for this network is the prediction of segmentation algorithm F on X t and the real Dice's coefficient between the predictive mask and label mask is used as the supervision. For data pre-processing, since the voxel size varies from case to case, which would affect the shape of pancreas and prediction of segmentation, we first re-sample the voxel size of all CT scans and annotation mask to 1mm×1mm×1mm. For training VAE, we apply simple alignment on the annotation mask. We employ a cube bounding box which is large enough to contain the whole pancreas region, centered at the pancreas centroid, then crop both volume and label mask out and resize it to a fixed size 128×128×128. We only employ a simple alignment because the human pose is usually fixed when taking CT scan, e.g. stance, so that the organ will not rotate or deform heavily. For a segmentation prediction, we also crop and resize the predictive foreground to 128 × 128 × 128 and feed it into VAE to capture the shape feature. During the training process, we employ rotation along x,y,z axes for −10,0,10 degree respectively and random translation for smaller than 5 voxel on annotation mask as data augmentation. This kind of mild disturbance can enhance the data distribution but keep the alignment property of our annotation mask. We tried different dimension of latent space and finally set it to 128. We found that with VAE with latent space of different dimension will have different capability in quality assessment. The hyper parameter λ in object function of VAE is set to 2 −5 to balance the small value of Dice Loss and large KL Divergence. We trained our network by SGD optimizer with batch size 4. The learning rate for training VAE is fixed to 0.1. We build our framework and other baseline model using TensorFlow. All the experiments are run on NVIDIA Tesla V100 GPU. The first training step is done in total 20000 iterations and takes about 5 hours. We split NIH data into four folds and three of them are used for training segmentation algorithms and our pipeline; the remaining one, together with all training data from MSD and MLC forms the validation data to evaluate our evaluation method. First we learn the parameter of VAE using the training label of NIH dataset. Then we choose BNN as the preparation algorithm. The training strategy in section 3.3 is applied on it to learn the parameters of regression. For all the baseline methods, we employ the same training strategy of jackknifing as in our method and choose the BNN as preparation algorithm for fair comparison. Finally we predict the quality of predictive mask on the validation data for all the segmentation algorithms. Note that all segmentation algorithms are trained only on the NIH training set. Table 1 reports the of using three baseline models and our method to evaluate the BNN model tested on three datasets. In general, our method achieves the lowest error and variance on all datasets. In our experiment, the BNN achieves 82.15, 57.10 and 66.36 average Dice score tested on NIH, MSD and MLC datasets respectively. The segmentation algorithm trained on NIH will fail on some cases of other datasets and that is why we need the alarm system. The spearman coefficient for direct regression method on NIH dataset is close to 0 because the testing on NIH are all of high quality and the regression is not sensitive to slight variation in quality. Uncertainty based methods can better predict the quality but as shown in Figure 1, the uncertainty mainly distributes on the boundary of predictive mask but not on the missing parts or false positive parts. When the BNN is tested on the other two datasets, our method remains stable in predicting the quality. Table 2 shows the quality assessment for 4 different segmentation algorithms. For each segmentation algorithm, When evaluating the segmentation from DeepLab algorithm tested on MLC dataset, the accuracy is lower but the correlation between the predictive quality and real quality is high. In the paper we present a VAE based alarm system for segmentation algorithms which predicts the qualities of the segmentation without using ground truth. We claim that the shape feature is useful in predicting the qualities of the segmentation . To capture the shape feature, we train a VAE using only ground truth masks. We utilize the fact that rare events will achieve larger value for loss function, and successfully detect the out-of-distribution shape according to the value for loss function in the testing time. In the second step we collect the segmentation of the segmentation algorithm on the training data and extract the shape feature of them to learn the parameters of regression. By applying jackknifing training on the segmentation algorithm, we will get segmentation of different qualities on the training data, therefore obtain more accurate regression parameters. The reliable quality assessment prove both that the shape feature capturing from VAE is meaningful and that the shape feature is useful for quality assessment in the segmentation task. Furthermore, our proposed method outperforms the uncertainty based methods and direct regression method, and possesses better transferability to other datasets and other segmentation algorithms.

represent this text to find a much much longer article about it with say hundreds-thousands of words

We use VAE to capture the shape feature for automatic segmentation evaluation

Represent the short summary for finding the corresponding scientific article (long)

We propose a method that extracts the uncertainties of features in each layer of DNNs and combines them for detecting OOD samples when solving classification tasks.