bert_as_service_client.py 636 字节
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
# coding: utf8
from paddlehub.serving.bert_serving import bert_service

if __name__ == "__main__":
    # 输入要做embedding的文本
    # 文本格式为[["文本1"], ["文本2"], ]
    input_text = [
        ["西风吹老洞庭波"],
        ["一夜湘君白发多"],
        ["醉后不知天在水"],
        ["满船清梦压星河"],
    ]
    # 调用客户端接口bert_service.connect()获取结果
    result = bert_service.connect(
        input_text=input_text,
        model_name="bert_chinese_L-12_H-768_A-12",
        server="127.0.0.1:8866")

    # 打印embedding结果
    for item in result:
        print(item)