[英]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.