美文网首页BERT
bert-serving-start:command not f

bert-serving-start:command not f

作者: 凌烟阁主5221 | 来源:发表于2019-04-19 09:48 被阅读332次

    背景:比价两个句子的语义相似度任务

    实践中发现xiaohan博士的bert-as-service项目,https://github.com/hanxiao/bert-as-service

    基于BERT模型封装后,非常便于使用,将一个中文句子encoding为一个定长的向量,通过比较两个向量的相似性进而比较两个句子的语义相似度。

    win10使用正常

    首先需要先安装,可以通过pycharm--setting先安装两个包bert-serving-server,bert-serving-client

    pip install bert-serving-server#server

    pip install bert-serving-client#client, independent of `bert-serving-server`

    windows操作系统,pycharm中直接安装,然后下载chinese_L-12_H-768_A-12

    https://github.com/google-research/bert#pre-trained-models

    在cmd中 bert-serving-start -model_dir G:\bertapp\chinese_L-12_H-768_A-12 -num_worker=4

    然后直接可以使用

    from bert_serving.clientimport BertClient

    bc = BertClient()

    bc.encode(['First do it','then do it right','then do it better'])

    Linux出现无法启动服务

    首先需要先安装,在终端先安装包
    pip install bert-serving-server#server

    安装过程中如果出现错误

    按照提示添加 --user ,也就是 $ pip install --user bert-serving-server就可以了。

    pip install bert-serving-client#client, independent of `bert-serving-server`

    将该服务部署在linux服务器,方便他人调用,目前环境配置如下,

    Description: Ubuntu 17.10

    Python 3.6.3 (default, Oct 3 2017, 21:45:48)

    [GCC 7.2.0] on linux

    Type "help", "copyright", "credits" or "license" for more information.

    import tensorflow as tf

    tf.version

    '1.8.0'

    git clone项目到服务器后,发现报错bert-serving-start: command not found...

    无法启动服务,没有bert-serving-start 这个命令,于是搜一下...

    发现这个命令在/home/xx/.local/bin/bert-serving-start 这个地方 很奇怪

    然后继续执行命令python3 bert-serving-start

    发现tf版本要求1.10,这里只有1.8,所以再升级一下,结束并查看

    注意一般情况下可以直接bert-serving-start -model_dir/home/xx/pythonworkspace//chinese_L-12_H-768_A-12  -num_worker=4 启动服务

    但是有时候需要用python3来启动服务

    python3 bert-serving-start -model_dir /home/liujiefei/pythonworkspace/06bertserver/02bertapp/chinese_L-12_H-768_A-12 -num_worker=4

    python3 bert-serving-start -model_dir /home/xx/pythonworkspace//chinese_L-12_H-768_A-12 -num_worker=4

    到这里,我的问题以经解决了,xiaohan的github上的issus没有出现这种情况,因此记一下解决过程。

    看到有人在centos上这样解决的,没看懂是什么原因。

    https://github.com/hanxiao/bert-as-service/issues/99

    这个项目最初就是mac开发的,后来为了兼容windows操作系统,现在开发到bert-serving-service bert-serving-client直接pip安装就可以在win10运行,可能是ubuntu上出的问题吧

    此外对于worker设置,这里都是4,由于win10没有gpu,使用的cpu,最好与其核数一致

    理论上,如果有两个gpu,最优值是2。实际上,在获得OOM之前,您可以使用任意数量的worker(每个worker占用700MB(空闲)-1.6G GPU内存)。在这种情况下,多个worker将被堆在同一个GPU上。因此,可以观察到边际加速略大于2。

    相关文章

      网友评论

        本文标题:bert-serving-start:command not f

        本文链接:https://www.haomeiwen.com/subject/fdmfgqtx.html