https://github.com/lonePatient/albert_pytorch/blob/master/README_zh.md
- 停止更新
- 僅僅是基於參考進行轉換,然後踩踩雷
- Albert zh for pytorch-transformers
- 測試支援繁體中文
先將本repo中的albert_zh
放置在你的專案底下
from albert_zh import ...
AlbertConfig
AlbertTokenizer
AlbertModel
AlbertForMaskedLM
AlbertForQuestionAnswering
AlbertForSequenceClassification
https://huggingface.co/transformers/v2.3.0/model_doc/albert.html
- 請參見
usage_example.py
或是參考p208p2002/taipei-QA-BERT的實際使用範例
- 測試在 transformers 2.3.0 正常運作
這個repo命名不符合python module命名慣例,並且jupyter本身對自訂的模組沒有很好的支援,請先參考下方的解決範例。後續考慮推上pypi
# 此段code僅適用於jupyter、colab
!git clone https://github.com/p208p2002/albert-zh-for-pytorch-transformers.git albert
import sys
sys.path.append('.')
from albert.albert_zh import AlbertConfig, AlbertTokenizer, AlbertForSequenceClassification
確保 model class 與 model config 由 albert_zh 引入,而非 transformers
config.json增加"share_type":"all"
請用log()
代替print()
,並且在程式開始的時候先執行一次blockPrint()
import os,sys
def log(*logs):
enablePrint()
print(*logs)
blockPrint()
# Disable
def blockPrint():
sys.stdout = open(os.devnull, 'w')
# Restore
def enablePrint():
sys.stdout = sys.__stdout__
- python 3.6.4
- pyotrch 1.3 (with cuda 10)
- transformers 2.3.0