class documentation

class ProbabilisticProjectiveDependencyParser(object): (source)

Constructor: ProbabilisticProjectiveDependencyParser()

View In Hierarchy

A probabilistic, projective dependency parser.

This parser returns the most probable projective parse derived from the probabilistic dependency grammar derived from the train() method. The probabilistic model is an implementation of Eisner's (1996) Model C, which conditions on head-word, head-tag, child-word, and child-tag. The decoding uses a bottom-up chart-based span concatenation algorithm that's identical to the one utilized by the rule-based projective parser.

Usage example

>>> from nltk.parse.dependencygraph import conll_data2
>>> graphs = [
... DependencyGraph(entry) for entry in conll_data2.split('\n\n') if entry
... ]
>>> ppdp = ProbabilisticProjectiveDependencyParser()
>>> ppdp.train(graphs)
>>> sent = ['Cathy', 'zag', 'hen', 'wild', 'zwaaien', '.']
>>> list(ppdp.parse(sent))
[Tree('zag', ['Cathy', 'hen', Tree('zwaaien', ['wild', '.'])])]
Method __init__ Create a new probabilistic dependency parser. No additional operations are necessary.
Method compute_prob Computes the probability of a dependency graph based on the parser's probability model (defined by the parser's statistical dependency grammar).
Method concatenate Concatenates the two spans in whichever way possible. This includes rightward concatenation (from the leftmost word of the leftmost span to the rightmost word of the rightmost span) and leftward concatenation (vice-versa) between adjacent spans...
Method parse Parses the list of tokens subject to the projectivity constraint and the productions in the parser's grammar. This uses a method similar to the span-concatenation algorithm defined in Eisner (1996). It returns the most probable parse derived from the parser's probabilistic dependency grammar.
Method train Trains a ProbabilisticDependencyGrammar based on the list of input DependencyGraphs. This model is an implementation of Eisner's (1996) Model C, which derives its statistics from head-word, head-tag, child-word, and child-tag relationships.
Instance Variable _grammar Undocumented
Instance Variable _tokens Undocumented
def __init__(self): (source)

Create a new probabilistic dependency parser. No additional operations are necessary.

def compute_prob(self, dg): (source)

Computes the probability of a dependency graph based on the parser's probability model (defined by the parser's statistical dependency grammar).

Parameters
dg:DependencyGraphA dependency graph to score.
Returns
intThe probability of the dependency graph.
def concatenate(self, span1, span2): (source)

Concatenates the two spans in whichever way possible. This includes rightward concatenation (from the leftmost word of the leftmost span to the rightmost word of the rightmost span) and leftward concatenation (vice-versa) between adjacent spans. Unlike Eisner's presentation of span concatenation, these spans do not share or pivot on a particular word/word-index.

Returns
list(DependencySpan)A list of new spans formed through concatenation.
def parse(self, tokens): (source)

Parses the list of tokens subject to the projectivity constraint and the productions in the parser's grammar. This uses a method similar to the span-concatenation algorithm defined in Eisner (1996). It returns the most probable parse derived from the parser's probabilistic dependency grammar.

def train(self, graphs): (source)

Trains a ProbabilisticDependencyGrammar based on the list of input DependencyGraphs. This model is an implementation of Eisner's (1996) Model C, which derives its statistics from head-word, head-tag, child-word, and child-tag relationships.

Parameters
graphsA list of dependency graphs to train from.
_grammar = (source)

Undocumented

Undocumented