【发布时间】:2016-02-08 20:48:02
【问题描述】:
我指的是该部分中的链接 http://www.nltk.org/book/ch06.html#recognizing-textual-entailment
def rte_features(rtepair):
extractor = nltk.RTEFeatureExtractor(rtepair)
features = {}
features['word_overlap'] = len(extractor.overlap('word'))
features['word_hyp_extra'] = len(extractor.hyp_extra('word'))
features['ne_overlap'] = len(extractor.overlap('ne'))
features['ne_hyp_extra'] = len(extractor.hyp_extra('ne'))
return features
rtepair = nltk.corpus.rte.pairs(['rte3_dev.xml'])
extractor = nltk.RTEFeatureExtractor(rtepair)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-39-a7f96e33ba9e> in <module>()
----> 1 extractor = nltk.RTEFeatureExtractor(rtepair)
C:\Users\RAVINA\Anaconda2\lib\site-packages\nltk\classify\rte_classify.pyc in __init__(self, rtepair, stop, lemmatize)
65
66 #Get the set of word types for text and hypothesis
---> 67 self.text_tokens = tokenizer.tokenize(rtepair.text)
68 self.hyp_tokens = tokenizer.tokenize(rtepair.hyp)
69 self.text_words = set(self.text_tokens)
AttributeError: 'list' object has no attribute 'text'
它是书中提到的确切代码,任何人都可以帮助我这里出了什么问题。 谢谢 拉维娜
【问题讨论】:
-
这与书中提到的代码不完全相同:
rtepair = nltk.corpus.rte.pairs(['rte3_dev.xml'])[33]他们取列表的第 33 个元素,而不是整个列表。 -
对不起,您弄错了,[33] 只是一个传说,提到了第 33 个代码 sn-p。 :-)
-
“为了说明这些特征的内容,我们检查了前面显示的文本/假设对 34 的一些属性:”。它们的意思是项目编号 34 (33 + 1)。
标签: python nltk text-classification