0
nltk.orgの第7章で取り組んでみました。特に、ここではhttp://www.nltk.org/book/ch07.htmlのセクション3.2にはConsecutiveNPChunker
クラスがあります。私はコードを複製しようとしました。しかし、それは一貫して次を投げたValueError
。次のようにNLTK継続的なNPCフンバーが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