keras xlnet
1.0.0
執照
[中文|英語]
XLNET的非正式實施。將提取和將提取物嵌入內存顯示如何使用預訓練的檢查點獲取最後一個變壓器層的輸出。
pip install keras-xlnet單擊任務名稱以查看具有基本模型的演示:
| 任務名稱 | 指標 | DEV集的近似結果 |
|---|---|---|
| 可樂 | 馬修·庫。 | 52 |
| SST-2 | 準確性 | 93 |
| MRPC | 精度/F1 | 86/89 |
| STS-B | 皮爾遜·柯爾森(Pearson Corr) / Spearman Corr。 | 86/87 |
| QQP | 精度/F1 | 90/86 |
| mnli | 準確性 | 84/84 |
| Qnli | 準確性 | 86 |
| rte | 準確性 | 64 |
| wnli | 準確性 | 56 |
(WNLI數據集中僅預測0)
import os
from keras_xlnet import Tokenizer , load_trained_model_from_checkpoint , ATTENTION_TYPE_BI
checkpoint_path = '.../xlnet_cased_L-24_H-1024_A-16'
tokenizer = Tokenizer ( os . path . join ( checkpoint_path , 'spiece.model' ))
model = load_trained_model_from_checkpoint (
config_path = os . path . join ( checkpoint_path , 'xlnet_config.json' ),
checkpoint_path = os . path . join ( checkpoint_path , 'xlnet_model.ckpt' ),
batch_size = 16 ,
memory_len = 512 ,
target_len = 128 ,
in_train_phase = False ,
attention_type = ATTENTION_TYPE_BI ,
)
model . summary ()參數batch_size , memory_len和target_len是用於初始化記憶的最大尺寸。如果in_train_phase為True ,則返回用於訓練語言模型的模型,否則將返回用於微調的模型。
請注意,如果使用記憶,則False shuffle應為fit或fit_generator 。
in_train_phase是False3個輸入:
(batch_size, target_len) 。(batch_size, target_len) 。(batch_size, 1) 。1輸出:
(batch_size, target_len, units) 。 in_train_phase是True4個輸入:
(batch_size, target_len) 。(batch_size, target_len) 。(batch_size, 1) 。(batch_size, target_len) 。1輸出:
(batch_size, target_len, num_token) 。