Latent Tree Language Model

In this paper we introduce Latent Tree Language Model (LTLM), a novel approach to language modeling that encodes syntax and semantics of a given sentence as a tree of word roles. The learning phase iteratively updates the trees by moving nodes according to Gibbs sampling. We introduce two algorithms to infer a tree for a given sentence. The first one is based on Gibbs sampling. It is fast, but does not guarantee to find the most probable tree. The second one is based on dynamic programming. It is slower, but guarantees to find the most probable tree. We provide comparison of both algorithms. We combine LTLM with 4-gram Modified Kneser-Ney language model via linear interpolation. Our experiments with English and Czech corpora show significant perplexity reductions (up to 46% for English and 49% for Czech) compared with standalone 4-gram Modified Kneser-Ney language model.


Introduction
Language modeling is one of the core disciplines in natural language processing (NLP).Automatic speech recognition, machine translation, optical character recognition, and other tasks strongly depend on the language model (LM).An improvement in language modeling often leads to better performance of the whole task.The goal of language modeling is to determine the joint probability of a sentence.Currently, the dominant approach is n-gram language modeling, which decomposes the joint probability into the product of conditional probabilities by using the chain rule.In traditional n-gram LMs the words are represented as distinct symbols.This leads to an enormous number of word combinations.
In the last years many researchers have tried to capture words contextual meaning and incorporate it into the LMs.Word sequences that have never been seen before receive high probability when they are made of words that are semantically similar to words forming sentences seen in training data.This ability can increase the LM performance because it reduces the data sparsity problem.In NLP a very common paradigm for word meaning representation is the use of the Distributional hypothesis.It suggests that two words are expected to be semantically similar if they occur in similar contexts (they are similarly distributed in the text) (Harris, 1954).Models based on this assumption are denoted as distributional semantic models (DSMs).
Recently, semantically motivated LMs have begun to surpass the ordinary n-gram LMs.The most commonly used architectures are neural network LMs (Bengio et al., 2003;Mikolov et al., 2010;Mikolov et al., 2011) and class-based LMs.Classbased LMs are more related to this work thus we investigate them deeper.Brown et al. (1992) introduced class-based LMs of English.Their unsupervised algorithm searches classes consisting of words that are most probable in the given context (one word window in both directions).However, the computational complexity of this algorithm is very high.This approach was later extended by (Martin et al., 1998;Whit-taker and Woodland, 2003) to improve the complexity and to work with wider context.Deschacht et al. (2012) used the same idea and introduced Latent Words Language Model (LWLM), where word classes are latent variables in a graphical model.They apply Gibbs sampling or the expectation maximization algorithm to discover the word classes that are most probable in the context of surrounding word classes.A similar approach was presented in (Brychcín and Konopík, 2014;Brychcín and Konopík, 2015), where the word clusters derived from various semantic spaces were used to improve LMs.
In above mentioned approaches, the meaning of a word is inferred from the surrounding words independently of their relation.An alternative approach is to derive contexts based on the syntactic relations the word participates in.Such syntactic contexts are automatically produced by dependency parse-trees.Resulting word representations are usually less topical and exhibit more functional similarity (they are more syntactically oriented) as shown in (Padó and Lapata, 2007;Levy and Goldberg, 2014).
Dependency-based methods for syntactic parsing have become increasingly popular in NLP in the last years (Kübler et al., 2009).Popel and Mareček (2010) showed that these methods are promising direction of improving LMs.Recently, unsupervised algorithms for dependency parsing appeared in (Headden III et al., 2009;Cohen et al., 2009;Spitkovsky et al., 2010;Spitkovsky et al., 2011;Mareček and Straka, 2013) offering new possibilities even for poorly-resourced languages.
In this work we introduce a new DSM that uses tree-based context to create word roles.The word role contains the words that are similarly distributed over similar tree-based contexts.The word role encodes the semantic and syntactic properties of a word.We do not rely on parse trees as a prior knowledge, but we jointly learn the tree structures and word roles.Our model is a soft clustering, i.e. one word may be present in several roles.Thus it is theoretically able to capture the word polysemy.The learned structure is used as a LM, where each word role is conditioned on its parent role.We present the unsupervised algorithm that discovers the tree structures only from the distribution of words in a training corpus (i.e.no labeled data or external sources of in-formation are needed).In our work we were inspired by class-based LMs (Deschacht et al., 2012), unsupervised dependency parsing (Mareček and Straka, 2013), and tree-based DSMs (Levy and Goldberg, 2014).
This paper is organized as follows.We start with the definition of our model (Section 2).The process of learning the hidden sentence structures is explained in Section 3. We introduce two algorithms for searching the most probable tree for a given sentence (Section 4).The experimental results on English and Czech corpora are presented in Section 6.We conclude in Section 7 and offer some directions for future work.

Latent Tree Language Model
In this section we describe Latent Tree Language Model (LTLM).LTLM is a generative statistical model that discovers the tree structures hidden in the text corpus.
Let L be a word vocabulary with total of |L| distinct words.Assume we have a training corpus w divided into S sentences.The goal of LTLM or other LMs is to estimate the probability of a text P (w).Let N s denote the number of words in the s-th sentence.The s-th sentence is a sequence of words w s = {w s,i } Ns i=0 , where w s,i ∈ L is a word at position i in this sentence and w s,0 = < s > is an artificial symbol that is added at the beginning of each sentence.
Each sentence s is associated with the dependency graph G s .We define the dependency graph as a labeled directed graph, where nodes correspond to the words in the sentence and there is a label for each node that we call role.Formally, it is a triple • The set of edges E s ⊆ V s × V s .
• The sequence of roles r s = {r s,i } Ns i=0 , where 1 ≤ r s,i ≤ K for i ∈ V s .K is the number of roles.
The artificial word w s,0 = < s > at the beginning of the sentence has always role 1 (r s,0 = 1).Analogously to w, the sequence of all r s is denoted as r and sequence of all G s as G. Edge e ∈ E s is an ordered pair of nodes (i, j).We say that i is the head or the parent and j is the dependent or the child.We use the notation i → j for such edge.The directed path from node i to node j is denoted as i * → j.We place a few constraints on the graph G s .
• The graph G s is a tree.It means it is the acyclic graph (if i → j then not j * → i), where each node has one parent (if i → j then not k → j for every k = i).
• The graph G s is projective (there are no cross edges).For each edge (i, j) and for each k between i and j (i.e.i < k < j or i > k > j) there must exist the directed path i * → k.
• The graph G s is always rooted in the node 0.
We denote these graphs as the projective dependency trees.Example of such a tree is on Figure 1.For the tree G s we define a function that returns the parent for each node except the root.
We use graph G s as a representation of the Bayesian network with random variables E s and r s .The roles r s,i represent the node labels and the edges express the dependences between the roles.The conditional probability of the role at position i given its parent role is denoted as P (r s,i |r s,hs(i) ).The conditional probability of the word at position i in the sentence given its role r s,i is denoted as P (w s,i |r s,i ).
We model the distribution over words in the sentence s as the mixture The root role is kept fixed for each sentence (r s,0 = 1) so P (w s ) = P (w s |r s,0 ).
We look at the roles as mixtures over child roles and simultaneously as mixtures over words.We can represent dependency between roles with a set of K multinomial distributions θ over K roles, such that r s,i .Simultaneously, dependency of words on their roles can be represented as a set of K multinomial distributions φ over |L| words, such that w s,i .To make predictions about new sentences, we need to assume a prior distribution on the parameters θ (k) and φ (k) .
We place a Dirichlet prior D with the vector of K hyper-parameters α on a multinomial distribution θ (k) ∼ D(α) and with the vector of |L| hyperparameters β on a multinomial distribution φ (k) ∼ D(β).In general, D is not restricted to be Dirichlet distribution.It could be any distribution over discrete children, such as logistic normal.In this paper, we focus only on Dirichlet as a conjugate prior to the multinomial distribution and derive the learning algorithm under this assumption.
The choice of the child role depends only on its parent role, i.e. child roles with the same parent are mutually independent.This property is especially important for the learning algorithm (Section 3) and also for searching the most probable trees (Section 4).We do not place any assumption on the length of the sentence N s or on how many children the parent node is expected to have.

Parameter Estimation
In this section we present the learning algorithm for LTLM.The goal is to estimate θ and φ in a way that maximizes the predictive ability of the model (generates the corpus with maximal joint probability P (w)).
Let χ k (i,j) be an operation that changes the tree such that the newly created tree G (V s , E s , r s ) consists of: It means that we change the role of the selected node i so that r s,i = k and simultaneously we change the parent of this node to be j.We call this operation a partial change.
The newly created graph G must satisfy all conditions presented in Section 2, i.e. it is a projective dependency tree rooted in the node 0. Thus not all partial changes χ k (i,j) are possible to perform on graph G s .
Clearly, for the sentence s there is at most parent changes 1 .To estimate the parameters of LTLM we apply Gibbs sampling and gradually sample χ k (i,j) for trees G s .For doing so we need to determine the posterior predictive distribution 2 from which we will sample partial changes to update the trees.In the equation, G denote the sequence of all trees for given sentences w and G s is a result of one sampling.In the following text we derive this equation under assumptions from Section 2. The posterior predictive distribution of Dirichlet multinomial has the form of additive smoothing that is well known in the context of language modeling.The hyper-parameters of Dirichlet prior determine how much is the predictive distribution smoothed.Thus the predictive distribution for the word-in-role distribution can be expressed as 1 The most parent changes are possible for the special case of the tree, where each node i has parent i − 1.Thus for each node i we can change its parent to any node j < i and keep the projectivity of the tree.That is Ns(1+Ns)   2 possibilities. 2 The posterior predictive distribution is the distribution of an unobserved variable conditioned by the observed data, i.e.P (Xn+1|X1, ..., Xn), where Xi are i.i.d.(independent and identically distributed random variables).
where n is the number of times the role r s,i has been assigned to the word w s,i , excluding the position i in the s-th sentence.The symbol • represents any word in the vocabulary so that n \s,i .We use the symmetric Dirichlet distribution for the word-in-role probabilities as it could be difficult to estimate the vector of hyper-parameters β for large word vocabulary.In the above mentioned equation, β is a scalar.
The predictive distribution for the role-by-role distribution is Analogously to the previous equation, n (r s,i |r s,hs(i) ) \s,i denote the number of times the role r s,i has the parent role r s,hs(i) , excluding the position i in the s-th sentence.The symbol • represents any possible role to make the probability distribution summing up to 1.We assume an asymmetric Dirichlet distribution.
We can use predictive distributions of above mentioned Dirichlet multinomials to express the joint probability that the role at position i is k (r s,i = k) with parent at position j conditioned on current values of all variables, except those in position i in the sentence s P (r s,i = k, j|w, r \s,i ) ∝ P (w s,i |r s,i = k, w \s,i , r \s,i ) × P (r s,i = k|r s,j , r \s,i ) × a:hs(a)=i P (r s,a |r s,i = k, r \s,i ). (7) The choice of the node i role affects the word that is produced by this role and also all the child roles of the node i. Simultaneously, the role of the node i depends on its parent j role.Formula 7 is derived from the joint probability of a sentence s and a tree G s , where all probabilities which do not depend on the choice of the role at position i are removed and equality is replaced by proportionality (∝).We express the final predictive distribution for sampling partial changes χ k (i,j) as ) that is essentially the fraction between the joint probability of r s,i and its parent after the partial change and before the partial change (conditioned on all other variables).This fraction can be interpreted as the necessity to perform this partial change.
We investigate two strategies of sampling partial changes: • Per sentence: We sample a single partial change according to Equation 8for each sentence in the training corpus.It means during one pass through the corpus (one iteration) we perform S partial changes.
• Per position: We sample a partial change for each position in each sentence.We perform in total N = S s=1 N s partial changes during one pass.Note that the denominator in Equation 8is constant for this strategy and can be removed.
We compare both training strategies in Section 6.After enough training iterations, we can estimate the conditional probabilities φ These equations are similar to equations 5 and 6, but here the counts n do not exclude any position in a corpus.
Note that in the Gibbs sampling equation, we assume that the Dirichlet parameters α and β are given.We use a fixed point iteration technique described in (Minka, 2003) to estimate them.

Inference
In this section we present two approaches for searching the most probable tree for a given sentence assuming we have already estimated the parameters θ and φ.

Inference
We use the same sampling technique as for estimating parameters (Equation 8), i.e. we iteratively sample the partial changes χ k (i,j) .However, we use equations 9 and 10 for predictive distributions of Dirichlet multinomials instead of 5 and 6.In fact, these equations correspond to the predictive distributions over the newly added word w s,i with the role r s,i into the corpus, conditioned on w and r.This sampling technique rarely finds the best solution, but often it is very near.

Deterministic Inference
Here we present the deterministic algorithm that guarantees to find the most probable tree for a given sentence.We were inspired by Cocke-Younger-Kasami (CYK) algorithm (Lange and Leiß, 2009).Let T n s,a,c denote the subtree of G s (subgraph of G s that is also a tree) containing subsequence of nodes {a, a + 1, ..., c}.The superscript n denotes the number of children the root of this subtree has.We denote the joint probability of a subtree from position a to position c with the corresponding words conditioned by the root role k as P n ({w s,i } c i=a , T n s,a,c |k).Our goal is to find the tree G s = T 1+ s,0,Ns that maximizes probability P (w s , G s ) = P 1+ ({w s,i } Ns i=0 , T 1+ s,0,Ns |0).Similarly to CYK algorithm, our approach fol-lows bottom-up direction and goes through all possible subsequences for a sentence (sequence of words).At the beginning, the probabilities for subsequences of length 1 (i.e.single words) are calculated as P 1+ ({w s,a }, T 1+ s,a,a |k) = P (w s,a |r s,a = k).Once it has considered subsequences of length 1, it goes on to subsequences of length 2, and so on.
Thanks to mutual independence of roles under the same parent, we can find the most probable subtree with the root role k and with at least two root children according to It means we merge two neighboring subtrees with the same root role k.This is the reason why the new subtree has at least two root children.This formula is visualized on Figure 2a.Unfortunately, does not cover all subtree cases.We find the most probable tree with only root child as follows This formula is visualized on Figure 2b.To find the most probable subtree matter how many children the root has, we need to take the maximum from both mentioned equations P 1+ = max(P 2+ , P 1 ).
The algorithm has complexity O(N 3 s K 2 ), i.e. it has cubic dependence on the length of the sentence N s .

Side-dependent LTLM
Until now, we presented LTLM in its simplified version.In role-by-role probabilities (role conditioned on its parent role) we did not distinguish whether the role is on the left side or the right side of the parent.However, this position keeps important information about the syntax of words (and their roles).
We assume separate multinomial distributions θ for roles that are on the left and θ for roles on the right.Each of them has its own Dirichlet prior with hyper-parameters α and α, respectively.The process of estimating LTLM parameters is almost the same.The only difference is that we need to redefine the predictive distribution for the role-by-role distribution (Equation 6) to include only counts of roles on the appropriate side.Also, every time the role-by-role probability is used we need to distinguish sides: .
(13) In the following text we always assume the sidedependent LTLM.

Experimental Results and Discussion
In this section we present experiments with LTLM on two languages, English (EN) and Czech (CS).
As a training corpus we use CzEng 1.0 (Bojar et al., 2012) of the sentence-parallel Czech-English corpus.We choose this corpus because it contains multiple domains, it is of reasonable length, and it is parallel so we can easily provide comparison between both languages.The corpus is divided into 100 similarly-sized sections.We use parts 0-97 for training, the part 98 as a development set, and the last part 99 for testing.
We have removed all sentences longer than 30 words.The reason was that the complexity of the learning phase and the process of searching most probable trees depends on the length of sentences.It has led to removing approximately a quarter of all sentences.The corpus is available in a tokenized form so the only preprocessing step we use is lowercasing.We keep the vocabulary of 100,000 most frequent words in the corpus for both languages.The less frequent words were replaced by the symbol <unk>.Statistics for the final corpora are shown in Table 1.
We measure the quality of LTLM by perplexity that is the standard measure used for LMs.Perplexity is a measure of uncertainty.The lower perplexity means the better predictive ability of the LM.During the process of parameter estimation we measure the perplexity of joint probability of sentences and their trees defined as PPX(P (w, G)) = N 1 P (w,G) , where N is the number of all words in the training data w.
As we describe in Section 3, there are two approaches for the parameter estimation of LTLM.
During our experiments, we found that the perposition strategy of training has the ability to converge faster, but to a worse solution compared to the per-sentence strategy which converges slower, but to a better solution.
We train LTLM by 500 iterations of the perposition sampling followed by another 500 iterations of the per-sentence sampling.This proves to be effi-  cient in both aspects, the reasonable speed of convergence and the satisfactory predictive ability of the model.The learning curves are showed on Figure 3.We present the models with 10, 20, 50, 100, 200, 500, and 1000 roles.The higher role cardinality models were not possible to create because of the very high computational requirements.Similarly to the training of LTLM, the non-deterministic inference uses 100 iterations of per-position sampling followed by 100 iterations of per-sentence sampling.
In the following experiments we measure how well LTLM generalizes the learned patterns, i.e. how well it works on the previously unseen data.Again, we measure the perplexity, but of probability P (w) for mutual comparison with different LMs that are based on different architectures (PPX(P (w)) = N 1 P (w) ).To show the strengths of LTLM we compare it with several state-of-the-art LMs.We experiment with Modified Kneser-Ney (MKN) interpolation (Chen and Goodman, 1998), with Recurrent Neural Network LM (RNNLM) (Mikolov et al.,  2010; Mikolov et al., 2011) 3 , and with LWLM (Deschacht et al., 2012) 4 .We have also created syntactic dependency tree based LM (denoted as STLM).Syntactic dependency trees for both languages are provided within CzEng corpus and are based on kuleuven.be/software.php.39.9 37.2 Table 3: Perplexity results on the test data for LTLMs and STLMs with different number of roles.Deterministic inference is denoted as det.and non-deterministic inference as non-det.
MST parser (McDonald et al., 2005).We use the same architecture as for LTLM and experiment with two approaches to represent the roles.Firstly, the roles are given by the part-of-speech tag (denoted as PoS STLM).No training is required, all information come from CzEng corpus.Secondly, we learn the roles using the same algorithm as for LTLM.The only difference is that the trees are kept unchanged.Note that both deterministic and non-deterministic inference perform almost the same in this model so we do not distinguish between them.We combine baseline 4-gram MKN model with other models via linear combination (in the tables denoted by the symbol +) that is simple but very efficient technique to combine LMs.Final probability is then expressed as In the case of MKN the probability P MKN is the probability of a word w s,i conditioned by 3 previous words with MKN smoothing.For LTLM or STLM this probability is defined as We use the expectation maximization algorithm (Dempster et al., 1977) for the maximum likelihood estimate of λ parameter on the development part of the corpus.The influence of the number of roles on the perplexity is shown in  cantly outperformed STLM where the syntactic dependency trees were provided as a prior knowledge.
The joint learning of syntax and semantics of a sentence proved to be more suitable for predicting the words.
An in-depth analysis of semantic and syntactic properties of LTLM is beyond the scope of this paper.For better insight into the behavior of LTLM, we show the most probable word substitutions for one selected sentence (see Table 4).We can see that the original words are often on the front positions.Also it seems that LTLM is more syntactically oriented, which confirms claims from (Levy and Goldberg, 2014;Padó and Lapata, 2007), but to draw such conclusions a deeper analysis is required.The properties of the model strongly depends on the number of distinct roles.We experimented with maximally 1000 roles.To catch the meaning of various words in natural language, more roles may be needed.However, with our current implementation, it was intractable to train LTLM with more roles in a reasonable time.Training 1000 roles LTLM took up to two weeks on a powerful computational unit.

Conclusion and Future Work
In this paper we introduced the Latent Tree Language Model.Our model discovers the latent tree structures hidden in natural text and uses them to predict the words in a sentence.Our experiments with English and Czech corpora showed dramatic improvements in the predictive ability compared with standalone Modified Kneser-Ney LM.Our Java implementation is available for research purposes at https://github.com/brychcin/LTLM.
It was beyond the scope of this paper to explicitly test the semantic and syntactic properties of the model.As the main direction for future work we plan to investigate these properties for example by comparison with human-assigned judgments.Also, we want to test our model in different NLP tasks (e.g.speech recognition, machine translation, etc.).
We think that the role-by-role distribution should depend on the distance between the parent and the child, but our preliminary experiments were not met with success.We plan to elaborate on this assumption.Another idea we want to explore is to use different distributions as a prior to multinomials.For example, Blei and Lafferty (2006) showed that the logistic-normal distribution works well for topic modeling because it captures the correlations between topics.The same idea might work for roles.

Figure 1 :
Figure 1: Example of LTLM for the sentence "Everything has beauty, but not everyone sees it." (a) The root has two or more children.(b) The root has only one child.

Figure 3 :
Figure 3: Learning curves of LTLM for both English and Czech.The points in the graphs represent the perplexities in every 100th iteration.

Table 1 :
Corpora statistics.OOV rate denotes the out-of-vocabulary rate.

Table 2 :
Perplexity results on the test data.The numbers in brackets are the relative improvements compared with standalone 4-gram MKN LM.
Table 3 and the final

Table 4 :
Ten most probable word substitutions on each position in the sentence "Everything has beauty, but not everyone sees it."produced by 1000 roles LTLM with the deterministic inference.