bert_serving 获取张量
强烈推介IDEA2020.2破解激活,IntelliJ IDEA 注册码,2020.2 IDEA 激活码
安装:
pip install bert-serving-server # server pip install bert-serving-client # client, independent of `bert-serving-server`
启动server
/data/apps/opt/anaconda3/bin/python /home/nlp/.local/bin/bert-serving-start -model_dir /data/nlp/pretrained_models/chinese_wwm_ext_L-12_H-768_A-12/ -num_worker=2 -port=5555 -port_out=5556
调用
from bert_serving.client import BertClient
bc = BertClient(ip='10.111.36.141')
test=bc.encode(['你好','bert'])
print(test)
输出
[[ 0.910996 0.09173454 0.31665277 ... 0.34575224 0.2235426 0.26009858] [-0.4473213 -0.16672006 -0.03753631 ... 0.15099688 -0.52282304 -0.24906637]]
------------- 分割线 -------------------
参数 | 说明 |
---|---|
-model_dir | 预训练模型的路径 |
-num_worker | 线程数,表示同时可以处理多少个并发请求 |
-pooling_strategy | 默认是句向量;-pooling_strategy NONE是词向量 |
-max_seq_len | 句子最大长度 |