2017-12-17 26 views
0

nltk.org 책 7 장에서 작업을 시도했습니다. 특히 섹션 3.2 아래 http://www.nltk.org/book/ch07.htmlConsecutiveNPChunker 클래스가 있습니다. 코드를 복제하려고했습니다. 그러나, 그것은 일관되게 다음을 던졌다 : 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 

답변

0

를, 그것은이다 zip 메서드는 n 개의 iterable을 취하고 튜플 목록을 반환합니다. 그래서, def parse() 방법/기능의 코드,

conlltags = [(w,t,c) for ((w,t),c) in tagged_sents]

이이 풀고 더 이상의 값을 얻을 것입니다

conlltags = [(w,t,c) for ((w,t),c) in zip(tagged_sents)] 

해야한다.