nltk.parse.NaiveBayesDependencyScorer¶
- class nltk.parse.NaiveBayesDependencyScorer[source]¶
Bases:
DependencyScorerI
A dependency scorer built around a MaxEnt classifier. In this particular class that classifier is a
NaiveBayesClassifier
. It uses head-word, head-tag, child-word, and child-tag features for classification.>>> from nltk.parse.dependencygraph import DependencyGraph, conll_data2
>>> graphs = [DependencyGraph(entry) for entry in conll_data2.split('\n\n') if entry] >>> npp = ProbabilisticNonprojectiveParser() >>> npp.train(graphs, NaiveBayesDependencyScorer()) >>> parses = npp.parse(['Cathy', 'zag', 'hen', 'zwaaien', '.'], ['N', 'V', 'Pron', 'Adj', 'N', 'Punc']) >>> len(list(parses)) 1
- train(graphs)[source]¶
Trains a
NaiveBayesClassifier
using the edges present in graphs list as positive examples, the edges not present as negative examples. Uses a feature vector of head-word, head-tag, child-word, and child-tag.- Parameters
graphs (list(DependencyGraph)) – A list of dependency graphs to train the scorer.
- score(graph)[source]¶
Converts the graph into a feature-based representation of each edge, and then assigns a score to each based on the confidence of the classifier in assigning it to the positive label. Scores are returned in a multidimensional list.
- Parameters
graph (DependencyGraph) – A dependency graph to score.
- Return type
3 dimensional list
- Returns
Edge scores for the graph parameter.