nltk.tag.brill module¶
- class nltk.tag.brill.BrillTagger[source]¶
Bases:
TaggerI
Brill’s transformational rule-based tagger. Brill taggers use an initial tagger (such as
tag.DefaultTagger
) to assign an initial tag sequence to a text; and then apply an ordered list of transformational rules to correct the tags of individual tokens. These transformation rules are specified by theTagRule
interface.Brill taggers can be created directly, from an initial tagger and a list of transformational rules; but more often, Brill taggers are created by learning rules from a training corpus, using one of the TaggerTrainers available.
- batch_tag_incremental(sequences, gold)[source]¶
Tags by applying each rule to the entire corpus (rather than all rules to a single sequence). The point is to collect statistics on the test set for individual rules.
NOTE: This is inefficient (does not build any index, so will traverse the entire corpus N times for N rules) – usually you would not care about statistics for individual rules and thus use batch_tag() instead
- Parameters
sequences (list of list of strings) – lists of token sequences (sentences, in some applications) to be tagged
gold (list of list of strings) – the gold standard
- Returns
tuple of (tagged_sequences, ordered list of rule scores (one for each rule))
- json_tag = 'nltk.tag.BrillTagger'¶
- print_template_statistics(test_stats=None, printunused=True)[source]¶
Print a list of all templates, ranked according to efficiency.
If test_stats is available, the templates are ranked according to their relative contribution (summed for all rules created from a given template, weighted by score) to the performance on the test set. If no test_stats, then statistics collected during training are used instead. There is also an unweighted measure (just counting the rules). This is less informative, though, as many low-score rules will appear towards end of training.
- Parameters
test_stats (dict of str -> any (but usually numbers)) – dictionary of statistics collected during testing
printunused (bool) – if True, print a list of all unused templates
- Returns
None
- Return type
None
- rules()[source]¶
Return the ordered list of transformation rules that this tagger has learnt
- Returns
the ordered list of transformation rules that correct the initial tagging
- Return type
list of Rules
- class nltk.tag.brill.Pos[source]¶
Bases:
Feature
Feature which examines the tags of nearby tokens.
- json_tag = 'nltk.tag.brill.Pos'¶
- class nltk.tag.brill.Word[source]¶
Bases:
Feature
Feature which examines the text (word) of nearby tokens.
- json_tag = 'nltk.tag.brill.Word'¶
- nltk.tag.brill.describe_template_sets()[source]¶
Print the available template sets in this demo, with a short description”
- nltk.tag.brill.fntbl37()[source]¶
Return 37 templates taken from the postagging task of the fntbl distribution https://www.cs.jhu.edu/~rflorian/fntbl/ (37 is after excluding a handful which do not condition on Pos[0]; fntbl can do that but the current nltk implementation cannot.)