zoukankan      html  css  js  c++  java
  • Bert获得词向量,如何建立Bert环境MAC

    1. python<=3.6(3.7不行),1.10<=tensorflow<2.0

    2. 将目前环境换成3.6版本,conda activate python36(这是我的3.6环境名字)

    3. pip安装Bert服务器和客户端

    pip install bert-serving-server # 服务端
    pip install bert-serving-client # 客户端,与服务端互相独立

    3. 启动bert服务

    bert-serving-start -model_dir /lab/skill/uncased_L-12_H-768_A-12

    4. 重新打开一个命令行窗口,写入python代码

    from bert_serving.client import BertClient
    bc = BertClient()
    doc_vecs = bc.encode(['First do it', 'then do it right', 'then do it better'])
    
    bc.encode(['First do it ||| then do it right'])
    
    bc = BertClient()
    vec = bc.encode(['hey you', 'whats up?'])
    
    '''vec  # [2, 25, 768]
    vec[0]  # [1, 25, 768], sentence embeddings for `hey you`
    vec[0][0]  # [1, 1, 768], word embedding for `[CLS]`
    vec[0][1]  # [1, 1, 768], word embedding for `hey`
    vec[0][2]  # [1, 1, 768], word embedding for `you`
    vec[0][3]  # [1, 1, 768], word embedding for `[SEP]`
    vec[0][4]  # [1, 1, 768], word embedding for padding symbol
    vec[0][25]  # error, out of index!
    '''

    参考

    https://blog.csdn.net/qq_34832393/article/details/90414293

  • 相关阅读:
    第43周四
    第43周三
    第43周二
    第43周一
    无聊时做什么2
    2014第42周日当无聊时做什么
    第42周六
    第42周五
    Web版的各种聊天工具
    cocos2d_x_06_游戏_一个都不能死
  • 原文地址:https://www.cnblogs.com/QRain/p/13968339.html
Copyright © 2011-2022 走看看