bs_client.py 627 字节
Newer Older
走神的阿圆's avatar
走神的阿圆 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
from paddlehub.serving.bert_serving import bert_service


class BSClient(object):
    def __init__(self,
                 module_name,
                 server,
                 max_seq_len=20,
                 show_ids=False,
                 do_lower_case=True,
                 retry=3):
        self.bs = bert_service.BertService(
            model_name=module_name,
            max_seq_len=max_seq_len,
            show_ids=show_ids,
            do_lower_case=do_lower_case,
            retry=retry)
        self.bs.add_server(server=server)

    def get_result(self, input_text):
        return self.bs.encode(input_text)