ModuleNotFoundError NLTK

问题描述 投票:0回答:1

令牌化工作正常,但是当我尝试进行命名实体识别时namedEnt = ne_chunk(tagged,binary = True)

它出现以下错误我确实使用pip install numpy从cmd安装了NumPy,但仍然出现错误

import nltk
from nltk.corpus import state_union
from nltk.tokenize import PunktSentenceTokenizer, word_tokenize
from nltk.chunk import ne_chunk

train_text = state_union.raw("2005-GWBush.txt")
sample_text = state_union.raw("2006-GWBush.txt")
# print(train_text)


custom_sent_tokenizer = PunktSentenceTokenizer(train_text)
tokenized = custom_sent_tokenizer.tokenize(sample_text)


def process_content():
    for i in tokenized:
        words = word_tokenize(i)
        tagged = nltk.pos_tag(words)
        namedEnt = ne_chunk(tagged, binary=True)
        print(namedEnt)


process_content()

错误:

PS D:\Python\nltk> & C:/Users/Talha/AppData/Local/Programs/Python/Python37/python.exe d:/Python/nltk/nltk_task.py
Traceback (most recent call last):
  File "d:/Python/nltk/nltk_task.py", line 64, in <module>
    process_content()
  File "d:/Python/nltk/nltk_task.py", line 60, in process_content
    namedEnt = ne_chunk(tagged, binary=True)
  File "C:\Users\Talha\AppData\Local\Programs\Python\Python37\lib\site-packages\nltk\chunk\__init__.py", line 185, in ne_chunk
    chunker = load(chunker_pickle)
  File "C:\Users\Talha\AppData\Local\Programs\Python\Python37\lib\site-packages\nltk\data.py", line 757, in load
    resource_val = pickle.load(opened_resource)
ModuleNotFoundError: No module named 'numpy'
python python-3.x nltk
1个回答
0
投票
通过pip install numpy安装numpy,然后通过import numpy as np导入它
© www.soinside.com 2019 - 2024. All rights reserved.