nltk.parse.ProbabilisticProjectiveDependencyParser

class nltk.parse.ProbabilisticProjectiveDependencyParser[source]

Bases: object

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', '.'])])]
__init__()[source]

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

parse(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.

concatenate(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

A list of new spans formed through concatenation.

Return type

list(DependencySpan)

train(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

graphs – A list of dependency graphs to train from.

Type

list(DependencyGraph)

compute_prob(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 (DependencyGraph) – A dependency graph to score.

Returns

The probability of the dependency graph.

Return type

int