bert-as-service 尝试

栏目: Java · 发布时间: 5年前

内容简介:肖涵博士,bert-as-service 作者。现为腾讯 AI Lab 高级科学家、德中人工智能协会主席。启动server:bert-serving-start -model_dir uncased_L-12_H-768_A-12 -num_worker=4

肖涵博士,bert-as-service 作者。现为腾讯 AI Lab 高级科学家、德中人工智能协会主席。

启动server:

bert-serving-start -model_dir uncased_L-12_H-768_A-12 -num_worker=4

/home/zhongling/tensorflow1.4/lib/python3.5/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.

from ._conv import register_converters as _register_converters

usage: /home/zhongling/tensorflow1.4/bin/bert-serving-start -model_dir uncased_L-12_H-768_A-12 -num_worker=4

ARG   VALUE

__________________________________________________

ckpt_name = bert_model.ckpt

config_name = bert_config.json

cors = *

cpu = False

device_map = []

fp16 = False

gpu_memory_fraction = 0.5

graph_tmp_dir = None

http_max_connect = 10

http_port = None

mask_cls_sep = False

max_batch_size = 256

max_seq_len = 25

model_dir = uncased_L-12_H-768_A-12

num_worker = 4

pooling_layer = [-2]

pooling_strategy = REDUCE_MEAN

port = 5555

port_out = 5556

prefetch_size = 10

priority_batch_size = 16

tuned_model_dir = None

verbose = False

xla = False

I:VENTILATOR:[__i:__i: 63]:freeze, optimize and export graph, could take a while...

I:GRAPHOPT:[gra:opt: 52]:model config: uncased_L-12_H-768_A-12/bert_config.json

I:GRAPHOPT:[gra:opt: 55]:checkpoint: uncased_L-12_H-768_A-12/bert_model.ckpt

I:GRAPHOPT:[gra:opt: 59]:build graph...

I:GRAPHOPT:[gra:opt:128]:load parameters from checkpoint...

I:GRAPHOPT:[gra:opt:132]:optimize...

启动客户端:

>>> bc = BertClient("192.168.2.12")

>>> arr = ["women bag","phone case","Spring and summer lace bra wrapped chest anti cross chest sexy vest backing sling underwear (without PAD)","Factory Direct Fawn Decorations Bucket Bag","Fashion Women's Crossbody Bag Shoulder Bag With Cute Decoration","Flower Stud Earrings","Luxury Phone Case For iPhone"]

>>> for i in range(len(arr)):

...     print(i,arr[i])

...

0 women bag

1 phone case

2 Spring and summer lace bra wrapped chest anti cross chest sexy vest backing sling underwear (without PAD)

3 Factory Direct Fawn Decorations Bucket Bag

4 Fashion Women's Crossbody Bag Shoulder Bag With Cute Decoration

5 Flower Stud Earrings

6 Luxury Phone Case For iPhone

>>> vecs = bc.encode(arr)

>>> 1 - spatial.distance.cosine(vecs[1],vecs[2])

0.6363017559051514

>>> 1 - spatial.distance.cosine(vecs[1],vecs[3])

0.703334391117096

>>> 1 - spatial.distance.cosine(vecs[1],vecs[4])

0.6734864711761475

>>> 1 - spatial.distance.cosine(vecs[1],vecs[5])

0.7531731724739075

>>> 1 - spatial.distance.cosine(vecs[1],vecs[6])

0.7267242670059204


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Python高效开发实战

Python高效开发实战

刘长龙 / 电子工业出版社 / 2016-10 / 89

也许你听说过全栈工程师,他们善于设计系统架构,精通数据库建模、通用网络协议、后端并发处理、前端界面设计,在学术研究或工程项目上能独当一面。通过对Python及其周边Web框架的学习和实践,你就可以成为这样的全能型人才。 《Python高效开发实战——Django、Tornado、Flask、Twisted》分为3部分:第1部分是基础篇,带领初学者实践Python开发环境和掌握基本语法,同时对......一起来看看 《Python高效开发实战》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

SHA 加密
SHA 加密

SHA 加密工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换