我的代码:
import nlp
def tokenize_sentences(text):
tokens = nlp(text)
sentences = [sent.text for sent in nlp(text).sents]
return sentences
text = "Some phrases that I use as a test. The context is not important. Test sentence.
sentences = tokenize_sentences(text)错误是:
TypeError Traceback (most recent call last)
<ipython-input-4-ec796e2a8070> in <module>
----> 1 sentences = tokenize_sentences(text)
<ipython-input-2-aa259d17fc09> in tokenize_sentences(text)
1 def tokenize_sentences(text):
----> 2 tokens = nlp(text)
3 sentences = [sent.text for sent in nlp(text).sents]
4 #print(sentences)
5 #for sent in tokens.sents:
TypeError: 'module' object is not callable我又试着安装了!pip install NLP-python,!pip install NLP,!pip install nlp。然后,当我尝试下面的,'NLP‘没有找到。
from NLP import NLP
nlp = NLP()我知道错误在进口的某个地方,但我不知道在哪里。
发布于 2021-10-15 10:55:45
从代码中的属性判断,您要寻找的库似乎不是NLP-python,而是spacy。
pip3 install spacy
python3 -m spacy download en_core_web_sm然后在您的代码中:
import spacy
nlp = spacy.load("en_core_web_sm")https://stackoverflow.com/questions/69583487
复制相似问题