bert 客户端无法远程访问到server
Created by: rickyhuw
使用127.0.0.1这个IP是可以访问的,切换到本机IP就无法访问了。 报错日志: Traceback (most recent call last): File "1.py", line 6, in bc = bs_client.BSClient(module_name="ernie_tiny", server="10.19.141.148:8866") File "/home/work/.local/lib/python3.6/site-packages/paddlehub/serving/bert_serving/bs_client.py", line 18, in init self.bs.add_server(server=server) File "/home/work/.local/lib/python3.6/site-packages/paddlehub/serving/bert_serving/bert_service.py", line 76, in add_server self.check_server() File "/home/work/.local/lib/python3.6/site-packages/paddlehub/serving/bert_serving/bert_service.py", line 88, in check_server client.connect((server_ip, server_port)) ConnectionRefusedError: [Errno 111] Connection refused
demo 代码:
coding: utf8
from paddlehub.serving.bert_serving import bs_client
if name == "main": # 初始化bert_service客户端BSClient bc = bs_client.BSClient(module_name="ernie_tiny", server="10.19.141.148:8866")
# 输入要做embedding的文本
# 文本格式为[["文本1"], ["文本2"], ]
input_text = [
["西风吹老洞庭波"],
["一夜湘君白发多"],
["醉后不知天在水"],
["满船清梦压星河"],
]
# BSClient.get_result()获取结果
result = bc.get_result(input_text=input_text)
# 打印输入文本的embedding结果
for item in result:
print(item)