CoreNLP 4.40镜像包制作
一、Dockerfile文件
CoreNLP是斯坦福(Stanford) NLP组(Group)用Java开发的自然语言处理包,开发中调用采用docker形式提供服务,是最方便和对原有程序解耦最彻底的。
Dockerfile
Text1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| FROM java:jre-alpine
RUN apk add --update --no-cache \ unzip \ wget
COPY stanford-corenlp-chinese-4.4.0.zip / RUN unzip stanford-corenlp-chinese-4.4.0.zip
WORKDIR stanford-corenlp-4.4.0
RUN export CLASSPATH="`find . -name '*.jar'`"
ENV PORT 9000 EXPOSE $PORT
CMD java -cp "*" -mx4g edu.stanford.nlp.pipeline.StanfordCoreNLPServer
|
其中, stanford-corenlp-chinese-4.4.0.zip 是和Dockerfile放在同一个目录下,是从https://stanfordnlp.github.io/CoreNLP/download.html 下载,
将2下载的stanford-corenlp-4.4.0-models-chinese.jar 放入1的压缩包中,就是新的stanford-corenlp-chinese-4.4.0.zip。
github上下载非常慢,我已提交到百度网盘,方便大家下载:
Text1
| 链接: https://pan.baidu.com/s/1_9pSxYaH9NVCTZkl6bTvlg 提取码: 8p6o
|
二、制作镜像
make.sh
Text1
| docker build -t cbbing/corenlp_with_chinese:4.4.0 .
|
执行过程:
Text1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| MacBook-Pro CoreNLP % sh make.sh [+] Building 15.9s (11/11) FINISHED => [internal] load build definition from Dockerfile 0.1s => => transferring dockerfile: 37B 0.0s => [internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => [internal] load metadata for docker.io/library/java:jre-alpine 15.3s => [internal] load build context 0.4s => => transferring context: 59B 0.0s => [1/6] FROM docker.io/library/java:jre-alpine@sha256:6a8cbe4335d1a5711a52912b684e30d6dbfab681a6733440ff7241b05a5deefd 0.0s => CACHED [2/6] RUN apk add --update --no-cache unzip wget 0.0s => CACHED [3/6] COPY stanford-corenlp-chinese-4.4.0.zip / 0.0s => CACHED [4/6] RUN unzip stanford-corenlp-chinese-4.4.0.zip 0.0s => CACHED [5/6] WORKDIR stanford-corenlp-4.4.0 0.0s => CACHED [6/6] RUN export CLASSPATH="`find . -name '*.jar'`" 0.0s => exporting to image 0.0s => => exporting layers 0.0s => => writing image sha256:8ff3dc6cb044148a34ae57fd50be32cf0d74ed5f7c5e1cdd51297d36c549a8c5 0.0s => => naming to docker.io/cbbing/corenlp_with_chinese:4.4.0
|
三、dockerhub下载
CoreNLP4.4.0支持中文,我已经提交到dockerhub,可以直接下载使用。地址为:https://hub.docker.com/repository/docker/cbbing/corenlp_with_chinese
四、CoreNLP使用
启动Docker:
Text1
| docker run -d -p 9004:9000 --name corenlp_c cbbing/corenlp_with_chinese:4.4.0
|
访问本机的9004端口,例如http://192.168.3.11:9004 (不能用0.0.0.0:9004)
输入中文文本:
Text1
| 5月1日,由国药集团中国生物北京生物制品研究所研发的奥密克戎变异株新冠病毒灭活疫苗临床研究正式在杭州启动,并于当天完成第一剂接种。
|
当然,英文也没问题,不过语言必须也得选Chinese,没搞明白这个逻辑:
注意,Docker容器分配内存至少4G,如果少了可能容器会因内存不足被killed。