Bert 模型離線下載使用
主要是為了能夠讓模型檔放入工作環境使用,所以需要簡單記錄一下,主要是要讓 pytorch-transformer 能夠動起來.
關鍵是針對每一個模型必須要下載 model.bin / config.json 與 tokenizer 需要的 vocab.txt
這幾個檔案其實都可以在 pytorch-transformer 裡面找到下載路徑,所以簡單透過 wget 下載下來並改名字統一放在一個目錄下就可以了
以 bert-base-chinese 為例
mkdir bert-base-chinese
wget https://s3.amazonaws.com/models.huggingface.co/bert/bert-base-chinese-pytorch_model.bin -O ./bert-base-chinese/pytorch_model.bin
wget https://s3.amazonaws.com/models.huggingface.co/bert/bert-base-chinese-config.json -O ./bert-base-chinese/config.json
wget https://s3.amazonaws.com/models.huggingface.co/bert/bert-base-chinese-vocab.txt -O ./bert-base-chinese/vocab.txt
使用的時候直接使用
model = BertModel.from_pretrained(‘./bert-base-chinese’)