Reputation: 77
I am getting error as ValueError: too many values to unpack (expected 2) for the below code. I am not sure whether it is because of too many nouns count.
from nltk.corpus import brown
import nltk
tagged_words = brown.tagged_words(categories='mystery')
for word, tag in tagged_words:
if any(noun_tag in tag for noun_tag in ['NP', 'NN']):
nouns=(word,tag)
for word, tag in nouns:
nouns_freq =nltk.FreqDist(word)
Please suggest
Error:
Traceback (most recent call last):
File "C:\Users\\Word2Vec.py", line 12, in module
for word, tag in nouns:
ValueError: too many values to unpack (expected 2)
Upvotes: 1
Views: 68
Reputation: 2126
The following code will give you the frequency of nouns of the mystery genre in brown corpus.
from nltk.corpus import brown
from nltk import FreqDist
tagged_words = brown.tagged_words(categories='mystery')
# get list of lowercased nouns
nouns = [word[0].lower() for word in tagged_words if word[1] in ['NP', 'NN']]
nouns_freq = FreqDist(nouns)
Upvotes: 1