Licence
[中文 | anglais]
Implémentation non officielle de XLNET. L'intégration d'extraction et d'extrait d'intégration avec la mémoire montre comment obtenir les sorties de la dernière couche de transformateur à l'aide de points de contrôle pré-formés.
pip install keras-xlnetCliquez sur le nom de la tâche pour voir les démos avec le modèle de base:
| Nom de tâche | Métrique | Résultats approximatifs sur les développeurs |
|---|---|---|
| Cola | Matthew Corr. | 52 |
| SST-2 | Précision | 93 |
| MRPC | Précision / F1 | 86/89 |
| STS-B | Pearson Corr. / Spearman Corr. | 86/87 |
| QQP | Précision / F1 | 90/86 |
| MNLI | Précision | 84/84 |
| QNLI | Précision | 86 |
| Rte | Précision | 64 |
| WNLI | Précision | 56 |
(Seuls 0 est prévu dans l'ensemble de données WNLI)
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 () Les arguments batch_size , memory_len et target_len sont des tailles maximales utilisées pour l'initialisation des souvenirs. Le modèle utilisé pour la formation d'un modèle de langue est retourné si in_train_phase est True , sinon un modèle utilisé pour le réglage fin sera retourné.
Notez que shuffle doit être False dans fit ou fit_generator si des souvenirs sont utilisés.
in_train_phase est False3 entrées:
(batch_size, target_len) .(batch_size, target_len) .(batch_size, 1) .1 sortie:
(batch_size, target_len, units) . in_train_phase est True4 entrées:
(batch_size, target_len) .(batch_size, target_len) .(batch_size, 1) .(batch_size, target_len) .1 sortie:
(batch_size, target_len, num_token) .