<?xml version="1.0"?><!DOCTYPE article SYSTEM "/project/take/software/searchbench_offline_processing/paperxml_generator/aclextractor/src/python/../resource/dtd/paperxml.dtd"><article><header><firstpageheader><page local="1" global="1213"/><title>Computation of Infix Probabilities for Probabilistic Context-Free Grammars</title><pubinfo>Proceedings of the 2011 Conference on Empirical Methods in Natural Language Processing,pages 1213-1221, Edinburgh, Scotland, UK, July 27-31,2011. ©2011 Association for Computational Linguistics</pubinfo><author surname="Nederhof" givenname="Mark-Jan"><org  name="University of St. Andrews" country="United Kingdom" city="St. Andrews"/></author><author surname="Satta" givenname="Giorgio"><org  name="University of Padua" country="Italy" city="Padua"/></author></firstpageheader><frontmatter><p><b>Computation of Infix Probabilities for Probabilistic Context-Free Grammars</b></p><p><b>Mark-Jan Nederhof</b></p><p>School of Computer Science University of St Andrews United Kingdom</p><p>markjan.nederhof@gmail.com</p><p><b>Giorgio Satta</b></p><p>Dept. of Information Engineering University of Padua Italy</p><p>satta@dei.unipd.it</p></frontmatter><abstract>The notion of infix probability has been intro­duced in the literature as a generalization of the notion of prefix (or initial substring) prob­ability, motivated by applications in speech recognition and word error correction. For the case where a probabilistic context-free gram­mar is used as language model, methods for the computation of infix probabilities have been presented in the literature, based on vari­ous simplifying assumptions. Here we present a solution that applies to the problem in its full generality. </abstract></header><body><section number="1" title="Introduction"><p>Probabilistic context-free grammars (PCFGs for short) are a statistical model widely used in natural language processing. Several computational prob­lems related to PCFGs have been investigated in the literature, motivated by applications in model­ing of natural language syntax. One such problem is the computation of <b>prefix probabilities </b>for PCFGs, where we are given as input a PCFG G and a string <i>w, </i>and we are asked to compute the probability that a sentence generated by G starts with w, that is, has w as a prefix. This quantity is defined as the possi­bly infinite sum of the probabilities of all strings of the form <i>wx, </i>for any string x over the alphabet of G.</p><p>The problem of computation of prefix probabili­ties for PCFGs was first formulated by Persoon and Fu (1975). Efficient algorithms for its solution have been proposed by Jelinek and Lafferty (1991) and Stolcke (1995). Prefix probabilities can be used to compute probability distributions for the next word or part-of-speech, when a prefix of the input has al­ready been processed, as discussed by Jelinek and Lafferty (1991). Such distributions are useful for speech recognition, where the result of the acous­tic processor is represented as a lattice, and local choices must be made for a next transition. In ad­dition, distributions for the next word are also useful for applications of word error correction, when one is processing 'noisy' text and the parser recognizes an error that must be recovered by operations of in­sertion, replacement or deletion.</p><p>Motivated by the above applications, the problem of the computation of <b>inix probabilities </b>for PCFGs has been introduced in the literature as a generaliza­tion of the prefix probability problem. We are now given a PCFG G and a string <i>w, </i>and we are asked to compute the probability that a sentence generated by G has w as an infix. This probability is defined as the possibly infinite sum of the probabilities of all strings of the form xwy, for any pair of strings x and y over the alphabet of G. Besides applications in computation of the probability distribution for the next word token and in word error correction, in­fix probabilities can also be exploited in speech un­derstanding systems to score partial hypotheses in algorithms based on beam search, as discussed by Corazzaetal. (1991).</p><p>Corazza et al. (1991) have pointed out that the computation of infix probabilities is more difficult than the computation of prefix probabilities, due to the added ambiguity that several occurrences of the given infix can be found in a single string generated by the PCFG. The authors developed solutions for the case where some distribution can be defined on the distance of the infix from the sentence bound­aries, which is a simplifying assumption.<page local="2" global="1214"/> The prob­lem is also considered by Fred (2000), which pro­vides algorithms for the case where the language model is a probabilistic regular grammar. However, the algorithm in (Fred, 2000) does not apply to cases with multiple occurrences of the given infix within a string in the language, which is what was pointed out to be the problematic case.</p><p>In this paper we adopt a novel approach to the problem of computation of inix probabilities, by re­moving the ambiguity that would be caused by mul­tiple occurrences of the given inix. Although our result is obtained by a combination of well-known techniques from the literature on PCFG parsing and pattern matching, as far as we know this is the irst algorithm for the computation of inix probabilities that works for general PCFG models without any re­strictive assumption.</p><p>The remainder of this paper is structured as fol­lows. In Section 2 we explain how the sum of the probabilities of all trees generated by a PCFG can be computed as the least ixed-point solution of a non-linear system of equations. In Section 3 we re­call the construction of a new PCFG out of a given PCFG and a given inite automaton, such that the language generated by the new grammar is the in­tersection of the languages generated by the given PCFG and the automaton, and the probabilities of the generated strings are preserved. In Section 4 we show how one can eficiently construct an un­ambiguous inite automaton that accepts all strings with a given inix. The material from these three sections is combined into a new algorithm in Sec­tion 5, which allows computation of the infix prob­ability for PCFGs. This is the main result of this paper. Several extensions of the basic technique are discussed in Section 6. Section 7 discusses imple­mentation and some experiments.</p></section><section number="2" title="Sum of probabilities of all derivations"><p>Assume a probabilistic context-free grammar G, rep­resented by a 5-tuple (E, <i>N, S, </i>R, p), where E and N are two finite disjoint sets of <b>terminals </b>and <b>non­terminals, </b>respectively, S G N is the <b>start symbol, </b>R is a finite set of <b>rules, </b>each of the form A <i>— </i>a, where A G N and <i>a G </i>(EU N)*, and p is a function from rules in R to real numbers in the interval [0,1].</p><p>The concept of <b>left-most derivation </b>in one step is represented by the notation <i>a </i>==<i>g ß</i>, which means that the left-most occurrence of any nonterminal in <i>a G (E U N</i><i>)*</i><i> </i>is rewritten by means of some rule n G R. If the rewritten nonterminal is A, then n must be of the form (A — 7) and ß is the result of replacing the occurrence of A in <i>a </i>by 7. A left­most derivation with any number of steps, using a sequence d of rules, is denoted as <i>a</i><i> </i><i>==g</i><i> </i><i>ß</i>. We omit the subscript G when the PCFG is understood. We also write <i>a </i>=<i>* ß </i>when the involved sequence of rules is of no relevance. Henceforth, all derivations we discuss are implicitly left-most.</p><p>A <b>complete </b>derivation is either the empty se­quence of rules, or a sequence d = <i>n\</i><i> </i><i>•</i><i> </i><i>•</i><i> </i><i>•</i><i> </i>nm, <i>m</i><i> </i><i>&gt;</i> 1, of rules such that A == w for some A G N and w <i>G E*</i>. In the latter case, we say the complete derivation starts with <i>A,</i><i> </i>and in the former case, with <i>d </i>an empty sequence of rules, we assume the com­plete derivation starts and ends with a single termi­nal, which is left unspeciied. It is well-known that there exists a bijective correspondence between left­most complete derivations starting with nonterminal <i>A </i>and parse trees derived by the grammar with root <i>A </i>and a yield composed of terminal symbols only.</p><p>The <b>depth </b>of a complete derivation d is the length of the longest path from the root to a leaf in the parse tree associated with <i>d. </i>The length of a path is de­fined as the number of nodes it visits. Thus if d = n for some rule n = (A — w) with w G E*, then the depth of d is 2.</p><p>The probability p(d) of a complete derivation d = <i>n\</i><i> </i><i>•</i><i> </i><i>•</i><i> </i><i>•</i><i> </i>nm, m &gt; 1, is:</p><doubt alpha="100.0" length="1" tooSmall="False" monospace="0.0">m</doubt><doubt alpha="30.8" length="13" tooSmall="False" monospace="0.0">P(d)=]^P(n*)-</doubt><doubt alpha="33.3" length="3" tooSmall="False" monospace="0.0">i=1</doubt><p>We also assume that p(d) = 1 when d is an empty sequence of rules. The probability p(w) of a string <i>w </i>is the sum of all complete derivations deriving that string from the start symbol:</p><p>P(w)   =      E P(d).</p><doubt alpha="50.0" length="6" tooSmall="False" monospace="0.0">d:S=4w</doubt><p>With this notation, <b>consistency </b>of a PCFG is defined as the condition:<page local="3" global="1215"/></p><p>1.</p><doubt alpha="44.4" length="9" tooSmall="False" monospace="0.0">d,w: S=^w</doubt><p><i>In </i>other words, a PCFG is consistent if the sum of probabilities of all complete derivations starting with S is 1. An equivalent definition of consistency considers the sum of probabilities of all strings:</p><doubt alpha="60.0" length="5" tooSmall="False" monospace="0.0">Ep(w)</doubt><p>See (Booth and Thompson, 1973) for further discus­sion.</p><p>In practice, PCFGs are often required to satisfy the additional condition:</p><doubt alpha="100.0" length="1" tooSmall="False" monospace="0.0">E</doubt><doubt alpha="42.9" length="7" tooSmall="False" monospace="0.0">n=(A—a)</doubt><doubt alpha="0.0" length="2" tooSmall="False" monospace="0.0">1,</doubt><p>for each A <i>G </i>N. This condition is called <b>proper-ness. </b>PCFGs that naturally arise by parameter es­timation from corpora are generally consistent; see (Sanchez and Benedi, 1997; Chi and Geman, 1998). However, in what follows, neither properness nor consistency is guaranteed.</p><p>We define the <b>partition function </b>of G as the func­tion Z that assigns to each A G N the value</p><p>Z(A)   =   E <i>P(A </i>4 w).</p><doubt alpha="0.0" length="3" tooSmall="False" monospace="0.0">(1)</doubt><p>For each k with 1 &lt; <i>k &lt; </i>|N|, the <b>generating function </b>associated with Ak is defined as</p><doubt alpha="31.6" length="19" tooSmall="False" monospace="0.0">9Ak(Z\,Z2,...,Z\N|)</doubt><doubt alpha="71.4" length="7" tooSmall="False" monospace="0.0">E(p(Afc</doubt><doubt alpha="33.3" length="3" tooSmall="False" monospace="0.0">|N|</doubt><doubt alpha="57.1" length="7" tooSmall="False" monospace="0.0">ak,i)•n</doubt><doubt alpha="46.2" length="13" tooSmall="False" monospace="0.0">f (Aj ,ak,i )</doubt><doubt alpha="0.0" length="3" tooSmall="False" monospace="0.0">(2)</doubt><doubt alpha="66.7" length="3" tooSmall="False" monospace="0.0">i=l</doubt><doubt alpha="0.0" length="3" tooSmall="False" monospace="0.0">3=1</doubt><p>Furthermore, for each <i>i &gt; 1 </i>we recursively define functions gAk(zi, Z2,..., Z|n|) by</p><doubt alpha="34.8" length="46" tooSmall="False" monospace="0.0">gA1k)(zi,Z2,...,Z|N|) =gAk(zi,Z2,...,Z|N|),(3)</doubt><doubt alpha="56.2" length="16" tooSmall="False" monospace="0.0">and, fori &gt;2, by</doubt><doubt alpha="0.0" length="3" tooSmall="False" monospace="0.0">(4)</doubt><doubt alpha="35.0" length="20" tooSmall="False" monospace="0.0">gAk(Z1,Z2,...,Z|N|)=</doubt><doubt alpha="35.7" length="28" tooSmall="False" monospace="0.0">gAk(gAi1~1)(Z1,Z2,...,Z|N|),</doubt><p>gAi2~1)(Zl,Z2,...,Z|N |),.. gA-v1)(Z1,Z2,...,Z|N|) ).</p><p>Using induction it is not difficult to show that, for each k and i as above, gAk (0,0,..., 0) is the sum of the probabilities of all complete derivations from Akhaving depth not exceeding i. This implies that, for i = 0,1,2,..the sequence of the (0,0,..., 0) monotonically converges to Z (Ak ). For each k with 1 &lt; k &lt; | N| we can now write = gAk (Z (A1),...,Z (A|n |)).</p><doubt alpha="42.9" length="7" tooSmall="False" monospace="0.0">Z (Ak )</doubt><doubt alpha="27.8" length="18" tooSmall="False" monospace="0.0">= lim gA)(0,...,0)</doubt><doubt alpha="19.6" length="46" tooSmall="False" monospace="0.0">= lim gAk( gAi_1)(0,0,...,0),...,^(0,0,...,0))</doubt><doubt alpha="33.3" length="54" tooSmall="False" monospace="0.0">= gAk( limi—ocgAii_1)(0, 0,0),...,limi—o^(0,0,...,0) )</doubt><p>The above shows that the values of the partition function provide a solution to the system of the fol­lowing equations, for 1 &lt; k &lt; | N| :</p><p>Note that Z(S) = 1 means that G is consistent. More generally, in later sections we will need to compute the partition function for non-consistent</p><p>PCFGs.</p><p>We can characterize the partition function of a PCFG as a solution of a speciic system of equa­tions. Following the approach in (Harris, 1963; Chi, 1999), we introduce generating functions associated with the nonterminals of the grammar. For A G N and <i>a G </i>(N U we write <i>f </i>(A, a) to denote the number of occurrences of symbol A within string a. Let N = {A1, A2,..., A|N|}. For each Ak G N,let mk be the number of rules in <i>R </i>with left-hand side Ak, and assume some fixed order for these rules. For each i with 1 &lt; i &lt; mk, let Ak —&gt; ak;i be the i-th rule with left-hand side Ak.</p><doubt alpha="100.0" length="2" tooSmall="False" monospace="0.0">Zk</doubt><p>gAk (Z1,Z2 ,...,Z|N |).</p><doubt alpha="0.0" length="3" tooSmall="False" monospace="0.0">(5)</doubt><p>In the case of a general PCFG, the above equa­tions are non-linear polynomials with positive (real) coeficients. We can represent the resulting system in vector form and write <b>X = g(X). </b>These systems are called monotone systems of polynomial equa­tions and have been investigated by Etessami and Yannakakis (2009) and Kiefer et al. (2007).<page local="4" global="1216"/> The sought solution, that is, the partition function, is the least ixed point solution of <b>X = g(X).</b></p><p>For practical reasons, the set of nonterminals of a grammar is usually divided into maximal subsets of mutually recursive nonterminals, that is, for each A and B in such a subset, we have A == uBa and B = vAß, for some u, v, a, ß. This corre­sponds to a <b>strongly connected component </b>if we see the connection between the left-hand side of a rule and a nonterminal member in its right-hand side as an edge in a directed graph. For each strongly connected component, there is a separate system of equations of the form <b>X = g(X). </b>Such systems can be solved one by one, in a bottom-up order. That is, if one strongly connected component contains nonterminal A, and another contains nonterminal B, where A == uBa for some u, a, then the system for the latter component must be solved irst.</p><p>The solution for a system of equations such as those described above can be irrational and non-expressible by radicals, even if we assume that all the probabilities of the rules in the input PCFG are rational numbers, as observed by Etessami and Yan-nakakis (2009). Nonetheless, the partition function can still be approximated to any degree of preci­sion by iterative computation of the relation in (4), as done for instance by Stolcke (1995) and by Ab-ney et al. (1999). This corresponds to the so-called ixed-point iteration method, which is well-known in the numerical calculus literature and is frequently applied to systems of non-linear equations because it can be easily implemented.</p><p>When a number of standard conditions are met, each iteration of (4) adds a ixed number of bits to the precision of the solution; see Kelley (1995, Chapter 4). Since each iteration can easily be im­plemented to run in polynomial time, this means that we can approximate the partition function of a PCFG in polynomial time in the size of the PCFG itself and in the number of bits of the desired preci­sion.</p><p>In practical applications where large PCFGs are empirically estimated from data sets, the standard conditions mentioned above for the polynomial time approximation of the partition function are usually met. However, there are some degenerate cases for which these standard conditions do not hold, result­ing in exponential time behaviour of the ixed-point iteration method. This has been irstly observed in (Etessami and Yannakakis, 2005).</p><p>An alternative iterative algorithm for the approx­imation of the partition function has been proposed by Etessami and Yannakakis (2009), based on New­ton's method for the solution of non-linear systems of equations. From a theoretical perspective, Kiefer et al. (2007) have shown that, after a certain number of initial iterations, Newton's method adds a ixed number of bits to the precision of the approximated solution, even in the above mentioned cases in which the ixed-point iteration method shows exponential time behaviour. However, these authors also show that, in some degenerate cases, the number of itera­tions needed to compute the irst bit of the solution can be at least exponential in the size of the system.</p><p>Experiments with Newton's method for the ap­proximation of the partition functions of PCFGs have been carried out in several application-oriented settings, by Wojtczak and Etessami (2007) and by Nederhof and Satta (2008), showing considerable improvements over the ixed-point iteration method.</p></section><section number="3" title="Intersection of PCFG and FA"><p>It was shown by Bar-Hillel et al. (1964) that context-free languages are closed under intersection with regular languages. Their proof relied on the con­struction of a new CFG out of an input CFG and an input inite automaton. Here we extend that con­struction by letting the input grammar be a proba­bilistic CFG. We refer the reader to (Nederhof and Satta, 2003) for more details.</p><p>To avoid a number of technical complications, we assume the inite automaton has no epsilon transi­tions, and has only one inal state. In the context of our use of this construction in the following sec­tions, these restrictions are without loss of general­ity. Thus, a finite automaton (FA) M is represented by a 5-tuple (E, Q, q0, qf, A), where E and Q are two inite sets of <b>terminals </b>and <b>states, </b>respectively, q0 is the <b>initial </b>state, qf is the <b>final </b>state, and A is a finite set of <b>transitions, </b>each of the form s —— t, where s, <i>t G </i>Q and a G <i>E</i>.</p><p>A <b>complete computation </b>of M accepting string <i>w</i><i> </i><i>=</i><i> </i><i>ai</i><i> </i><i>■</i><i> </i><i>■</i><i> </i><i>■</i><i> </i><i>an</i><i> </i>is a sequence c = n • • • r„ of tran­sitions such that Tj = (si_i — s^) for each i (1 &lt; <i>i &lt; </i>n), for some <i>s0, si, .</i><page local="5" global="1217"/><i>.., </i><i>sn</i><i> </i>with <i>s0</i><i> </i><i>=</i><i> </i><i>q0</i><i> </i>and <i>sn</i><i> </i><i>=</i><i> </i><i>q</i><i>f</i>. The language of all strings accepted by M is denoted by <i>L(M). </i>A FA is <b>unambiguous </b>if at most one complete computation exists for each ac­cepted string. A FA is <b>deterministic </b>if there is at most one transition s —— <i>t </i>for each s and a.</p><p>For a FA M as above and a PCFG G = <i>(E, N, S, R, p) </i>with the same set of terminals, we construct a new PCFG G' = <i>(E, N', S', </i><i>R',</i><i> p'), </i>where <i>N'</i><i> </i>= <i>Q</i><i> </i>x <i>(E</i><i> </i>U <i>N</i>) x <i>Q, </i>S' = <i>(q0, S, qf ), </i>and R' is the set of rules that is obtained as follows.</p><p>• For each <i>A </i>—&gt; Xi ■ ■ ■ <i>Xm </i>in R and each se­quence <i>s0, ..., </i><i>sm</i><i> </i>with si G Q, 0 &lt; i &lt; m, and m &gt; 0, let <i>(s0,A,s</i><i>m) </i><i>— </i>(so,Xi,si) ■ ■ ■ ( <i>s</i><i>m_ </i>i <i>,</i><i> </i><i>X</i><i>m, </i><i>s</i><i>m) </i>be in <i>R';</i><i> </i>if <i>m</i><i> </i>= 0, the new rule is of the form <i>(s0, </i><i>A,</i><i> s0) — e. </i>Function p' assigns the same probability to the new rule as <i>p </i>assigned to the original rule.</p><p>• For each <i>s</i><i> </i>—— <i>t</i><i> </i>in <i>A,</i><i> </i>let <i>(s, a,t) — a </i>be in R'. Function p' assigns probability 1 to this rule.</p><p>Intuitively, a rule of G' is either constructed out of a rule of G or out of a transition of M. On the basis of this correspondence between rules and transitions of G', G and M, it is not difficult to see that each derivation <i>dd</i><i> </i>in G' deriving string <i>w</i><i> </i>corresponds to a unique derivation <i>d </i>in G deriving the same string and a unique computation <i>c </i>in M accepting the same string. Conversely, if there is a derivation <i>d </i>in G deriving string <i>w, </i>and some computation <i>c </i>in M accepting the same string, then the pair of <i>d </i>and <i>c </i>corresponds to a unique derivation <i>d'</i><i> </i>in G' deriving the same string <i>w. </i>Furthermore, the probabilities of <i>d</i><i> </i>and <i>dd</i><i> </i>are equal, by definition of p'.</p><p>Let us now assume that each string <i>w </i>is accepted by at most one computation, i.e. M is unambigu­ous. If a string <i>w </i>is accepted by M, then there are as many derivations deriving <i>w </i>in G' as there are in G. If <i>w </i>is not accepted by M, then there are zero derivations deriving <i>w </i>in G'. Consequently:</p><doubt alpha="17.4" length="23" tooSmall="False" monospace="0.0">£    p'(d')   = £ p(d),</doubt><doubt alpha="53.6" length="28" tooSmall="False" monospace="0.0">d',w: d,w: S'^g,wS4SwAwGL(M)</doubt><p>or more succinctly:</p><p><i>p'(w) = p(w).</i></p><doubt alpha="71.4" length="7" tooSmall="False" monospace="0.0">wweL(M)</doubt><p>Note that the above construction ofG' is exponen­tial in the largest value of <i>m </i>in any rule from G. For this reason, G is usually brought in binary form be­fore the intersection, i.e. the input grammar is trans­formed to let each right-hand side have at most two members. Such a transformation can be realized in linear time in the size ofthe grammar. We will return to this issue in Section 7.</p></section><section number="4" title="Obtaining unambiguous FAs"><p>In the previous section, we explained that unambigu­ous finite automata have special properties with re­spect to the grammar G' that we may construct out of a FA M and a PCFG G. In this section we dis­cuss how unambiguity can be obtained for the spe­cial case of finite automata accepting the language of all strings with given infix <i>w</i><i> </i>G <i>E*</i><i> </i>:</p><p><i>L</i><i>infix</i><i>(w)   =   {xwy </i>| <i>x,y </i>G <i>E</i><i>*</i><i>}.</i></p><p>Any deterministic automaton is also unambigu­ous. Furthermore, there seem to be no practical al­gorithms that turn FAs into equivalent unambiguous FAs other than the algorithms that also determinize them. Therefore, we will henceforth concentrate on deterministic rather than unambiguous automata.</p><p>Given a string <i>w</i><i> </i><i>=</i><i> </i><i>ai</i><i> </i>■ ■ ■ an, a finite automaton accepting <i>L</i><i>infix </i><i>(w) </i>can be straightforwardly con­structed. This automaton has states <i>s</i><i>0,</i><i> </i><i>. . . , s</i><i>n, </i>tran­sitions <i>s0</i><i> </i>—— <i>s0</i><i> </i>and <i>sn</i><i> </i>—— <i>sn</i><i> </i>for each <i>a</i><i> </i>G <i>E</i>, and transition <i>sj_i </i>—<i>s</i><i>i </i>for each <i>i </i>(1 &lt; <i>i </i>&lt; n). The initial state is <i>s0</i><i> </i>and the final state is sn. Clearly, there is nondeterminism in state <i>s</i><i>0.</i></p><p>One way to make this automaton deterministic is to apply the general algorithm of determinization of finite automata; see e.g. (Aho and Ullman, 1972). This algorithm is exponential for general FAs. An alternative approach is to construct a deterministic finite automaton directly from w, in line with the Knuth-Morris-Pratt algorithm (Knuth et al., 1977; Gusfield, 1997). Both approaches result in the same deterministic FA, which we denote by <i>Iw</i>. However, the latter approach is easier to implement in such a way that the time complexity of constructing the au­tomaton is linear in | w |.<page local="6" global="1218"/></p><p>The automaton Iw is described as follows. There are n + 1 states to, • • •, tn, where as before n is the length of w. The initial state is <i>t0</i><i> </i>and the final state is <i>tn</i>. The intuition is that Iw reads a string <i>x</i><i> </i><i>=</i><i> </i><i>bi</i><i> </i>• • • bm from left to right, and when it has read the prefix bi • • • <i>b</i><i>j </i>(0 &lt; j &lt; m), it is in state <i>ti</i><i> </i>(0 &lt; <i>i &lt; n) </i>if and only if <i>ai</i><i> </i><i>•</i><i> </i><i>•</i><i> </i><i>•</i><i> </i>ai is the longest prefix of w that is also a suffix of bi • • • bj. If the automaton is in state <i>tn</i>, then this means that w is an infix of bi • • • bj.</p><p>In more detail, for each i (1 &lt; i &lt; n) and each <i>a</i><i> </i>G E, there is a transition <i>ti-i</i><i> </i>A <i>t</i><i>j</i>, where j is the length of the longest string that is both a prefix of w and a suffix of <i>ai</i><i> </i><i>•</i><i> </i><i>•</i><i> </i><i>•</i><i> </i><i>ai-ia.</i><i> </i>If <i>a</i><i> </i><i>=</i><i> </i><i>ai,</i><i> </i>then clearly j = i, and otherwise j &lt; i. To ensure that we remain in the final state once an occurrence of infix w has been found, we also add transitions tn A tnfor each <i>a </i>G <i>E</i>. This construction is illustrated in Figure 1.</p></section><section number="5" title="Infix probability"><p>With the material developed in the previous sections, the problem of computing the infix probabilities can be effectively solved. Our goal is to compute for given infix w G E* and PCFG G = (E, <i>N, S, R, </i>p):</p><p><i>&lt;7</i><i>infix </i><i>(w, </i>G)    = £ <i>P(z).</i></p><p>In Section 4 we have shown the construction of finite automaton <i>Iw</i><i> </i>accepting <i>L</i><i>lnfix </i><i>(w)</i>, by which we ob­tain:</p><p>Omfix(w, G)    =       £ <i>P(z).</i></p><doubt alpha="71.4" length="7" tooSmall="False" monospace="0.0">zeL(Zw)</doubt><p>As <i>Iw</i><i> </i>is deterministic and therefore unambiguous, the results from Section 3 apply and if G' = (E, N', <i>p')</i><i> </i>is the PCFG constructed out of G and Iw</p><doubt alpha="80.0" length="5" tooSmall="False" monospace="0.0">then:</doubt><p>Omfix(w, G)    =    £<i>p'(z).</i></p><doubt alpha="100.0" length="1" tooSmall="False" monospace="0.0">z</doubt><p>Finally, we can compute the above sum by applying the iterative method discussed in Section 2.</p></section><section number="6" title="Extensions"><p>The approach discussed above allows for a number of generalizations. First, we can replace the infix w by a <b>sequence </b>of infixes wi; ..., wm, which have to occur in the given order, one strictly after the other, with arbitrary infixes in between:</p><doubt alpha="57.9" length="19" tooSmall="False" monospace="0.0">^island(wi,—,wm,G)=</doubt><p>£       p(xowiXi ••• wmXm).</p><doubt alpha="41.7" length="12" tooSmall="False" monospace="0.0">x0,...,xmeE*</doubt><p>This problem was discussed before by (Corazza et al., 1991), who mentioned applications in speech recognition. Further applications are found in com­putational biology, but their discussion is beyond the scope of this paper; see for instance (Apostolico et al., 2005) and references therein. In order to solve the problem, we only need a small addition to the procedures we discussed before. First we construct separate automata <i>lWj </i>(1 &lt; j &lt; m) as explained in Section 4. These automata are then composed into a single automaton <i>I(W1</i><i> </i>,_,Wm). In this composition, the outgoing transitions of the final state of <i>IWj</i>, for each j (1 &lt; j &lt; m), are removed and that final state is merged with the initial state of the next automaton 2Wj+1. The initial state of the composed automaton is the initial state of <i>IW1</i>, and the final state is the final state of 2Wm. The time costs of constructing <i>I</i><i>{Wl^^,wm) </i>are linear in the sum of the lengths of the strings w<i>j.</i></p><p>Another way to generalize the problem is to re­place w by a finite set L = {wi,..., wm}. The ob­jective is to compute:</p><doubt alpha="47.8" length="23" tooSmall="False" monospace="0.0">Omfix(L, G)   =£ p(xwy)</doubt><p>Again, this can be solved by first constructing a de­terministic FA, which is then intersected with G. This FA can be obtained by determinizing a straight­forward nondeterministic FA accepting L, or by di­rectly constructing a deterministic FA along the lines of the Aho-Corasick algorithm (Aho and Corasick, 1975). Construction of the automaton with the latter approach takes linear time.</p><p>Further straightforward generalizations involve formalisms such as probabilistic tree adjoining grammars (Schabes, 1992; Resnik, 1992). The tech­nique from Section 3 is also applicable in this case, as the construction from Bar-Hillel et al. (1964) car­ries over from context-free grammars to tree ad­joining grammars, and more generally to the linear context-free rewriting systems of Vijay-Shanker et al. (1987).<page local="7" global="1219"/></p><figure caption="Figure 1: Deterministic automaton that accepts all strings over alphabet{a, b, c}with infixabac."></figure></section><section number="7" title="Implementation"><p>We have conducted experiments with the computa­tion of infix probabilities. The objective was to iden­tify parts of the computation that have a high time or space demand, and that might be improved. The experiments were run on a desktop with a 3.0 GHz Pentium 4 processor. The implementation language is C++.</p><p>The set-up of the experiments is similar to that in (Nederhof and Satta, 2008). A probabilistic context-free grammar was extracted from sections 2-21 of the Penn Treebank version II. Subtrees that gener­ated the empty string were systematically removed. The result was a CFG with 10,035 rules, 28 nonter­minals and 36 parts-of-speech. The rule probabili­ties were determined by maximum likelihood esti­mation. The grammar was subsequently binarized, to avoid exponential behaviour, as explained in Sec­tion 3.</p><p>We have considered 10 strings of length 7, ran­domly generated, assuming each of the parts-of-speech has the same probability. For all prefixes of those strings from length 2 to length 7, we then com­puted the infix probability. The duration of the full computation, averaged over the 10 strings of length 7, is given in the first row of Table 1.</p><p>In order to solve the non-linear systems of equa­tions, we used Broyden's method. It can be seen as an approximation of Newton's method. It re­quires more iterations, but seems to be faster over­all, and more scalable to large problem sizes, due to the avoidance of matrix inversion, which sometimes makes Newton's method prohibitively expensive. In our experiments, Broyden's method was generally faster than Newton's method and much faster than the simple iteration method by the relation in (4). For further details on Broyden's method, we refer the reader to (Kelley, 1995).</p><p>The main obstacle to computation for infixes sub­stantially longer than 7 symbols is the memory con­sumption rather than the running time. This is due to the required square matrices, the dimension of which is the number of nonterminals. The number of nonterminals (of the intersection grammar) natu­rally grows as the infix becomes longer.</p><p>As explained in Section 2, the problem is divided into smaller problems by isolating disjoint sets of mutually recursive nonterminals, or strongly con­nected components. We found that for the applica­tion to the automata discussed in Section 4, there were exactly three strongly connected components that contained more than one element, throughout the experiments. For an infix of length n, these com­ponents are:</p><p>• Ci, which consists of nonterminals of the form (ti, A, tj), where i &lt; n and j &lt; n,</p><p>• C2, which consists of nonterminals of the form (ti, A, tj), where i = j = n, and</p><p>• C3, which consists of nonterminals of the form ( t<i>i </i>, A, t<i>j </i>) , where i &lt; j = n.</p><p>This can be easily explained by looking at the struc­ture of our automata. See for example Figure 1, with cycles running through states t0,..., tn-i, and cy­cles through state tn. Furthermore, the grammar ex­tracted from the Penn Treebank is heavily recursive,<page local="8" global="1220"/></p><p>Table 1: Running time for infixes from length 2 to length 7. The infixes are prefixes of 10 random strings of length 7, and reported CPU times (in seconds) are averaged over the 10 strings.</p><p>so that almost every nonterminal can directly or in­directly call any other.</p><p>The strongly connected component C2 is always the same, consisting of 2402 nonterminals, for each inix of any length. (Note that binarization of the grammar introduced artiicial nonterminals.) The last three rows of Table 1 present the time costs of Broyden s method, for the three strongly connected components.</p><p>The strongly connected component C3 happens to correspond to a <i>linear</i><i> </i>system of equations. This is because a rule in the intersection grammar with a left-hand side <i>(ti,A,tj</i>), where <i>i &lt; j = n, </i>must have a right-hand side of the form (ti; <i>A', tj</i>), or of the form (ti, Ai, tk) (tk, A2, tj), with <i>k &lt; </i>n. If <i>k &lt; n, </i>then only the second member can be in C3. If k = n, only first member can be in C3. Hence, such a rule corresponds to a linear equation within the system of equations for the entire grammar.</p><p>A linear system of equations can be solved an­alytically, for example by Gaussian elimination, rather than approximated through Newton ' s method or Broyden s method. This means that the running times in the last row of Table 1 can be reduced by treating C3 differently from the other strongly con­nected components. However, the running time for Ci dominates the total time consumption.</p><p>The above investigations were motivated by two questions, namely whether any part of the computa­tion can be precomputed, and second, whether inix probabilities can be computed incrementally, for in-ixes that are extended to the left or to the right. The irst question can be answered afirmatively for C2, as it is always the same. However, as we can see in Table 1, the computation of C2 amounts to a small portion of the total time consumption.</p><p>The second question can be rephrased more pre­cisely as follows. Suppose we have computed the infix probability of a string w and have kept inter­mediate results in memory. Can the computation of the infix probability of a string of the form <i>aw </i>or wa, a G <i>E, </i>be computed by relying on the existing re­sults, so that the computation is substantially faster than if the computation were done from scratch?</p><p>Our investigations so far have not found a posi­tive answer to this second question. In particular, the systems of equations for Ci and C3 change fun­damentally if the inix is extended by one more sym­bol, which seems to at least make incremental com­putation very dificult, if not impossible. Note that the algorithms for the computation of preix prob­abilities by Jelinek and Lafferty (1991) and Stolcke (1995) do allow incrementality, which contributes to their practical usefulness for speech recognition.</p></section><section number="8" title="Conclusions"><p>We have shown that the problem of infix probabili­ties for PCFGs can be solved by a construction that intersects a context-free language with a regular lan­guage. An important constraint is that the inite automaton that is input to this construction be un­ambiguous. We have shown that such an automa­ton can be eficiently constructed. Once the input probabilistic PCFG and the FA have been combined into a new probabilistic CFG, the inix probability can be straightforwardly solved by iterative algo­rithms. Such algorithms include Newton s method, and Broyden ' s method, which was used in our exper­iments. Our discussion ended with an open question about the possibility of incremental computation of inix probabilities.</p><table class="main" frame="box" rules="all" border="0" regular="False"><tr class="row"><td class="cell"></td><td class="cell"></td><td class="cell"></td><td class="cell"></td><td class="cell"></td><td class="cell"></td><td class="cell"></td><td class="cell"></td><td class="cell"></td></tr><tr class="row"><td class="cell"></td><td class="cell"><p>infix length</p></td><td class="cell"><p>2</p></td><td class="cell"><p>3</p></td><td class="cell"><p>4</p></td><td class="cell"><p>5</p></td><td class="cell"><p>6</p></td><td class="cell"><p>7</p></td><td class="cell"></td></tr><tr class="row"><td class="cell"></td><td class="cell"><p>total running time</p></td><td class="cell"><p>1.07</p></td><td class="cell"><p>1.95</p></td><td class="cell"><p>5.84</p></td><td class="cell"><p>11.38</p></td><td class="cell"><p>23.93</p></td><td class="cell"><p>45.91</p></td><td class="cell"></td></tr><tr class="row"><td class="cell"></td><td class="cell"><p>Broyden's method for <i>C1</i></p></td><td class="cell"><p>0.46</p></td><td class="cell"><p>0.90</p></td><td class="cell"><p>3.42</p></td><td class="cell"><p>6.63</p></td><td class="cell"><p>12.91</p></td><td class="cell"><p>24.38</p></td><td class="cell"></td></tr><tr class="row"><td class="cell"></td><td class="cell"><p>Broyden's method for C2</p></td><td class="cell"><p>0.08</p></td><td class="cell"><p>0.04</p></td><td class="cell"><p>0.07</p></td><td class="cell"><p>0.04</p></td><td class="cell"><p>0.03</p></td><td class="cell"><p>0.09</p></td><td class="cell"></td></tr><tr class="row"><td class="cell"></td><td class="cell"><p>Broyden ' s method for C3</p></td><td class="cell"><p>0.20</p></td><td class="cell"><p>0.36</p></td><td class="cell"><p>0.81</p></td><td class="cell"><p>1.74</p></td><td class="cell"><p>5.30</p></td><td class="cell"><p>9.02</p></td><td class="cell"></td></tr><tr class="row"><td class="cell"></td><td class="cell"></td><td class="cell"></td><td class="cell"></td><td class="cell"></td><td class="cell"></td><td class="cell"></td><td class="cell"></td><td class="cell"></td></tr></table></section><references><p>S. Abney, D. McAllester, and F. Pereira. 1999. Relating probabilistic grammars and automata. In <i>37th Annual</i> <i>Meeting of the Association for Computational Linguis­tics, Proceedings of the Conference, </i>pages 542-549, Maryland, USA, June.<page local="9" global="1221"/></p><p>A.V. Aho and M.J. Corasick. 1975. Efficient string matching: an aid to bibliographic search. <i>Communi­cations of the ACM, </i>18(6):333-340, June.</p><p>A.V. Aho and J.D. Ullman. 1972. <i>Parsing, </i>volume 1 of <i>The Theory ofParsing, Translation and Compiling. </i>Prentice-Hall, Englewood Cliffs, N.J.</p><p>A. Apostolico, M. Comin, and L. Parida. 2005. Con­servative extraction of overrepresented extensible mo­tifs. In <i>Proceedings ofIntelligent Systems for Molecu­lar Biology (ISMB05).</i></p><p>Y. Bar-Hillel, M. Perles, and E. Shamir. 1964. On formal properties of simple phrase structure grammars. In Y. Bar-Hillel, editor, <i>Language and Information: Se­lected Essays on their Theory and Application, </i>chap­ter 9, pages 116-150. Addison-Wesley, Reading, Mas­sachusetts.</p><p>T.L. Booth and R.A. Thompson. 1973. Applying prob­abilistic measures to abstract languages. <i>IEEE Trans­actions on Computers, </i>C-22:442-450.</p><p>Z. Chi and S. Geman. 1998. Estimation of probabilis­tic context-free grammars. <i>Computational Linguistics,</i> 24(2):299-305.</p><p>Z. Chi. 1999. Statistical properties of probabilistic context-free grammars. <i>Computational Linguistics, </i>25(1):131-160.</p><p>A. Corazza, R. De Mori, R. Gretter, and G. Satta. 1991. Computation of probabilities for an island-driven parser. <i>IEEE Transactions on Pattern Analysis and Machine Intelligence, </i>13(9):936-950.</p><p>K. Etessami and M. Yannakakis. 2005. Recursive Markov chains, stochastic grammars, and monotone systems of nonlinear equations. In <i>22nd International Symposium on Theoretical Aspects ofComputer Sci­ence, </i>volume 3404 of <i>Lecture Notes in Computer Sci­ence, </i>pages 340-352, Stuttgart, Germany. Springer­Verlag.</p><p>K. Etessami and M. Yannakakis. 2009. Recursive Markov chains, stochastic grammars, and monotone systems of nonlinear equations. <i>Journal ofthe ACM, </i>56(1):1-66.</p><p>A.L.N. Fred. 2000. Computation of substring proba­bilities in stochastic grammars. In A. Oliveira, edi­tor, <i>Grammatical Inference: Algorithms and Applica­tions, </i>volume 1891 of <i>Lecture Notes in Artificial Intel­ligence, </i>pages 103-114. Springer-Verlag.</p><p>D. Gusield. 1997. <i>Algorithms on Strings, Trees, and Sequences. </i>Cambridge University Press, Cambridge.</p><p>T.E. Harris. 1963. <i>The Theory of Branching Processes. </i>Springer-Verlag, Berlin, Germany.</p><p>F. Jelinek and J.D. Lafferty. 1991. Computation of the probability of initial substring generation by stochas­tic context-free grammars. <i>Computational Linguistics,</i> 17(3):315-323.</p><p>C. T. Kelley. 1995. <i>Iterative Methods for Linear and Nonlinear Equations. </i>Society for Industrial and Ap­plied Mathematics, Philadelphia, PA.</p><p>S. Kiefer, M. Luttenberger, and J. Esparza. 2007. On the convergence of Newton s method for monotone sys­tems of polynomial equations. In <i>Proceedings ofthe 39th ACM Symposium on Theory of Computing, </i>pages 217-266.</p><p>D. E. Knuth, J.H. Morris, Jr., and V.R. Pratt. 1977. Fast pattern matching in strings. <i>SIAMJournal on Comput­ing, </i>6:323-350.</p><p>M.-J. Nederhof and G. Satta. 2003. Probabilistic pars­ing as intersection. In <i>8th International Workshop on Parsing Technologies, </i>pages 137-148, LORIA, Nancy, France, April.</p><p>M.-J. Nederhof and G. Satta. 2008. Computing parti­tion functions of PCFGs. <i>Research on Language and Computation, </i>6(2):139-162.</p><p>E. Persoon and K.S. Fu. 1975. Sequential classification of strings generated by SCFG s. <i>International Journal of Computer and Information Sciences, </i>4(3):205-217.</p><p>P. Resnik. 1992. Probabilistic tree-adjoining grammar as a framework for statistical natural language process­ing. In <i>Proc. of the fifteenth International Conference on Computational Linguistics, </i>Nantes, August, pages 418-424.</p><p>J.-A. Sanchez and J.-M. Benedf. 1997. Consistency of stochastic context-free grammars from probabilis­tic estimation based on growth transformations. <i>IEEE Transactions on Pattern Analysis and Machine Intelli­gence, </i>19(9):1052-1055, September.</p><p>Y. Schabes. 1992. Stochastic lexicalized tree-adjoining grammars. In <i>Proc. of the fifteenth International Con­ference on Computational Linguistics, </i>Nantes, Au­gust, pages 426-432.</p><p>A. Stolcke. 1995. An efficient probabilistic context-free parsing algorithm that computes preix probabilities. <i>Computational Linguistics, </i>21(2):167-201.</p><p>K. Vijay-Shanker, D.J. Weir, and A.K. Joshi. 1987.</p><p>Characterizing structural descriptions produced by various grammatical formalisms. In <i>25th Annual Meeting ofthe Association for Computational Linguis­tics, Proceedings </i><i>ofthe</i><i> Conference, </i>pages 104-111, Stanford, California, USA, July. D. Wojtczak and K. Etessami. 2007. PReMo: an an­alyzer for Probabilistic Recursive Models. In <i>Tools and Algorithms for the Construction and Analysis of Systems, 13th International Conference, </i>volume 4424 of <i>Lecture Notes in Computer Science, </i>pages 66-71, Braga, Portugal. Springer-Verlag.</p></references></body></article>