forked from jina-ai/clip-as-service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example3.py
37 lines (27 loc) · 1.01 KB
/
example3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Han Xiao <artex.xh@gmail.com> <https://hanxiao.github.io>
# NOTE: First install bert-as-service via
# $
# $ pip install bert-serving-server
# $ pip install bert-serving-client
# $
# using BertClient in multicast way
import sys
import threading
from bert_serving.client import BertClient
def client_clone(id, idx):
bc = BertClient(port=int(sys.argv[1]), port_out=int(sys.argv[2]), identity=id)
for j in bc.fetch():
print('clone-client-%d: received %d x %d' % (idx, j.shape[0], j.shape[1]))
if __name__ == '__main__':
bc = BertClient(port=int(sys.argv[1]), port_out=int(sys.argv[2]))
# start two cloned clients sharing the same identity as bc
for j in range(2):
t = threading.Thread(target=client_clone, args=(bc.identity, j))
t.start()
with open('README.md') as fp:
data = [v for v in fp if v.strip()]
for _ in range(3):
vec = bc.encode(data)
print('bc received %d x %d' % (vec.shape[0], vec.shape[1]))