nltk分句、分词

使用 nltk 遇到错误

from nltk.tokenize import sent_tokenize

错误

LookupError:
**********************************************************************
  Resource punkt not found.

  Please use the NLTK Downloader to obtain the resource:

  >>> import nltk
  >>> nltk.download('punkt')

  Searched in:
    - 'C:\\Users\\admin/nltk_data'
    - 'C:\\nltk_data'
    - 'D:\\nltk_data'
    - 'E:\\nltk_data'
    - 'D:\\software\\Anaconda3\\nltk_data'
    - 'D:\\software\\Anaconda3\\lib\\nltk_data'
    - 'C:\\Users\\admin\\AppData\\Roaming\\nltk_data'
    - ''
**********************************************************************

方案 1

import nltk
nltk.download('punkt')

若无法安装,则 在 C:\Windows\System32\drivers\etc 路径下找到hosts文件,并在最后添加 199.232.68.133 raw.githubusercontent.com IP地址,并保存

如果raw.GitHub的IP地址更换得比较频繁,那么先查询该网址的IP地址后再修改hosts文件。打开查询IP地址的网址:https://www.ipaddress.com/

raw.githubusercontent.com

输入如下代码,按Enter

nltk分句、分词

参考:https://mp.weixin.qq.com/s?__biz=MzI1NzczMDIwNw==&mid=2247483777&idx=1&sn=cd985f3f7fe0472df9560de94753d86d&chksm=ea13b271dd643b67a591485d249ca9f64aaa380db3ff16c462c0d2def5ccce114e3c938b955e&token=445308227&lang=zh_CN#rd

方案 2

import nltk
nltk.download()

点击 “all” 这一行,然后点击 “Download” 按钮进行下载

nltk分句、分词
参考:https://www.jianshu.com/p/4fb3e3c9bd69

方案三:离线下载

1、手动下载 NLTK 数据集

这里直接附上别人的博客《解决nltk download(‘punkt’) 连接尝试失败》;

异可在官网下载:NLTK Corpora

2、安装 punkt

把下载好的语料包 punkt.zip 解压到 nltk_data/tokenizers/ 中。

参考:https://blog.csdn.net/qq_41297934/article/details/111310009

Original: https://blog.csdn.net/weixin_43815222/article/details/123074153
Author: Maann
Title: nltk分句、分词

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/530448/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球