NameError: name 'sent_tokenize' is not defined
NameError: name 'sent_tokenize' is not defined
我目前正在使用 google colab 读取 txt 文件并使用 nltk 将其分解成句子。
import nltk
nltk.download('punkt')
with open ('demo.txt','r') as file:
content = file.read()
print(content)
sentences = tokenize.sent_tokenize(content)
print(sentences)
当我点击 运行,
[nltk_data] 正在将包 punkt 下载到 /root/nltk_data...
[nltk_data]包 punkt 已经是最新的!
-------------------------------------------- ------------------------------
NameError Traceback(最后一次调用)
在 ()
1 导入 nltk
2 nltk.download('punkt')
----> 3 分词器= sent_tokenize()
4 句 = tokenize.sent_tokenize(内容)
5 打印(句子)
NameError: 名称 'sent_tokenize' 未定义
出现这个错误。对了,我已经安装了nltk.
进口sent_tokenize
import nltk
from nltk.tokenize import sent_tokenize
nltk.download('punkt')
with open ('demo.txt','r') as file:
content = file.read()
print(content)
sentences = sent_tokenize(content)
print(sentences
我目前正在使用 google colab 读取 txt 文件并使用 nltk 将其分解成句子。
import nltk
nltk.download('punkt')
with open ('demo.txt','r') as file:
content = file.read()
print(content)
sentences = tokenize.sent_tokenize(content)
print(sentences)
当我点击 运行,
[nltk_data] 正在将包 punkt 下载到 /root/nltk_data... [nltk_data]包 punkt 已经是最新的! -------------------------------------------- ------------------------------ NameError Traceback(最后一次调用) 在 () 1 导入 nltk 2 nltk.download('punkt') ----> 3 分词器= sent_tokenize() 4 句 = tokenize.sent_tokenize(内容) 5 打印(句子) NameError: 名称 'sent_tokenize' 未定义
出现这个错误。对了,我已经安装了nltk.
进口sent_tokenize
import nltk
from nltk.tokenize import sent_tokenize
nltk.download('punkt')
with open ('demo.txt','r') as file:
content = file.read()
print(content)
sentences = sent_tokenize(content)
print(sentences