Mac环境下step by step安装BERT环境

Bert 要在tensorflow 1.10.0版本+python 3.5上才能配合使用,现在默认安装是装TensorFlow 2.1.0和python 3.7以上,启动模型会报错:

fail to optimize the graph!

TypeError: cannot unpack non-iterable NoneType object

 

 

一:预备安装

需要有conda安装,可以用brew来安装,也可以直接直接安装 https://www.anaconda.com/distribution/#macos

安装python 3X版本,可以用 brew install python,会安装最新的python

 

二:设置conda

由于墙的原因以及直连国外的仓库限速的原因,安装下面的软件速度都比较慢,所以推荐一些国内的镜像,来加速安装过程

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes

 

三: python 3.5安装:

conda create -n python35 python=3.5 anaconda 进行降级

降级完成要进行激活

conda activate python35

注:python35就是该镜像名

 

四:TensorFlow安装

在刚才的终端下,输入:

conda install tensorflow==1.10.0

 

五:安装bert的client和server

新起终端:

pip3 install bert-serving-server 

pip3 install bert-serving-client 

 

六:下载bert的中文模型:

从下面这个地址去下载

https://storage.googleapis.com/bert_models/2018_11_03/chinese_L-12_H-768_A-12.zip

比较大,差不多有300M,我一般用free download manager工具来下载

 

七:启动模型

1. 把刚才的模型解压缩到某一地址

2. 切换到python35环境:

conda activate python35

3. 启动模型

bert-serving-start -model_dir 模型地址 -num_worker=2 -cpu

 

八:使用VSCode调试程序

我比较喜欢用vs code

Vscode 下设置conda环境,参考该文 https://www.cnblogs.com/justn0w/articles/11644507.html

但python需要指向python 3.5版本,需要设置工作区

工作区设置:

  "python.pythonPath": "/anaconda3/envs/python35"

 

这样所有的环境准备都完成了!

原文地址:https://www.cnblogs.com/sjc2547/p/jincheng123.html