How to Run standford corenlp server on Google Colab?

守給你的承諾、 提交于 2021-01-29 20:41:35

问题


I want to use stanford corenlp for obtaining dependency parser of sentences. In order to using stanford corenlp in python, we need to do the below steps in Google Colab:

  1. Install java

import os

!apt-get install openjdk-8-jdk-headless -qq > /dev/null

os.environ["JAVA_HOME"] = "/usr/lib/jvm/java-8-openjdk-amd64"

  1. Download stanford-corenlp-full-2018-10-05 and extract it.

!wget http://nlp.stanford.edu/software/stanford-corenlp-full-2018-10-05.zip

!unzip stanford-corenlp-full-2018-10-05.zip

  1. Change directory to stanford-corenlp-full-2018-10-05 folder with "cd" command.
  2. Run this command in the current directory:

"java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -port 9001 -timeout 75000"

After that, stanford-corenlp server will run at 'http://localhost:9001'

When I attempt to follow the answer on the post @ how to run stanford corenlp server on google colab? I end up getting the response:


Port 9001 is closed, retrying...

Port 9001 is closed, retrying...

Port 9001 is closed, retrying...

Port 9001 is closed, retrying...


Is there any other technique or tutorial known where I may connect between two different google colab .ipynb?


回答1:


Took a page out of tensor board playbook.

Run standford core in the background

LOGDIR = '/tmp/log'
get_ipython().system_raw(
    'java -mx8g -cp "*" 
    edu.stanford.nlp.pipeline.StanfordCoreNLPServer -port 9001 ->timeout 60000 &'
    .format(LOGDIR)
)

Use ngrok to tunnel traffic to localhost

! wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip
! unzip ngrok-stable-linux-amd64.zip
get_ipython().system_raw('./ngrok http 9001 &')

Retrieve public url

! curl -s http://localhost:4040/api/tunnels | python3 -c \
    "import sys, json; print(json.load(sys.stdin)['tunnels'][0]['public_url'])"

Take returned url from above and update the PyCoreNLP.py default_url

URL_DEFAULT = "http://localhost:9000" <- replace URL from above here Save the file... then run the server in the background locally on Google Colab



来源:https://stackoverflow.com/questions/59193589/how-to-run-standford-corenlp-server-on-google-colab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!