如何在Google Colab上运行Standford Corenlp服务器? [英] How to Run standford corenlp server on Google Colab?

查看:217
本文介绍了如何在Google Colab上运行Standford Corenlp服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用stanford corenlp来获取句子的依赖解析器.为了在python中使用stanford corenlp,我们需要在Google Colab中执行以下步骤:

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. 安装Java

导入操作系统

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

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

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

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

  1. 下载stanford-corenlp-full-2018-10-05并将其解压缩.

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

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

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

  1. 使用"cd"命令将目录更改为stanford-corenlp-full-2018-10-05文件夹.
  2. 在当前目录中运行此命令:

"java -mx4g -cp" *"edu.stanford.nlp.pipeline.StanfordCoreNLPServer端口9001-超时75000"

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

之后,stanford-corenlp服务器将在' http://localhost:9001 '

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

当我尝试遵循帖子@上的答案时如何在Google colab上运行斯坦福corenlp服务器?我最终得到响应:

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:

端口9001已关闭,正在重试...

Port 9001 is closed, retrying...

端口9001已关闭,正在重试...

Port 9001 is closed, retrying...

端口9001已关闭,正在重试...

Port 9001 is closed, retrying...

端口9001已关闭,正在重试...

Port 9001 is closed, retrying...

在其他两个Google colab .ipynb之间可以连接的其他技术或教程吗?

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

推荐答案

从张量板手册中取出一页.

在后台运行standford核心

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

使用ngrok将流量隧道传输到本地主机

! 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 &')

检索公共网址

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

从上方获取返回的网址,并更新PyCoreNLP.py default_url

URL_DEFAULT =" http://localhost:9000 "<-从上面替换URL保存文件...然后在Google Colab本地在后台运行服务器

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

这篇关于如何在Google Colab上运行Standford Corenlp服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆