本文介绍了当我在NLTK中尝试FreqDist()时收到错误消息-NameError:未定义名称'nltk'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习NLTK和我的Mac 工作正常,除了我在FreqDist()上遇到麻烦. (我看到了另一个有关FreqDist()的问题,但他得到了不同的错误消息.TypeError:不能散列的类型:'list')这是一个示例:

I'm learning about the NLTK and my mac is working fine except I have trouble with the FreqDist(). (I saw another question about FreqDist() but he was getting a different error message. TypeError: unhashable type: 'list')Here's an example:

>>> from nltk.corpus import brown
>>> news_text = brown.words(categories='news')
>>> fdist = nltk.FreqDist([w.lower() for w in news_text])

Traceback (most recent call last):

`  File "<stdin>", line 1, in <module>`
`NameError: name 'nltk' is not defined`

此错误消息非常一致.每当我尝试FreqDist()时,我都会收到此消息.其他命令-->> brown.fileids()也可以.

This error message is pretty consistent. I get this message every time I try the FreqDist(). Other commands like - >>> brown.fileids() are fine.

感谢您的帮助!

推荐答案

在使用FreqDist之前,需要将其导入.

Before you can use FreqDist, you need to import it.

添加如下一行:

import nltk

或者如果您只想使用FreqDist,则应尝试以下操作:

or if you just want to use FreqDist you should try this:

>>> from nltk.corpus import brown
>>> from nltk import FreqDist
>>> news_text = brown.words(categories='news')
>>> fdist = FreqDist([w.lower() for w in news_text])

这篇关于当我在NLTK中尝试FreqDist()时收到错误消息-NameError:未定义名称'nltk'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-05 19:34