Probabilistic context-free grammar

From testwiki
Jump to navigation Jump to search

In theoretical linguistics and computational linguistics, probabilistic context free grammars (PCFGs) extend context-free grammars, similar to how hidden Markov models extend regular grammars. Each production is assigned a probability. The probability of a derivation (parse) is the product of the probabilities of the productions used in that derivation. These probabilities can be viewed as parameters of the model, and for large problems it is convenient to learn these parameters via machine learning. A probabilistic grammar's validity is constrained by context of its training dataset.

PCFGs originated from grammar theory, and have application in areas as diverse as natural language processing to the study the structure of RNA molecules and design of programming languages. Designing efficient PCFGs has to weigh factors of scalability and generality. Issues such as grammar ambiguity must be resolved. The grammar design affects results accuracy. Grammar parsing algorithms have various time and memory requirements.

Definitions

Derivation: The process of recursive generation of strings from a grammar.

Parsing: Finding a valid derivation using an automaton.

Parse Tree: The alignment of the grammar to a sequence.

An example of a parser for PCFG grammars is the pushdown automaton. The algorithm parses grammar nonterminals from left to right in a stack-like manner. This brute-force approach is not very efficient. In RNA secondary structure prediction variants of the Cocke–Younger–Kasami (CYK) algorithm provide more efficient alternatives to grammar parsing than pushdown automata.[1] Another example of a PCFG parser is the Stanford Statistical Parser which has been trained using Treebank.[2]

Formal definition

Similar to a CFG, a probabilistic context-free grammar Template:Mvar can be defined by a quintuple:

G=(M,T,R,S,P)

where

Relation with hidden Markov models

PCFGs models extend context-free grammars the same way as hidden Markov models extend regular grammars.

The Inside-Outside algorithm is an analogue of the Forward-Backward algorithm. It computes the total probability of all derivations that are consistent with a given sequence, based on some PCFG. This is equivalent to the probability of the PCFG generating the sequence, and is intuitively a measure of how consistent the sequence is with the given grammar. The Inside-Outside algorithm is used in model parametrization to estimate prior frequencies observed from training sequences in the case of RNAs.

Dynamic programming variants of the CYK algorithm find the Viterbi parse of a RNA sequence for a PCFG model. This parse is the most likely derivation of the sequence by the given PCFG.

Grammar construction

Context-free grammars are represented as a set of rules inspired from attempts to model natural languages.[3][4][5] The rules are absolute and have a typical syntax representation known as Backus–Naur form. The production rules consist of terminal {a,b} and non-terminal Template:Mvar symbols and a blank ϵ may also be used as an end point. In the production rules of CFG and PCFG the left side has only one nonterminal whereas the right side can be any string of terminal or nonterminals. In PCFG nulls are excluded.[1] An example of a grammar:

SaS,SbS,Sϵ

This grammar can be shortened using the '|' ('or') character into:

SaS|bS|ϵ

Terminals in a grammar are words and through the grammar rules a non-terminal symbol is transformed into a string of either terminals and/or non-terminals. The above grammar is read as "beginning from a non-terminal Template:Mvar the emission can generate either Template:Mvar or Template:Mvar or ϵ". Its derivation is:

SaSabSabbSabb

Ambiguous grammar may result in ambiguous parsing if applied on homographs since the same word sequence can have more than one interpretation. Pun sentences such as the newspaper headline "Iraqi Head Seeks Arms" are an example of ambiguous parses.

One strategy of dealing with ambiguous parses (originating with grammarians as early as Pāṇini) is to add yet more rules, or prioritize them so that one rule takes precedence over others. This, however, has the drawback of proliferating the rules, often to the point where they become difficult to manage. Another difficulty is overgeneration, where unlicensed structures are also generated.

Probabilistic grammars circumvent these problems by ranking various productions on frequency weights, resulting in a "most likely" (winner-take-all) interpretation. As usage patterns are altered in diachronic shifts, these probabilistic rules can be re-learned, thus updating the grammar.

Assigning probability to production rules makes a PCFG. These probabilities are informed by observing distributions on a training set of similar composition to the language to be modeled. On most samples of broad language, probabilistic grammars where probabilities are estimated from data typically outperform hand-crafted grammars. CFGs when contrasted with PCFGs are not applicable to RNA structure prediction because while they incorporate sequence-structure relationship they lack the scoring metrics that reveal a sequence structural potential [6]

Weighted context-free grammar

A weighted context-free grammar (WCFG) is a more general category of context-free grammar, where each production has a numeric weight associated with it. The weight of a specific parse tree in a WCFG is the product[7] (or sum[8] ) of all rule weights in the tree. Each rule weight is included as often as the rule is used in the tree. A special case of WCFGs are PCFGs, where the weights are (logarithms of [9][10]) probabilities.

An extended version of the CYK algorithm can be used to find the "lightest" (least-weight) derivation of a string given some WCFG.

When the tree weight is the product of the rule weights, WCFGs and PCFGs can express the same set of probability distributions.[7]

Applications

RNA structure prediction

Since the 1990s, PCFG has been applied to model RNA structures.[11][12][13][14][15]

Energy minimization[16][17] and PCFG provide ways of predicting RNA secondary structure with comparable performance.[11][12][1] However structure prediction by PCFGs is scored probabilistically rather than by minimum free energy calculation. PCFG model parameters are directly derived from frequencies of different features observed in databases of RNA structures [6] rather than by experimental determination as is the case with energy minimization methods.[18][19]

The types of various structure that can be modeled by a PCFG include long range interactions, pairwise structure and other nested structures. However, pseudoknots can not be modeled.[11][12][1] PCFGs extend CFG by assigning probabilities to each production rule. A maximum probability parse tree from the grammar implies a maximum probability structure. Since RNAs preserve their structures over their primary sequence, RNA structure prediction can be guided by combining evolutionary information from comparative sequence analysis with biophysical knowledge about a structure plausibility based on such probabilities. Also search results for structural homologs using PCFG rules are scored according to PCFG derivations probabilities. Therefore, building grammar to model the behavior of base-pairs and single-stranded regions starts with exploring features of structural multiple sequence alignment of related RNAs.[1]

SaSa|bSb|aa|bb

The above grammar generates a string in an outside-in fashion, that is the basepair on the furthest extremes of the terminal is derived first. So a string such as aabaabaa is derived by first generating the distal Template:Mvar's on both sides before moving inwards:

SaSaaaSaaaabSbaaaabaabaa

A PCFG model extendibility allows constraining structure prediction by incorporating expectations about different features of an RNA . Such expectation may reflect for example the propensity for assuming a certain structure by an RNA.[6] However incorporation of too much information may increase PCFG space and memory complexity and it is desirable that a PCFG-based model be as simple as possible.[6][20]

Every possible string Template:Mvar a grammar generates is assigned a probability weight P(x|θ) given the PCFG model θ. It follows that the sum of all probabilities to all possible grammar productions is xP(x|θ)=1. The scores for each paired and unpaired residue explain likelihood for secondary structure formations. Production rules also allow scoring loop lengths as well as the order of base pair stacking hence it is possible to explore the range of all possible generations including suboptimal structures from the grammar and accept or reject structures based on score thresholds.[1][6]

Implementations

RNA secondary structure implementations based on PCFG approaches can be utilized in :

  • Finding consensus structure by optimizing structure joint probabilities over MSA.[20][21]
  • Modeling base-pair covariation to detecting homology in database searches.[11]
  • pairwise simultaneous folding and alignment.[22][23]

Different implementation of these approaches exist. For example, Pfold is used in secondary structure prediction from a group of related RNA sequences,[20] covariance models are used in searching databases for homologous sequences and RNA annotation and classification,[11][24] RNApromo, CMFinder and TEISER are used in finding stable structural motifs in RNAs.[25][26][27]

Design considerations

PCFG design impacts the secondary structure prediction accuracy. Any useful structure prediction probabilistic model based on PCFG has to maintain simplicity without much compromise to prediction accuracy. Too complex a model of excellent performance on a single sequence may not scale.[1] A grammar based model should be able to:

  • Find the optimal alignment between a sequence and the PCFG.
  • Score the probability of the structures for the sequence and subsequences.
  • Parameterize the model by training on sequences/structures.
  • Find the optimal grammar parse tree (CYK algorithm).
  • Check for ambiguous grammar (Conditional Inside algorithm).

The resulting of multiple parse trees per grammar denotes grammar ambiguity. This may be useful in revealing all possible base-pair structures for a grammar. However an optimal structure is the one where there is one and only one correspondence between the parse tree and the secondary structure.

Two types of ambiguities can be distinguished. Parse tree ambiguity and structural ambiguity. Structural ambiguity does not affect thermodynamic approaches as the optimal structure selection is always on the basis of lowest free energy scores.[6] Parse tree ambiguity concerns the existence of multiple parse trees per sequence. Such an ambiguity can reveal all possible base-paired structures for the sequence by generating all possible parse trees then finding the optimal one.[28][29][30] In the case of structural ambiguity multiple parse trees describe the same secondary structure. This obscures the CYK algorithm decision on finding an optimal structure as the correspondence between the parse tree and the structure is not unique.[31] Grammar ambiguity can be checked for by the conditional-inside algorithm.[1][6]

Building a PCFG model

A probabilistic context free grammar consists of terminal and nonterminal variables. Each feature to be modeled has a production rule that is assigned a probability estimated from a training set of RNA structures. Production rules are recursively applied until only terminal residues are left.

A starting non-terminal 𝑆 produces loops. The rest of the grammar proceeds with parameter 𝐿 that decide whether a loop is a start of a stem or a single stranded region Template:Mvar and parameter 𝐹 that produces paired bases.

The formalism of this simple PCFG looks like:

𝑆𝐿𝑆|𝐿
𝐿𝑠|𝑑𝐹𝑑
𝐹𝑑𝐹𝑑|𝐿𝑆

The application of PCFGs in predicting structures is a multi-step process. In addition, the PCFG itself can be incorporated into probabilistic models that consider RNA evolutionary history or search homologous sequences in databases. In an evolutionary history context inclusion of prior distributions of RNA structures of a structural alignment in the production rules of the PCFG facilitates good prediction accuracy.[21]

A summary of general steps for utilizing PCFGs in various scenarios:

  • Generate production rules for the sequences.
  • Check ambiguity.
  • Recursively generate parse trees of the possible structures using the grammar.
  • Rank and score the parse trees for the most plausible sequence.[1]

Algorithms

Several algorithms dealing with aspects of PCFG based probabilistic models in RNA structure prediction exist. For instance the inside-outside algorithm and the CYK algorithm. The inside-outside algorithm is a recursive dynamic programming scoring algorithm that can follow expectation-maximization paradigms. It computes the total probability of all derivations that are consistent with a given sequence, based on some PCFG. The inside part scores the subtrees from a parse tree and therefore subsequences probabilities given an PCFG. The outside part scores the probability of the complete parse tree for a full sequence.[32][33] CYK modifies the inside-outside scoring. Note that the term 'CYK algorithm' describes the CYK variant of the inside algorithm that finds an optimal parse tree for a sequence using a PCFG. It extends the actual CYK algorithm used in non-probabilistic CFGs.[1]

The inside algorithm calculates α(i,j,v) probabilities for all i,j,v of a parse subtree rooted at Wv for subsequence xi,...,xj. Outside algorithm calculates β(i,j,v) probabilities of a complete parse tree for sequence Template:Mvar from root excluding the calculation of xi,...,xj. The variables Template:Mvar and Template:Mvar refine the estimation of probability parameters of an PCFG. It is possible to reestimate the PCFG algorithm by finding the expected number of times a state is used in a derivation through summing all the products of Template:Mvar and Template:Mvar divided by the probability for a sequence Template:Mvar given the model P(x|θ). It is also possible to find the expected number of times a production rule is used by an expectation-maximization that utilizes the values of Template:Mvar and Template:Mvar.[32][33] The CYK algorithm calculates γ(i,j,v) to find the most probable parse tree π^ and yields logP(x,π^|θ).[1]

Memory and time complexity for general PCFG algorithms in RNA structure predictions are O(L2M) and O(L3M3) respectively. Restricting a PCFG may alter this requirement as is the case with database searches methods.

Covariance models (CMs) are a special type of PCFGs with applications in database searches for homologs, annotation and RNA classification. Through CMs it is possible to build PCFG-based RNA profiles where related RNAs can be represented by a consensus secondary structure.[11][12] The RNA analysis package Infernal uses such profiles in inference of RNA alignments.[34] The Rfam database also uses CMs in classifying RNAs into families based on their structure and sequence information.[24]

CMs are designed from a consensus RNA structure. A CM allows indels of unlimited length in the alignment. Terminals constitute states in the CM and the transition probabilities between the states is 1 if no indels are considered.[1] Grammars in a CM are as follows:

PaWb
probabilities of pairwise interactions between 16 possible pairs
LaW
probabilities of generating 4 possible single bases on the left
RWa
probabilities of generating 4 possible single bases on the right
BSS
bifurcation with a probability of 1
SW
start with a probability of 1
Eϵ
end with a probability of 1

The model has 6 possible states and each state grammar includes different types of secondary structure probabilities of the non-terminals. The states are connected by transitions. Ideally current node states connect to all insert states and subsequent node states connect to non-insert states. In order to allow insertion of more than one base insert states connect to themselves.[1]

In order to score a CM model the inside-outside algorithms are used. CMs use a slightly different implementation of CYK. Log-odds emission scores for the optimum parse tree - loge^ - are calculated out of the emitting states P,L,R. Since these scores are a function of sequence length a more discriminative measure to recover an optimum parse tree probability score- logP(x,π^|θ) - is reached by limiting the maximum length of the sequence to be aligned and calculating the log-odds relative to a null. The computation time of this step is linear to the database size and the algorithm has a memory complexity of O(MaD+MbD2).[1]

Example: Using evolutionary information to guide structure prediction

The KH-99 algorithm by Knudsen and Hein lays the basis of the Pfold approach to predicting RNA secondary structure.[20] In this approach the parameterization requires evolutionary history information derived from an alignment tree in addition to probabilities of columns and mutations. The grammar probabilities are observed from a training dataset.

Estimate column probabilities for paired and unpaired bases

In a structural alignment the probabilities of the unpaired bases columns and the paired bases columns are independent of other columns. By counting bases in single base positions and paired positions one obtains the frequencies of bases in loops and stems. For basepair Template:Mvar and Template:Mvar an occurrence of XY is also counted as an occurrence of YX. Identical basepairs such as XX are counted twice.

Calculate mutation rates for paired and unpaired bases

By pairing sequences in all possible ways overall mutation rates are estimated. In order to recover plausible mutations a sequence identity threshold should be used so that the comparison is between similar sequences. This approach uses 85% identity threshold between pairing sequences. First single base positions differences -except for gapped columns- between sequence pairs are counted such that if the same position in two sequences had different bases Template:Mvar the count of the difference is incremented for each sequence.

Template:Nowrap
               Template:Nowrap
               Template:Nowrap
Template:Nowrap
               Template:Nowrap
               Template:Nowrap
               Template:Nowrap

For unpaired bases a 4 X 4 mutation rate matrix is used that satisfies that the mutation flow from X to Y is reversible:[35]

PXrXY=PYrYX

For basepairs a 16 X 16 rate distribution matrix is similarly generated.[36][37] The PCFG is used to predict the prior probability distribution of the structure whereas posterior probabilities are estimated by the inside-outside algorithm and the most likely structure is found by the CYK algorithm.[20]

Estimate alignment probabilities

After calculating the column prior probabilities the alignment probability is estimated by summing over all possible secondary structures. Any column Template:Mvar in a secondary structure σ for a sequence Template:Mvar of length Template:Mvar such that D=(C1,C2,...Cl) can be scored with respect to the alignment tree Template:Mvar and the mutational model Template:Mvar. The prior distribution given by the PCFG is P(σ|M). The phylogenetic tree, Template:Mvar can be calculated from the model by maximum likelihood estimation. Note that gaps are treated as unknown bases and the summation can be done through dynamic programming.[38]

P(D|T,M)
=P(D,σ|T,M)
=P(D|σ,T,M)P(σ|T,M)
=P(D|σ,T,M)P(σ|M)
Assign production probabilities to each rule in the grammar

Each structure in the grammar is assigned production probabilities devised from the structures of the training dataset. These prior probabilities give weight to predictions accuracy.[21][32][33] The number of times each rule is used depends on the observations from the training dataset for that particular grammar feature. These probabilities are written in parentheses in the grammar formalism and each rule will have a total of 100%.[20] For instance:

SLS(80%)|L(20%)
Ls(70%)|dFd(30%)
FdFd(60.4%)|LS(39.6%)
Predict the structure likelihood

Given the prior alignment frequencies of the data the most likely structure from the ensemble predicted by the grammar can then be computed by maximizing P(σ|D,T,M) through the CYK algorithm. The structure with the highest predicted number of correct predictions is reported as the consensus structure.[20]

σMAP=argmaxσP(D|σ,TML,M)P(σ|M)
Pfold improvements on the KH-99 algorithm

PCFG based approaches are desired to be scalable and general enough. Compromising speed for accuracy needs to as minimal as possible. Pfold addresses the limitations of the KH-99 algorithm with respect to scalability, gaps, speed and accuracy.[20]

  • In Pfold gaps are treated as unknown. In this sense the probability of a gapped column equals that of an ungapped one.
  • In Pfold the tree Template:Mvar is calculated prior to structure prediction through neighbor joining and not by maximum likelihood through the PCFG grammar. Only the branch lengths are adjusted to maximum likelihood estimates.
  • An assumption of Pfold is that all sequences have the same structure. Sequence identity threshold and allowing a 1% probability that any nucleotide becomes another limit the performance deterioration due to alignment errors.

Protein sequence analysis

Whereas PCFGs have proved powerful tools for predicting RNA secondary structure, usage in the field of protein sequence analysis has been limited. Indeed, the size of the amino acid alphabet and the variety of interactions seen in proteins make grammar inference much more challenging.[39] As a consequence, most applications of formal language theory to protein analysis have been mainly restricted to the production of grammars of lower expressive power to model simple functional patterns based on local interactions.[40][41] Since protein structures commonly display higher-order dependencies including nested and crossing relationships, they clearly exceed the capabilities of any CFG.[39] Still, development of PCFGs allows expressing some of those dependencies and providing the ability to model a wider range of protein patterns.

See also

References

Template:Reflist

  1. 1.00 1.01 1.02 1.03 1.04 1.05 1.06 1.07 1.08 1.09 1.10 1.11 1.12 1.13 Cite error: Invalid <ref> tag; no text was provided for refs named Durbin 1998
  2. Template:Cite journal
  3. Cite error: Invalid <ref> tag; no text was provided for refs named Chomsky_1956
  4. Cite error: Invalid <ref> tag; no text was provided for refs named Chomsky_1959
  5. Cite error: Invalid <ref> tag; no text was provided for refs named Chomsky_1957
  6. 6.0 6.1 6.2 6.3 6.4 6.5 6.6 Cite error: Invalid <ref> tag; no text was provided for refs named Dowell 2004
  7. 7.0 7.1 Template:Cite journal
  8. Template:Cite book
  9. Template:Cite web
  10. Template:Cite journal
  11. 11.0 11.1 11.2 11.3 11.4 11.5 Cite error: Invalid <ref> tag; no text was provided for refs named Eddy 1994
  12. 12.0 12.1 12.2 12.3 Cite error: Invalid <ref> tag; no text was provided for refs named Sakakibara 1994
  13. Cite error: Invalid <ref> tag; no text was provided for refs named Grat 1995
  14. Cite error: Invalid <ref> tag; no text was provided for refs named Lefebvre 1995
  15. Cite error: Invalid <ref> tag; no text was provided for refs named Lefebvre 1996
  16. Cite error: Invalid <ref> tag; no text was provided for refs named McCaskill 1990
  17. Cite error: Invalid <ref> tag; no text was provided for refs named Juan 1999
  18. Cite error: Invalid <ref> tag; no text was provided for refs named Zuker 2000
  19. Cite error: Invalid <ref> tag; no text was provided for refs named Mathews 1999
  20. 20.0 20.1 20.2 20.3 20.4 20.5 20.6 20.7 Cite error: Invalid <ref> tag; no text was provided for refs named Knudsen 2003
  21. 21.0 21.1 21.2 Cite error: Invalid <ref> tag; no text was provided for refs named Knudsen 1999
  22. Cite error: Invalid <ref> tag; no text was provided for refs named Rivas 2001
  23. Cite error: Invalid <ref> tag; no text was provided for refs named Holmes 2002
  24. 24.0 24.1 Cite error: Invalid <ref> tag; no text was provided for refs named Gardner 2010
  25. Cite error: Invalid <ref> tag; no text was provided for refs named Yao 2006
  26. Cite error: Invalid <ref> tag; no text was provided for refs named Rabani 2008
  27. Cite error: Invalid <ref> tag; no text was provided for refs named Goodarzi 2012
  28. Cite error: Invalid <ref> tag; no text was provided for refs named Sipser 1996
  29. Cite error: Invalid <ref> tag; no text was provided for refs named Harrison 1978
  30. Cite error: Invalid <ref> tag; no text was provided for refs named Hopcroft 1979
  31. Cite error: Invalid <ref> tag; no text was provided for refs named Giegerich 2000
  32. 32.0 32.1 32.2 Cite error: Invalid <ref> tag; no text was provided for refs named Lari and Young 1990
  33. 33.0 33.1 33.2 Cite error: Invalid <ref> tag; no text was provided for refs named Lari and Young 1991
  34. Cite error: Invalid <ref> tag; no text was provided for refs named Nawrocki 2013
  35. Cite error: Invalid <ref> tag; no text was provided for refs named Tavaré 1986
  36. Cite error: Invalid <ref> tag; no text was provided for refs named Muse 1995
  37. Cite error: Invalid <ref> tag; no text was provided for refs named Schöniger 1994
  38. Cite error: Invalid <ref> tag; no text was provided for refs named Baker 1979
  39. 39.0 39.1 Template:Cite journal
  40. Template:Cite journal
  41. Template:Cite journal