TypeError: 'NLP' object is not callable

899 Views Asked by At

Here's the Site

From here i just try to ran the sample code provided on site, but am getting this error

enter image description here


TypeError Traceback (most recent call last) in ----> 1 text = nlp("The virginica species has the least average sepal_width.")

TypeError: 'NLP' object is not callable

I have installed all packages, but still what might have cause this issue?

2

There are 2 best solutions below

2
On BEST ANSWER

Try that:

>>> from nlg.utils import load_spacy_model
>>> nlp = load_spacy_model()
>>> text = nlp("The virginica species has the least average sepal_width.")

I think the example author forgot to instantiate the nlp object, very common in spacy library. Consider reporting a issue in the nlg project.

0
On

from NLP import NLP is terrible code, because now the class (the second mention of NLP) will shadow the package. You won't be able to reference both of these. (It's also not great practice for the package name and its main class to be identically-named, but that's on the package author, not us programmers).

Much better to do this:

import NLP

# instantiate one
nlp = NLP.NLP()

# ... then do stuff with it