【问题和解决】NLTK was unable to find the megam file!(1)

编程入门 行业动态 更新时间:2024-10-19 17:44:25

【问题和解决】NLTK was <a href=https://www.elefans.com/category/jswz/34/1771031.html style=unable to find the megam file!(1)"/>

【问题和解决】NLTK was unable to find the megam file!(1)

在学到“训练基于分类器的分块器”这一小节的时候,在测试代码之后遇到了问题。

class ConsecutiveNPChunkTagger(nltk.TaggerI):def __init__(self, train_sents):train_set = []for tagged_sent in train_sents:untagged_sent = nltk.tag.untag(tagged_sent)history = []for i, (word, tag) in enumerate(tagged_sent):featureset = npchunk_features(untagged_sent, i, history) train_set.append( (featureset, tag) )history.append(tag)self.classifier = nltk.MaxentClassifier.train(train_set, algorithm='megam', trace=0)def tag(self, sentence):history = []for i, word in enumerate(sentence):featureset = npchunk_features(sentence,i, history)tag = self.classifier.classify(featureset)history.append(tag)return zip(sentence, history)
class ConsecutiveNPChunker(nltk.ChunkParserI):def __init__(self, train_sents):tagged_sents = [[((w,t),c) for (w,t,c) innltk.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)
>>>print chunker.evaluate(test_sents)

以上是书上提供的代码,问题是,当在执行

chunker = ConsecutiveNPChunker(train_sents)并没有如期执行,反而出现了一个错误。
Traceback (most recent call last):File "<pyshell#119>", line 1, in <module>chunker = ConsecutiveNPChunker(train_sents)File "<pyshell#118>", line 5, in __init__self.tagger = ConsecutiveNPChunkTagger(tagged_sents)File "<pyshell#116>", line 11, in __init__self.classifier = nltk.MaxentClassifier.train(train_set, algorithm='megam', trace=0)File "D:\SpecialSoftware\Python25\Lib\site-packages\nltk\classify\maxent.py", line 319, in traingaussian_prior_sigma, **cutoffs)File "D:\SpecialSoftware\Python25\Lib\site-packages\nltk\classify\maxent.py", line 1522, in train_maxent_classifier_with_megamstdout = call_megam(options)File "D:\SpecialSoftware\Python25\Lib\site-packages\nltk\classify\megam.py", line 163, in call_megamconfig_megam()File "D:\SpecialSoftware\Python25\Lib\site-packages\nltk\classify\megam.py", line 59, in config_megamurl='/')File "D:\SpecialSoftware\Python25\Lib\site-packages\nltk\internals.py", line 528, in find_binaryurl, verbose)File "D:\SpecialSoftware\Python25\Lib\site-packages\nltk\internals.py", line 512, in find_fileraise LookupError('\n\n%s\n%s\n%s' % (div, msg, div))
LookupError: ===========================================================================
NLTK was unable to find the megam file!
Use software specific configuration paramaters or set the MEGAM environment variable.For more information, on megam, see:</>
===========================================================================

虽然说给出了相应的提示,但是并不完全。

通过对谷歌的搜索,找到了一些解决的眉目。

我的操作系统是Windows8.

nltk语言工具的官网给出了提示:

Megam为可选包,将来使用的时候可以再来安装。下载的网址为:MegaM: /megam/megam_src.tgz,直接下载我并没有下载成功,使用迅雷下载成功的。

但是打开之后发现,都是些源文件。但是在这个压缩包里面有一个README文件,给出了怎样使用的提示,发现,还需要装一个东西。

README中这样写到:ocaml()

需要到这个网站下载源文件的编译器,于是我下载了和自己电脑系统相匹配的版本,但是看说明安装起来还是需要琢磨的,在安装过程中提示是病毒,但是我还是选择信任,要不然没办法继续。

 【现在Ocaml正在安装,我点的完全安装(可能实际当中没有必要完全安装吧),等安装完成后,再继续探索怎么解决这个问题】

 

 

转载于:.html

更多推荐

【问题和解决】NLTK was unable to find the megam file!(1)

本文发布于:2024-03-23 23:42:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1744225.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:unable   NLTK   find   file   megam

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!