오류 메시지 : ValueError : NLTK의 주파수 분포에서 압축을 풀기에 너무 많은 값

Aug 17 2020

ValueError : too many values ​​to unpack (expected 2) for the below code. 명사가 너무 많아서인지 모르겠습니다.

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)

제안하십시오

오류:

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)

답변

1 thorntonc Aug 17 2020 at 07:27

다음 코드는 갈색 말뭉치에서 미스터리 장르의 명사의 빈도를 제공합니다.

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)