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) 。