安装了NLTK,但NLTK_UTILS返回ModulenotFoundError
我正在使用Virtual Env,当我尝试导入 nltk_utils 时,我已经使用pip3安装了NLTK模块,我也将获得一个ModulenotFoundError,
>>> import nltk
>>> import nltk_utils
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'nltk_utils'
我也尝试过没有Virtualenv,但也没有运气
OS:Ubuntu
Python版本:3.9。 5
GCC:10.3.0
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
nltk_utils
没有nltk
运送的东西。您的意思是nltk.util
,它是 a>?否则
nltk_utils
在某些示例中使用nltk
,其中它是一个自定义文件,其中包含与nltk
(例如, =“ https://www.python-engineer.com/posts/chatbot-pytorch/” rel =“ nofollow noreferrer”>此聊天机器人示例nltk_utils
应该包含的位置nltk_utils
is nothing that comes shipped withnltk
. Did you meannltk.util
, which is described here?Otherwise
nltk_utils
is used in some examples usingnltk
where it is a custom file that contains useful functions in interacting withnltk
(E.g. in this chatbot example) so if you are following some tutorial or similar, check if they mention somewhere whatnltk_utils
should contain添加到用户FlyingTeller的答案:
我来这里遇到了同样的问题,我遵循完全相同的tutorial < /a> 由用户FlyingTeller链接。引用导入的“ NLTK_UTILS”是在教程范围中制作的自定义文件。
解决问题:
您可以在教程创建者的github上找到“ nltk_utils”,此处:
(有关该文件的更多说明,请检查教程中链接的视频)。
更新:
您还需要文件“ model.py”,这也可以在上述链接的github上找到。
之后,您仍然可能会面临错误,就我而言,我需要将“#火车模型”部分移至 main 中,并将标签投放到INT。调整后的代码如下:
之后,我使它起作用:
在培训大约3分钟后的脚本输出
Adding to the answer of user FlyingTeller:
I came here having the same problem, and i followed the exact same tutorial as linked by user FlyingTeller. The referenced import "nltk_utils" is a custom file made in the scope of the tutorial.
Solving the problem:
You can find "nltk_utils" at the github of the tutorial creator, here:
https://github.com/patrickloeber/pytorch-chatbot/blob/master/nltk_utils.py
(for more explanation about that file, check the video that is linked in the tutorial).
Update:
You also need the file "model.py", which is found at the above linked github, too.
After that, you may still face errors, in my case i needed to move the "# train model" part into main and also cast the labels to int. The adjusted code looks as follows:
After that, i got it working:
Output of script after about 3 minutes of training
您的问题可能是因为您没有将nltk_utils.py文件带入您的目录,因此请确保您已经完成了。我随身携带了这个重新调理
Your issue arises possibly because you did not take the nltk_utils.py file into your directory so ensure that you have done that; I come with this reseasoning because I usually write the utility methods like tokenize, stem or bag_of_words etc into that file for modularisation