0
nltk.org 책 7 장에서 작업을 시도했습니다. 특히 섹션 3.2 아래 http://www.nltk.org/book/ch07.html에 ConsecutiveNPChunker
클래스가 있습니다. 코드를 복제하려고했습니다. 그러나, 그것은 일관되게 다음을 던졌다 : ValueError
. 나는이 프로그램을 실행했을 때NLTK ConsecutiveNPChunker가 ValueError를 던졌습니다
import nltk
from nltk.corpus import conll2000
train_sents = conll2000.chunked_sents('train.txt', chunk_types=['NP'])
class ConsecutiveNPChunker(nltk.ChunkParserI): # [_consec-chunker]
def __init__(self, train_sents):
tagged_sents = [[((w,t),c) for (w,t,c) in
nltk.chunk.tree2conlltags(sent)]
for sent in train_sents]
self.tagger = ConsecutiveNPChunkTagger(tagged_sents)
def parse(self, sentence):
tagged_sents = self.tagger.tag(sentence)
conlltags = [(w,t,c) for ((w,t),c) in tagged_sents]
return nltk.chunk.conlltags2tree(conlltags)
def npchunk_features(sentence, i, history):
word, pos = sentence[i]
return {"pos": pos}
chunker = ConsecutiveNPChunker(train_sents)
다음은 오류입니다 : 다음과 같이
내 코드는 당신이이 없기 때문에 당신이 압축 풀기 오류가
~/.pyenv/versions/3.4.3/envs/nlp/lib/python3.4/site-packages/nltk/tag/util.py in <listcomp>(.0)
67
68 """
---> 69 return [w for (w, t) in tagged_sentence]
70
71
ValueError: need more than 1 value to unpack