Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

text_annotation = self.pipeline.createBasicTextAnnotation("", "", text) AttributeError: 'NoneType' object has no attribute 'createBasicTextAnnotation' #86

Open
monajalal opened this issue May 15, 2018 · 9 comments
Assignees

Comments

@monajalal
Copy link

monajalal commented May 15, 2018

What is the minimum working example of a code that I feed in a string and gives me the named entities?

from ccg_nlpy import local_pipeline

pipeline = local_pipeline.LocalPipeline()

d = "RT @HuffingtonPost BREAKING: Hillary Clinton wins #NVCaucus https://t.co/ZVCgIDvrX1"

doc = pipeline.doc(d)

if doc is not None:
    # do sth with it
    ner_view = doc.get_ner_conll

For above code, I get the following error:

$ python ccg_ner.py
WARNING:ccg_nlpy.pipeline_config:Models not found. To use pipeline locally, please refer the documentation for downloading models.
INFO:ccg_nlpy.pipeline_config:Using local pipeline
ERROR:ccg_nlpy.local_pipeline:Fail to load models, please check if your Java version is up to date.
Traceback (most recent call last):
  File "ccg_ner.py", line 7, in <module>
    doc = pipeline.doc(d)
  File "/scratch/sjn/anaconda/lib/python3.6/site-packages/ccg_nlpy/pipeline_base.py", line 36, in doc
    response = self.call_server(text, "TOKENS")
  File "/scratch/sjn/anaconda/lib/python3.6/site-packages/ccg_nlpy/local_pipeline.py", line 63, in call_server
    text_annotation = self.pipeline.createBasicTextAnnotation("", "", text)
AttributeError: 'NoneType' object has no attribute 'createBasicTextAnnotation'

My server is running on 02:13:57 INFO LabeledChuLiuEdmondsDecoder:72 - Loading cached PoS-to-dep dictionary from deprels.dict
Reading POS tagger model from edu/stanford/nlp/models/pos-tagger/english-left3words/english-left3words-distsim.tagger ... done [1.4 sec].
Loading parser from serialized file edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz ... done [0.7 sec].
02:14:01 INFO MainServer:67 - Done with loading the pipeline . . .
02:14:01 INFO MainServer:227 - ##### Used Memory[MB]:1532
02:14:01 INFO MainServer:230 - / Free Memory[MB]:1027
02:14:01 INFO MainServer:233 - / Total Memory[MB]:2560
02:14:01 INFO MainServer:236 - / Max Memory[MB]:31858
02:14:01 INFO log:186 - Logging initialized @120702ms
02:14:01 INFO EmbeddedJettyServer:126 - == Spark has ignited ...
02:14:01 INFO EmbeddedJettyServer:127 - >> Listening on 0.0.0.0:8080
02:14:01 INFO Server:345 - jetty-9.3.6.v20151106
02:14:01 INFO ServerConnector:270 - Started ServerConnector@67e0a155{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}
02:14:01 INFO Server:397 - Started @120785ms

@danyaljj
Copy link
Member

Seems like you're missing the model files. Did you run python -m ccg_nlpy download before running your code?

@monajalal
Copy link
Author

@danyaljj I have downloaded it but I still get the same error:

$ ls -ltra ~/.ccg_nlpy/
total 36
drwx-----x. 45 jalal cs-grad 12288 May 15 02:21 ..
-rw-r--r--.  1 jalal cs-grad   903 May 15 02:21 pom.xml
drwxr-xr-x.  2 jalal cs-grad 12288 May 15 02:22 model_3.1.15
drwxr-xr-x.  3 jalal cs-grad  4096 May 15 02:22 .
-rw-r--r--.  1 jalal cs-grad   103 May 15 02:22 config.cfg
$ python ccg_ner.py 
INFO:ccg_nlpy.pipeline_config:Using local pipeline
ERROR:ccg_nlpy.local_pipeline:Fail to load models, please check if your Java version is up to date.
Traceback (most recent call last):
  File "ccg_ner.py", line 6, in <module>
    pipeline.call_server(d, "NER_ONTONOTES")
  File "/scratch/sjn/anaconda/lib/python3.6/site-packages/ccg_nlpy/local_pipeline.py", line 63, in call_server
    text_annotation = self.pipeline.createBasicTextAnnotation("", "", text)
AttributeError: 'NoneType' object has no attribute 'createBasicTextAnnotation'

@monajalal
Copy link
Author

monajalal commented May 15, 2018

Any idea what could be fixed?

$ java -version
openjdk version "1.8.0_171"
OpenJDK Runtime Environment (build 1.8.0_171-b10)
OpenJDK 64-Bit Server VM (build 25.171-b10, mixed mode)
$ python ccg_test.py 
INFO:ccg_nlpy.pipeline_config:Using local pipeline
ERROR:ccg_nlpy.local_pipeline:Fail to load models, please check if your Java version is up to date.
Traceback (most recent call last):
  File "ccg_test.py", line 7, in <module>
    doc = pipeline.doc(d)
  File "/scratch/sjn/anaconda/lib/python3.6/site-packages/ccg_nlpy/pipeline_base.py", line 36, in doc
    response = self.call_server(text, "TOKENS")
  File "/scratch/sjn/anaconda/lib/python3.6/site-packages/ccg_nlpy/local_pipeline.py", line 63, in call_server
    text_annotation = self.pipeline.createBasicTextAnnotation("", "", text)
AttributeError: 'NoneType' object has no attribute 'createBasicTextAnnotation'
$ cat ccg_test.py 
from ccg_nlpy import local_pipeline

pipeline = local_pipeline.LocalPipeline()

d = "RT @HuffingtonPost BREAKING: Hillary Clinton wins #NVCaucus https://t.co/ZVCgIDvrX1"

doc = pipeline.doc(d)

if doc is not None:
    # do sth with it
    ner_view = doc.get_ner_conll

$ lsb_release -a
LSB Version:	:core-4.1-amd64:core-4.1-noarch
Distributor ID:	CentOS
Description:	CentOS Linux release 7.5.1804 (Core) 
Release:	7.5.1804
Codename:	Core

@danyaljj
Copy link
Member

@GHLgh any thoughts on this?

@GHLgh
Copy link
Member

GHLgh commented May 15, 2018

@danyaljj @monajalal The actual error message was omitted in the code and on my side, the error message is the following:

dlopen(/Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home/jre/lib/server/libjvm.dylib, 10): image not found

The JDK 9 Release remove the sub-directory "jre" and I believe that pyjnius still searching files in "jre" directory. You should check if this is the case here. A workaround is to create a symbolic link (to pretend there is "jre" directory):

cd $JAVA_HOME
sudo ln -s ./ jre

After using the workaround, another issue came out:

jnius.JavaException: JVM exception occurred: View 'å' cannot be provided by this AnnotatorService.

It seems like the Python string doesn't get converted to Java string properly, as suggested in the issue, this can be fixed by converting the string explicitly before passing it to APIs on Java side:

# In local_pipeline.py

# import Java String class along with other imported autoclasses
self.JString = autoclass('java.lang.String') 
# Convert the string into Java String before calling APIs on Java side, example:
self.pipeline.addView(text_annotation, self.JString(view.strip()))
# Previous implementation: self.pipeline.addView(text_annotation,view.strip())

After that, the example can be run properly:

python -i test.py
...
>>> print(ner_view)
NER_CONLL view: (PER Hillary Clinton) (ORG NVCaucus)

@danyaljj
Copy link
Member

@monajalal does this resolve your problem?

@monajalal
Copy link
Author

Thanks for looking into this. At the moment, I don't have enough permission and our site admin will look into this. I will notify if it will help us or what further bugs we might get.

@monajalal
Copy link
Author

monajalal commented May 16, 2018

that didn't work out so I opted out to remote server:

$ cat ccg_test_remote.py 
from ccg_nlpy import remote_pipeline

pipeline = remote_pipeline.RemotePipeline()

d = "RT @HuffingtonPost BREAKING: Hillary Clinton wins #NVCaucus https://t.co/ZVCgIDvrX1"

doc = pipeline.doc(d)

if doc is not None:
    # do sth with it
    ner_view = doc.get_ner_conll
    print(ner_view)

$ python ccg_test_remote.py 
INFO:ccg_nlpy.pipeline_config:Using pipeline web server with API: http://austen.cs.illinois.edu:8080
INFO:ccg_nlpy.remote_pipeline:pipeline has been set up
NER_CONLL view: (PER Hillary Clinton) 

btw why in here @huffingtonpost is not considered as an entity?

@KeyWeeUsr
Copy link

Hi, check the kivy/pyjnius#300 and the newest pyjnius release again whether it fixed the issues for you. If not, open a new issue with detailed description and reproducible steps. 🍡

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants