Bert官方github地址:https://github.com/google-research/bert?tab=readme-ov-file
在github下載:
在huggingface(地址)下載config.json和pytorch_model.bin
將github下載的解壓,並將huggingface下載的config.json和pytorch_model.bin放到解壓後的資料夾:
測試:
from transformers import BertModel,BertTokenizer
BERT_PATH = '上面解壓好的資料夾的路徑'
tokenizer = BertTokenizer.from_pretrained(BERT_PATH)
print(tokenizer.tokenize('I have a good time, thank you.'))
bert = BertModel.from_pretrained(BERT_PATH)
print('load bert model over')
輸出:
['i', 'have', 'a', 'good', 'time', ',', 'thank', 'you', '.']
load bert model over
來源:https://blog.csdn.net/GCTTTTTT/article/details/136055023
(為防止來源出現意外消失故在此轉載作為筆記)