L ANGUAGE MODELING USING T ENSOR T RAINS
Anonymous authors
Paper under double-blind review
A BSTRACT
Tensor networks have previously been shown to have potential in language modeling in theory but lack practical evidence support.
We propose a novel Tensor Train
Language Model (TTLM) based on Tensor-Train decomposition.
To show the usefulness of TTLM, we perform a principled experimental evaluation on real-world language modeling tasks, showing that our proposed variants, TTLM-Large and
TTLM-Tiny, can be more effective than Vanilla RNNs with low-scale of hidden sizes.
Also, we demonstrate the relationship between TTLM and Second-order
Recurrent Neural Networks (RNNs), Recurrent Arithmetic Circuits, and Multiplicative Integration RNNs in the sense that the architectures of all of these are, essentially, special cases of that of TTLM.
I NTRODUCTION
A language model assigns probabilities of sequences of words from the vocabulary V ; the number of texts increases exponentially w.r.t to length N .
Hence the domain of a language model is, by definition, the exponential space V N .
However, due to the vanilla exponential space being intractable, existing work tends to use recurrent or auto-regressive architectures to generate conditional probabilities based on the context (typically encapsulated as a fixed-length dense vector).
This indeed simplifies the calculation.
Recently, researchers (Pestun & Vlassopoulos, 2017; Miller et al., 2021; Zhang et al., 2019) have reconsidered the view of language models as joint probabilities of text, as it leads to exponential representations in tensor space.
Word connections could be preserved in the exponential tensor space when measuring joint probabilities.
To deal with the exponential space complexity, a mathematical tool called ‘tensor network’ 2 has been used to reduce the exponential space of language modeling to a tractable one (Pestun & Vlassopoulos, 2017).
However, the so-called ‘tensor network language model’ in Pestun & Vlassopoulos (2017) is currently a concept that needs to be proved practically.
As proof-of-concept work, we derive a Tensor Train Language Model (TTLM)
(the simplest tensor network).
Technically, we represent a sentence based on the exponential semantic space constructed by the tensor product of word representations.
The probability of the sentence is obtained by the inner product of two high-dimensional tensors: the input Φ( X ) and the global coefficients A .
Under the framework of TTLM, we propose two variants: TTLM-Tiny and TTLM-Large.
Also, we clarify the relationship between the proposed TTLM and a series of Recurrent Neural Networks (RNNs) (i.e., Second-order RNNs (Goudreau et al., 1994), Recurrent Arithmetic Circuits (RACs) (Levine et al., 2018), and Multiplicative Integration RNNs (MI-RNNs)
(Wu et al., 2016)).
These connections open a new eye to understanding RNNs and give some natural implementations for
TTLM.
We benchmark these TTLM variants and analyze the difference in their working mechanism and behaviors.
Experimental results on language modeling tasks show that our TTLM variants could outperform than Vanilla-RNNs under the same training setting.
These demonstrate the feasibility of
TTLM.
The main contributions of our work can be summarized as follows:
We propose a novel Tensor Train Language Model, as a first attempt to apply tensor networks on real-world language modeling tasks.
We propose two novel TTLM variants, TTLM-Large and TTLM-Tiny, and theoretically demonstrate the relationship between TTLM and a series of existing RNNs.
Compared to Vanilla-RNNs on WikiText-2 and PTB datasets, TTLM-Large reduces perplexity by 14.3 and 16.0, respectively, and TTLM-Tiny reduces perplexity by 1.7 and 8.5, respectively.
R ELATED WORK
Previous studies on tensor networks in machine learning have mainly been devoted to analyzing the theoretical properties of neural networks.
A better understanding of feed-forward, convolutional and recurrent architectures has been gained, including compression parameters (Novikov et al., 2015), expressive power (Cohen et al., 2016; Cohen & Shashua, 2016;
Khrulkov et al., 2018), and depth efficiency for long-term memory (Levine et al., 2018).
Focusing on natural language modeling, certain studies have tensorized existing network architectures (Novikov et al., 2015), while few studies have applied tensor networks alone as a language model.
To the best of our knowledge, tensor network language models have remained a theoretical proposal instead of an empirical model (Pestun & Vlassopoulos, 2017; Pestun et al., 2017).
Perhaps,
Miller et al.
(2021) is the only other work that uses tensor networks for probabilistic sequence modeling, while it fails to scale up its model for real-world sequence modeling tasks.
We first derive a tensor network language model in the way that it can be applied to real-world language modeling datasets, while its variants outperform Vanilla RNNs with lower-scale hidden sizes.
P RELIMINARIES
We briefly recapitulate basic notions and notations 3 ; full technical introductions can be found in standard textbooks (e.g., Bi et al.
; Itskov (2009)).
Notation.
For the purposes of this paper, every tensor A is a multidimensional array of elements (called components ) of R , each denoted by its integer coordinates in the array; e.g., for a twodimensional array, the component at position i, j ∈ N is denoted A ij .
The order of a tensor is how many indices it has (e.g., a vector v is a first-order tensor, a matrix M is a second-order tensor, etc.).
The dimension of a tensor refers to the number of values that a particular index (or so-called mode ) can take, e.g., the dimension of B ∈ R I
×
I
×
I 3 is I
1 ×
I
×
I 3 .
Tensor product.
For two tensors C ∈ R I 1 ×···× I j (order j ) and D ∈ R
I j +1 , ×···× I j + k
(order k ), their tensor product is denoted by ⊗ and return a tensor E i 1 ··· i j + k = C i 1 ...i j · D i j +1 ··· i j + k (order j + k ).
Generalized inner product.
For two tensor X , Y ∈ R I
×
I 2 ×···× I N of the same size, their inner product is defined as ⟨ X , Y ⟩ = (cid:80)
I 1 i 1 =1 (cid:80) I 2 i 2 =1 · · · (cid:80) I N i N =1 X i 1 ,i 2 ,...,i N Y i 1 ,i 2 ,...,i N .
For two tensors
X ∈ R
I
×
I 2 ×···×
I N × I x and Y ∈ R
I
×
I 2 ×··· I N × I y sharing N modes of the same size, the “generalized inner product” defined in (Kossaifi et al., 2020) is calculated as ⟨ X , Y ⟩ N =
I 1 (cid:88) i 1 =
I 2 (cid:88) i 2 = · · ·
I N (cid:88) i N =
X i 1 ,i 2 ,...,i N Y i 1 ,i 2 ,...,i N with ⟨ X , Y ⟩ N ∈
R
I x
× I y .
L ANGUAGE M ODELING USING T ENSOR T RAINS
We introduce a language model in tensor space in Sec. 4.1.
We define our general Tensor Train
Language Model in Sec. 4.2, and its special case, TTLM, in Sec. 4.3.
Vector
Matrix
Order-3 tensor 𝑖 ∈ [𝐼 ! ]
𝑖 ∈ [𝐼 ! ]
𝑗 ∈ [𝐼 " ] a) =
𝑖 ∈ [𝐼 ! ]
𝑗 ∈ [𝐼 " ] 𝑘 ∈
[𝐼 # ] 𝑗 𝑘 𝑖 𝑗 𝑘 𝐶 !"
= # # $ !
𝑩 !"
# 𝒗 #
Order-N tensor 𝐓 𝑖 % ∈
[𝐼 % ] 𝑖 & ∈
[𝐼 & ] 𝑖 ’(% ∈ [𝐼 ’(% ] 𝑖 ’ ∈
[𝐼 ’ ] b) 𝒗 𝑨 𝐁 𝐁 𝒗 𝑪
Tensor Contraction implies a contraction or connected indices paper, augment our equations with diagrams to make them easier
to
4. L ANGUAGE MODELS IN A TENSOR SPACE
Natural language typically has complex dependencies between features (e.g., tokens or words)
(Hou et al., 2013) 4 that are not captured well by standard methods such as feature concatenation.
One could also see a similar interaction between any arbitrary features in factorization machines (Rendle, 2010).
Suppose a given text consists of N words X
= [ x (1) , x (2) , · · · , x ( N ) ] and let f
i ∈
R
I i be a feature extractor (it can be one-hot encoding or word embedding).
We now define a representation of X designed to capture these dependencies:
[Equation]
where the tensor space is R I 1 ⊗ R I 2 ⊗ · · · ⊗ R I N .
Each component of f i represents independent meaning-bearing units, such as morphemes or latent factors.
For simplicity, we assume that a text shares the same one-hot encoding f
( x ( t ) )
∈ R | V | in later sections.
Consequently, Φ( X ) is a | V | Ndimensional tensor that records all possible combinations of words in X .
Inspired by Kossaifi et al.
; Zhang et al.
(2019), we define a tensor regression model to obtain the estimated probability for each text X :
[Equation]
where ⟨·⟩ denotes the inner product of two same-sized tensors, and A is a regression weight tensor of the same shape as Φ( X ) in the tensor space V ⊗ N = V ⊗ · · · ⊗ V
[Equation]
N where V refers to R | V | .
Similar functions were considered in Novikov et al.
; Stoudenmire & Schwab (2016a); Khrulkov et al.
; Zhang et al.
4. G ENERAL T ENSOR T RAIN L ANGUAGE MODEL
Suppose the sequence of indices of words in the text X is w 1 , w 2 , · · · , w N , where w i ∈ { 1 , 2 , · · · , | V |} and its corresponding weight in A is denoted as A w 1 w 2 ··· w N .
We use TT decomposition to represent A w 1 w 2 ··· w N in the TT format (Oseledets, 2011) as follows:
|𝑉| 𝑅 𝐆 (") 𝒇 𝑥 " … Φ 𝑋 𝒜 |𝑉| 𝐆 𝑅 𝐺 𝑅 |𝑉|
𝐆 ($) 𝒇 𝑥 % 𝒇 𝑥 & a) TTLM 𝑅 𝐖 ’( |𝑉| 𝑅 𝐖 ’( 𝐖 () |𝑉| 𝑅 𝑅 𝑅 c) TTLM-Large b)
TTLM-Tiny 𝐆
𝐆 𝑅 𝑅 𝛅 𝑊 ))
𝑊 ))
𝑅 𝛅 𝑅 𝑅 𝑅 𝑅
[Equation]
where the tensors G ( t ) ∈ R R t − 1 ×| V |× R t ( t = 1 , ..., d , R 0 =
R N = 1 by definition) are called TT cores .
We now combine Φ( X ) and A in the TT format to define general TTLM .
The elements of G ( t ) : ,w t , : in
Eq.
3 can be represented as
[Equation]
where each f ( x ( t ) ) is a one-hot vector having w t = 1 for at most one t , and has zeros elsewhere.
Therefore, one-hot encoding enables us to integrate the input data into the TT format of A by inserting Eq.
4 into Eq.
[Equation]
where Φ( X ) =
N (cid:78) i =1 f ( x ( i ) ) .
The difference between Eq.
5 and Eq.
3 is that Eq.
5 has combined A and Φ( X ) in the low-dimensional form.
This is because that Eq.
3 can compute the elements of A (Oseledets, 2011), and because Φ( X ) here is the tensor product of one-hot vectors, so
that Eq. 5 can compute Eq. 2.
Further, since Eq. 5 now has input data (one-hot vectors) and weights (TT cores), we name Eq.
5 as our general TTLM .
4. TTLM
Here we consider a special class of general TTLM .
Despite its site-dependent TT cores G ( t ) potentially giving it more expressiveness for language modeling, this property currently generates unnecessary obstacles to its applicability, like the choice of R t .
We here provide a detailed explanation of its special case: TTLM.
Definition.
Suppose all the intermediate TT cores are equal to each other G
[Equation]
G (2) , . . .
, G ( N − 1) ∈ R R ×| V |× R and G (1) =
G ( N ) ∈ R | V |× R in Eq.
Then, TTLM is defined as follows:
[Equation]
where its tensor diagram notation is shown in Figure 2a.
Recursive information.
We recursively unfold the calculation of TTLM in Eq. 6 and find that
G has two sources of “input”: the information from the previous recursive unfolding, and the input data f ( x ( t ) )
(see Eq.
15 for a detailed version).
From this perspective, G acts as a bilinear map
G : R | V | × R R → R R , and we can regard the information in the previous step as a hidden state h ( t ) TTLM , given by:
[Equation] [Equation]
where f ( x ( t ) ) , G , and h ( t − 1) TTLM are contracted together (we permute the indices of G from R R ×| V |× R to R | V |× R × R which does not change the number of indices).
Recursive Probability Computation.
Here, we here provide further details about the process of computing p ( X ) by TTLM in practice.
𝐆 (") 𝑓(𝑥 ! )
𝑓(𝑥 " ) Φ 𝑋 ($:&) 𝒜 ($:()
𝒇 𝑥 " 𝒇 𝑥 $ |𝑉| 𝑅 𝑅 𝑅 𝒚
(() |𝑉| 𝒇 𝑥 % 𝐆 𝐆 (&) 𝐆 |𝑉| |𝑉|
TTLM.
Here we provide an example that given the text
[Equation]
where y (4) ∈ V is the probability distribution of word x (4) .
In language modeling, p ( X ) is often decomposed using the chain rule (Bahl et al., 1983) as follows:
[Equation]
where x (1: t − 1) denotes the text [ x (1) , x (2) , · · · , x ( t − 1) ] .
At time t , the output prediction of a model, y ( t ) ∈ V , is a probability distribution of word x ( t ) given x (1: t − 1) .
In TTLM, we define y ( t ) as follows:
[Equation]
where G ( t ) ∈ R | V |× R is the last TT core in TT format at time t .
Such a definition is the same as that of RNNs, which use hidden states and a weight matrix to calculate word probabilities.
Fig.
3 provides a simple example.
We can derive the definition of y ( t ) in high-dimensional space, if we substitute h ( t − 1) TTLM in Eq. 8 by
Eq.
6 and Eq.
[Equation]
where A (1: t ) ∈ V ⊗ t , Φ( X (1: t − 1) )
∈ V ⊗ t − 1 and ⟨·⟩ t − 1 denotes the ”generalized inner product defined” in Preliminary.
Note that Eq.
9 is the low-dimensional form of Eq.
11, similarly to the relationship between Eq.
5 and Eq. 2.
By these definitions, there are some interesting properties of TTLM.
We can use teacher forcing (Jurafsky, 2000) to learn parameters of TT cores.
The hidden-to-output tensor G ( t ) is defined to be the same as
the input-to-hidden tensor G (1) .
3) G and G ( t ) have no parameters in common.
We provide a detailed explanation of the relationship between different TT cores in Appendix A.
TTLM VARIANTS
To show the versatility and practical applicability of the TTLM framework, we now propose two new variants: TTLM-Large and TTLM-Tiny in Sec. 5.1.
In Sec.
5.2, we briefly summarize the relationship between TTLM and some widely-used RNNs.
5. N EW V ARIANTS : TTLM-L ARGE AND TTLM-T INY
The TT core G in TTLM is an entire third-order tensor.
In the two variants, we decompose G into several separate tensors without violating the TT format, as shown in Fig.
2b and Fig.
2c.
We define
TTLM-Tiny and TTLM-Large as follows:
[Equation]
12) where W xe ∈ R | V |× R × R is the input-to-hidden tensor ; W eh ∈ R R × R × R × R ; and δ ∈ R R × R × R × R is a fourth-order diagonal tensor such that δ ijkl =
1 iff the i = j = k = l , and δ ijkl = 0 otherwise.
The relationship between our proposed models and TTLM is as follows:
W xe in both models take the same role as G ( t ) in TTLM (i.e. input-to-hidden and hidden-to-output), while G = W xe δW hh in TTLM-Tiny and G = W xe W eh δW hh in TTLM-Large.
As in RNNs, we compute the conditional probability recursively for TTLM-Large and TTLM-Tiny as:
[Equation]
where V ∈ R R ×| V |× R is an output embedding tensor, and P ∈ R R × R × R is a projector tensor.
Then we tie the input tensor W xe to the output embedding tensor V (we provide a detailed explanation in
Appendix C).
One obvious advantage of our models is to utilize information from the hidden layer and input data separately.
Such interaction, particularly TTLM-Tiny, can potentially avoid overfitting, similarly to
Wu et al.
(2016) where multiplication integration between two sources of ”input” can outperform many other methods.
In Sec 6.2, we provide relevant experimental evidence.
5. E XISTING TTLM VARIANTS
Given the fact that TT scores of TTLM can vary, Appendix B provides a detailed illustration that three existing models, namely second-order RNNs, RACs and MI-RNNs can be considered as one of the ”special” implementations of TTLM.
We briefly summarize the differences between the three models: 1) Second-order RNNs use the third-order T as the TT cores with an activation function given Eq.
14; 2) RACs use W hx ⊙ W hh as the TT cores given Eq.
18; 3) MI-RNNs use W hx ⊙ W hh as the TT cores with an activation function given Eq. 19.
Along with our two proposed models, we study the experimental performance of second-order
RNNs, RACs and MI-RNNs compared to TTLM-Large and TTLM-Tiny in Section 6.
E XPERIMENTAL E VALUATION
To further understand the properties of TTLM variants, we now investigate the effectiveness of
TTLM-Large and TTLM-Tiny
compared to Second-order RNNs, RACs, MI-RNNs, and VanillaRNNs.
We conduct experiments from two distinct perspectives: (1) The rank of TT decomposition
[Table]
6. E XPERIMENTAL SETTING
Tasks, Datasets, and Metrics.
We conduct experiments on word-level language model datasets:
English Penn Treebank (PTB), which consists of 929k training words, 73k validation words, and 82k test words.
It has 10k words in its vocabulary (Marcinkiewicz, 1994).
The WikiText-2 dataset (Merity et al., 2016) is derived from Wikipedia articles and consists of 2088k training words, 217k validation words, 45k test words, and a vocabulary of over 30,000 words.
We compare these models on the language modelling task, evaluated by the Perplexity (PPL) (Meister & Cotterell, 2021): the lower the perplexity, the better the model.
Baselines.
Vanilla RNNs , Second-RNNs , RACs and MI-RNNs are our baselines.
We also provide some original results of RNN-based models as references (Mikolov & Zweig, 2012; Zaremba et al., 2014; Grave et al., 2016; Merity et al., 2017).
The implementation details are introduced in Appendix C.
Hyperparameters.
To compare the effectiveness of comparable models in the same scale: 1) We set the rank/hidden size of TTLM variants/Vanilla-RNNs as [5, 10, 20, 25, 30, 35, 40, 45, 50].
The embedding size of these models is the squared number of hidden sizes/ranks.
To avoid the impact of the large embedding size on the model performance, we also provide several common choices of embedding size in Vanilla-RNNs by setting its embedding size as [100, 200, 300] (we name them as
RNNs-100, RNNs-200, RNNs-300 correspondingly and use them in Fig. 5).
The random seed is fixed to ensure the experimental results are not influenced by initializing the weights.
We train all models for 50 epochs and choose the best model in the validation set to predict the result in the test set.
6. R ANK AND E FFECTIVENESS A NALYSIS
The rank of the TT format has been used to explain the expressive power or long-term memory capacity of RNNs (Khrulkov et al., 2018; Levine et al., 2018).
However, the relationship between rank and effectiveness in language modelling has yet to be shown practically.
Later, we will evaluate the effectiveness of our models w.r.t rank.
Effectiveness.
(1) Fig.
4 shows the influence of the rank on our models based on the validation
PPL.
The validation PPL of TTLM-Large drops down at the early training step but easily increases when the rank increases.
In contrast, the validation PPL of TTLM-Tiny stably decreases as the rank increases.
(2) Compared to Vanilla-RNNs, the influence of the rank on our models based on the test
[Figure]
PPL is shown in Fig.
Our models outperform Vanilla-RNNs on all used parameter settings.
Table 1 provides a supplementary example to show the comparison of our models with baselines and some references.
TTLM-Large and TTLM-Tiny are more effective than baselines.
Overfitting.
Based on Fig.
4a and Fig.
4b, we find that TTLM-Large is more prone to overfitting than
TTLM-Tiny.
As the only difference between the two models is W eh , this suggests that the simpler parameterization of the TT cores, the more easily the model avoids overfitting.
This finding is consistent with the comparison between MI-RNNs and Second-order
RNNs by Wu et al.
Low-scale.
Despite the effectiveness of our models under the current hyperparameter settings, Fig.
5 reveals their limited potential when the rank is larger than 40 where the test perplexity of Vanilla-RNNs still stably decreases.
Therefore, we expect that our model can outperform vanilla RNNs with a low-scale of hidden size (i.e. range from 5 to 50), but not larger scales; this is a clear tradeoff of using the simple parameterization of TT cores as we do in TTLMs.
6. N ON - LINEARITY A NALYSIS .
Fig.
6 shows the effects of the tanh activation function on TT variants based on validation PPL.
Regarding the speed of convergence, tanh speeds up TTLM-Large-tanh, TTLM-Tiny-tanh, MI-RNNs while barely influencing second-order RNNs.
Regarding the magnitude of the lowest validation perplexity, tanh impairs the performance TTLM-Large and TTLM-Tiny, but has little influence on multiplicative integration and the third-tensor T in Second-order RNNs.
Thus, the influence of non-linearity on TTLM variants depends on TT cores settings, both for the convergence of validation PPL and the magnitude of the lowest validation PPL.
Thus, from an experimental point of view, the effect of non-linearity functions on one TT variant cannot simply be transferred or analogized to another TT variant.
This also suggests that one should be wary of the analogy between tensor decomposition and existing neural network models at the implementation level declared by previous research (Khrulkov et al., 2018; Levine et al., 2018).
The activation function could be a factor to influence such an analogy.
C ONCLUSION
We first apply TT decomposition to real-world language modeling and name the framework as
TTLM.
We propose two variants: TTLM-Large and TTLM-Tiny, and show that they are more ef-
[Figure]
fective compared to Vanilla-RNNs with low-scale of hidden sizes.
Meanwhile, we demonstrate that
Second-order RNNs, RACs and MI-RNNs are special implementations of TTLM
A PPENDIX A R ELATIONSHIP BETWEEN TT CORES IN TTLM
To help readers understand the roles of TT cores in TTLM, we here provide a detailed calculation of the probability of a text X =
[ x (1) , x (2) , · · · , x ( N ) ] by TTLM.
Note that all the intermediate TT cores are equal to each other: G = G (2) , ..., G ( N − 1) and G (1) =
G ( N ) .
The calculation of y ( t ) (i.e. the conditional probability of x ( t ) given x (1: t − 1) ) at time t ) can be described as three steps.
As step I, suppose f ( x (1) ) is a one-hot vector having f ( x (1) )
1 = 1 .
The calculation of G (1) f
( x (1 ) in TTLM is as follows:
[Equation]
As step II, TTLM will calculate f ( x ( i ) )
G h
( i − 1) TTLM where i ∈ { 2 , 3 , · · · , t − 1 } .
For example, h (2) TTLM is calculated in Eq.
7 at time t = 2 as follows:
[Equation]
As step III, TTLM will output y ( t ) as follows:
[Equation]
 
Observing the calculation, G (1) , G and G ( t ) theoretically have no parameters in common (though we set G (1) =
G ( t ) for simplicity).
Further, their roles in TTLM are different: G (1) can be viewed as a word embedding matrix; G deals with two sources of information, i.e. hidden state and input word; G ( t ) extracts the evidence provided in h ( t − 1) TTLM and generates a set of scores over vocabulary.
B R ELATIONSHIP BETWEEN TTLM AND SOME RNN S
We now demonstrate the relationship between TTLM and Second-order RNNs, Recurrent Arithmetic Circuits (RACs) and Multiplicative Integration RNNs (MI-RNNs).
To avoid symbol clutter when representing different RNNs, the notation is: W hx ∈ R R ×| V | denotes the input-to-hidden matrix, W hh ∈ R R × R denotes hidden-to-hidden matrix, ϕ ( · ) is a element-wise nonlinear activation function.
Also, different hidden states are denoted as: Second-order RNNs ( h ( t ) 2nd ), RACs ( h ( t ) RAC ) and MI-RNNs ( h ( t ) MI ).
B. R ELATION TO S ECOND - ORDER RNN S
Unlike Vanilla-RNNs (Mikolov & Zweig, 2012) that have additive blocks, Second-order RNNs have interaction between hidden states and input data in multiplicative form.
This is achieved by a third-order tensor T with the i -th coordinate of the hidden states h ( t ) 2nd defined as (Hochreiter &
Schmidhuber, 1997; Maupom´e & Meurs, 2020):
[Equation]
) where T i, : , : ∈ R M × R is the i th slice of tensor T ∈ R M × R × R , and b is a bias vector.
For simplicity, we will ignore b for other variants of RNNs since b can be seen as
th component of f ( x ( t ) ) which equals to 1.
Rabusseau et al.
(2019) has provided that Tensor Trains can generalize linear Secondorder RNNs.
We here provide a basic proof from the perspective of recursive property in TTLM.
Claim B.1.
The third-order tensor T in Second-order RNNs equals the TT cores in TTLM.
The hidden states of Second-order RNNs is identical to that of TTLM if they are accompanied by an activation function.
Proof.
The proof is based on the following observation: We recursively unfold the calculation of
TTLM in Eq.
[Equation]
Observe in the above, that at each time step, G has two sources of “input”: the information from the previous recursive unfolding ( e.g. , in the second line, the first line is the previous information), and the input data f ( x ( t ) ) .
From this perspective, G acts as a bilinear map G : R | V | × R R → R R , and we can regard the information in the previous line as a hidden state h ( t ) TTLM , given by:
[Equation]
where we permute the indices of G α t − 1 i t α t as G i t α t α t − 1 ( note that this does not change the number of indices).
We can also represent the hidden states in Second-order RNNs shown by Eq.
14 in element-wise fashion:
[Equation]
where j, k are the dummy indices as i t , α t ; i specifies the coordinate of h ( t ) 2 nd just like α t for h ( t ) TTLM .
Thus, T and G are the same-sized trainable bi-linear map.
After demonstrating that the third-order tensor T in Second-order RNNs equals the TT cores G , the only difference between the hidden states in Eq.
17 and in Eq.
16 is an activation function.
If we add an activation function for h ( t ) TTLM , the hidden states of Second-order RNNs and TTLM are identical, as shown in Fig.
7a.
|𝑉| 𝑅 𝐓 𝒇 𝑥 ! …
Φ 𝑋 𝒜 |𝑉| 𝑅 𝐓 𝑅 |𝑉| 𝐓
𝒇 𝑥 " 𝒇 𝑥 # a) Second-order RNNs b) RACs c) MI-RNNs 𝑾 !!
𝑾 !"
𝛿 |𝑉| 𝑅 𝑅 𝑅 𝑅 𝐆 𝑾 !!
𝑾 !"
𝛿 |𝑉| 𝑅 𝑅 𝑅 𝐆 𝑅
R ELATION TO RAC S AND MI-RNN S
We here focus on Multiplicative Integration (MI), a way to connect two sources of inputs by the
Hadamard product ‘ ⊙ ’.
MI has been used in RACs, Multiplicative RNNs (M-RNNs)
(Sutskever et al., 2011) and MI-RNNs:
Recurrent Arithmetic Circuits (RACs) are recurrent networks with hidden states h ( t ) RAC defined as (Levine et al., 2018):
[Equation]
(18) where these hidden states are also used as an intermediate term in M-RNNs.
Multiplicative Integration RNNs (MI-RNNs) are RACs with an activation function and hidden states h ( t ) MI defined as (Wu et al., 2016):
[Equation]
Claim B.2.
Given the condition the TT-scores: G = W hx ⊙ W hh .
The hidden states of RACs are identical to that of TTLM.
The hidden states of MI-RNNs are identical to that of TTLM if they are accompanied by an activation function.
Proof.
The proof is based on the following observation:
In the language of tensor contractions, Eq.
18 involves contracting the input weights matrix W hx with the input vector f ( x ( t ) ) , and contracting the hidden weights matrix W hh with h ( t − 1) RAC .
The Hadamard product of the two is a third-order diagonal tensor δ ∈ R R × R × R such that δ ijk = 1 iff the i = j = k , and δ ijk = 0 otherwise.
Thus, we can write Eq.
18 in element-wise fashion:
[Equation]
where G = W hx ⊙ W hh .
In this case, the hidden state of TTLM in Eq.
16 is equal to the hidden state of RACs in Eq.
20, as shown in Fig.
7b.
Similarly, if Eq.
16 is accompanied with an activation function ϕ , Eq.
16 is equal to the hidden state of MI-RNNs in Eq.
19 as shown in Fig.
7c.
Given Claim B.1 and B.2, the three models shall be simulated by TTLM with a non-linear activation function and we leave finding a theoretical proof of this conjecture to a future work.
C I MPLEMENTATIONS
We implement all RNNs models, TTLM, TTLM-Large, and TTLM-Tiny using PyTorch.
The weights in the models are adjusted to minimize the average cross entropy loss over training sequences via stochastic gradient descent computed using the truncated backpropagation through time algorithm.
(Werbos, 1990; Williams & Peng, 1990)).
For RNNs, there are five matrix parameters: W xe ∈ R E ×| V | is the input embedding matrix,
W eh ∈ R E × H is the embedding-to- hidden matrix,
W hh ∈
R H
× H is the hidden-to-hidden matrix.
We tie (share the same training parameters) the input embedding W xe and output embedding V which has been proved lead to a significant reduction in perplexity (Press & Wolf, 2016).
So there is a projection matrix P ∈
R H
× E before the output embedding.
All this process is introduced in (Press & Wolf, 2016).
For TTLM models, we tie the input tensor W xe and V .
The implementation of δ is functioned by a reshape function, so the interaction between hidden and input can be computed by matrix product.
We also let G (1) have the same parameters along the dimension | V | (i.e. G (1) is simplified into a
G (1) ∈ R 1 × R and can be viewed as initial hidden state h (0) ).
[Table]
[Equation]
MI-
[Equation]
RACs
[Equation]
[Table]
W xe ∈ R E ×| V | , T ∈ R H
× H × H , W hh ∈ R E × H ,
P ∈ R H
× E , V ∈ R E ×| V |
TTLM
G ∈ R R ×| V |× R , G ( t ) ∈ R R ×| V | , G (1) ∈ R R ×| V |
TTLM-Tiny
W xe ∈ R R ×| V |× R , W hh ∈ R R × R ,
P ∈ R R × R × R , V ∈ R R × R ×| V
|
TTLM-Large
W xe ∈ R R ×| V |× R , W eh ∈ R R × R × R × R , W hh ∈ R R × R ,
P ∈ R R × R × R , V ∈ R R × R ×| V
|