简体   繁体   English

Google colaboratory 中没有名为“nltk.lm”的模块

[英]No module named 'nltk.lm' in Google colaboratory

I'm trying to import the NLTK language modeling module ( nltk.lm ) in a Google colaboratory notebook without success.我正在尝试在 Google 协作笔记本中导入 NLTK 语言建模模块 ( nltk.lm ),但没有成功。 I've tried by installing everything from nltk, still without success.我已经尝试从 nltk 安装所有东西,但仍然没有成功。

What mistake or omission could I be making?我会犯什么错误或遗漏?

Thanks in advance.提前致谢。

在此处输入图像描述 . . 在此处输入图像描述

Google Colab has nltk v3.2.5 installed, but nltk.lm (Language Modeling package) was added in v3.4 . Google Colab 已安装nltk v3.2.5 ,但v3.4中添加了nltk.lm (语言建模包)。

In your Google Colab run:在您的 Google Colab 运行中:

!pip install -U nltk

In the output you will see it downloads a new version, and uninstalls the old one:在 output 中,您会看到它下载了新版本,并卸载了旧版本:

...
Downloading nltk-3.6.5-py3-none-any.whl (1.5 MB)
...
Successfully uninstalled nltk-3.2.5
...
You must restart the runtime in order to use newly installed versions.

Click the Restart runtime button shown in the end of the output.单击 output 末尾所示的Restart runtime按钮。

Now it should work!现在它应该工作了!

You can double check the nltk version using this code:您可以使用以下代码仔细检查nltk版本:

import nltk
print('The nltk version is {}.'.format(nltk.__version__))

You need v3.4 or later to use nltk.lm .您需要v3.4或更高版本才能使用nltk.lm

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM