简体   繁体   中英

NLTK PoS tagging

I'm new in Python and need it for PoS tagging. Therefore I tried to use the standard tools. I tried to create a tagger and get a ValueError, that I don't understand. My code:

import nltk
tagged_sents = nltk.corpus.brown.tagged_sents(categories = 'reviews')
tagger =nltk.ClassifierBasedTagger(tagged_sents)

I have already checked, that tagged_sents is a list of all sentences. Each sentence self is a list of tuples (word, PoS), like in the documentation:

:param train: A tagged corpus consisting of a list of tagged sentences, where each sentence is a list of (word, tag) tuples.

Why do I get the Value Error?

ValueError: Must specify either training data or trained model.

You've passed tagged_sents positionally, so it is being used as the feature_detector argument. You should construct the tagger like this:

tagger = nltk.ClassifierBasedTagger(train=tagged_sents)

See http://www.nltk.org/api/nltk.tag.html#nltk.tag.sequential.ClassifierBasedTagger

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM