keras-bert学习

TOKEN_PAD = ''                   # Token for padding               填充标记
TOKEN_UNK = '<UNK>'              # Token for unknown words         未登录词标记
TOKEN_CLS = '<CLS>'              # Token for classification        分类标记
TOKEN_SEP = '<SEP>'              # Token for separation            分隔符标记
TOKEN_MASK = '<MASK>'            # Token for masking               掩蔽标记

token_dict = get_base_dict()
print(token_dict)
# {'': 0, '<UNK>': 1, '<CLS>': 2, '<SEP>': 3, '<MASK>': 4}
# len(token_dict) = 5

example01:
sentence_pairs = 
[
    [['all', 'work', 'and', 'no', 'play'], ['makes', 'jack', 'a', 'dull', 'boy']],
    [['from', 'the', 'day', 'forth'], ['my', 'arm', 'changed']],
    [['and', 'a', 'voice', 'echoed'], ['power', 'give', 'me', 'more', 'power']]
]

for pairs in sentence_pairs:
    for token in pairs[0] + pairs[1]:
        if token not in token_dict:
            token_dict[token] = len(token_dict)   # 未添加 token 前,token_dict 字典的长度
token_list = list(token_dict.keys())              # 用于随机选择一个单词
print(token_list)
# ['', '<UNK>', '<CLS>', '<SEP>', '<MASK>', 'all', 'work', 'and', 'no', 'play', 'makes', 'jack', 'a', 'dull', 'boy', 'from', 'the', 'day', 'forth', 'my', 'arm', 'changed', 'voice', 'echoed', 'power', 'give', 'me', 'more']
print(list(token_dict.values()))
# [0, 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]

https://github.com/CyberZHG/keras-bert/

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
kaggle中WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7a356dc338d0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/keras-bert/ WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7a356dc33410>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/keras-bert/ WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7a356dc33290>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/keras-bert/ WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7a356dc33590>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/keras-bert/ WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7a356dc354d0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/keras-bert/ ERROR: Could not find a version that satisfies the requirement keras_bert (from versions: none) ERROR: No matching distribution found for keras_bert
05-28
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值