安装了NLTK,但NLTK_UTILS返回ModulenotFoundError

发布于 2025-01-24 01:12:33 字数 406 浏览 3 评论 0 原文

我正在使用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

I am using virtual env, I have installed nltk module with pip3, when I am trying to import nltk_utils I am getting a ModuleNotFoundError

>>> import nltk
>>> import nltk_utils
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'nltk_utils'

I have tried without virtualenv too but no luck

OS : Ubuntu

Python Version : 3.9.5

GCC : 10.3.0

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

多孤肩上扛 2025-01-31 01:12:33

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 with nltk. Did you mean nltk.util, which is described here?

Otherwise nltk_utils is used in some examples using nltk where it is a custom file that contains useful functions in interacting with nltk (E.g. in this chatbot example) so if you are following some tutorial or similar, check if they mention somewhere what nltk_utils should contain

极致的悲 2025-01-31 01:12:33

添加到用户FlyingTeller的答案:
我来这里遇到了同样的问题,我遵循完全相同的tutorial < /a> 由用户FlyingTeller链接。引用导入的“ NLTK_UTILS”是在教程范围中制作的自定义文件。

解决问题:
您可以在教程创建者的github上找到“ nltk_utils”,此处:

(有关该文件的更多说明,请检查教程中链接的视频)。

更新:
您还需要文件“ model.py”,这也可以在上述链接的github上找到。
之后,您仍然可能会面临错误,就我而言,我需要将“#火车模型”部分移至 main 中,并将标签投放到INT。调整后的代码如下:

...
if __name__ == '__main__':
    # Train the model
    for epoch in range(num_epochs):
        for (words, labels) in train_loader:
            words = words.to(device)
            labels = labels.type(torch.LongTensor) # <- Fix from here: https://stackoverflow.com/a/71149364/18456868
            labels = labels.to(device)

            # Forward pass
            outputs = model(words)
...

之后,我使它起作用:
在培训大约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:

...
if __name__ == '__main__':
    # Train the model
    for epoch in range(num_epochs):
        for (words, labels) in train_loader:
            words = words.to(device)
            labels = labels.type(torch.LongTensor) # <- Fix from here: https://stackoverflow.com/a/71149364/18456868
            labels = labels.to(device)

            # Forward pass
            outputs = model(words)
...

After that, i got it working:
Output of script after about 3 minutes of training

幽蝶幻影 2025-01-31 01:12:33

您的问题可能是因为您没有将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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文