两种方式
本地或者线上(中文或英文分词)
CLS, PAD = '[CLS]', '[PAD]'
# bert_path = 'bert-base-cased'
bert_path = '../bert_pretrain/' # 改为自己存放预训练模型的目录
text1 = "the game has gone!unaffable I have a new GPU!"
tokenizer = BertTokenizer.from_pretrained(bert_path)
tokens1 = tokenizer.tokenize(text1)
print("英文分词来一个:", tokens1)
输出
英文分词来一个: ['the', 'game', 'has', 'gone', '!', 'un', '##af', '##fa', '##ble', 'i', 'have', 'a', 'new', 'g', '##pu', '!']
本地包已上传,或者自己下载
https://huggingface.co/hfl