XLNet¶
- Reference:
Yang et al. “XLNet: Generalized Autoregressive Pretraining for Language Understanding” in NIPS 2019.
- class textbox.model.LM.xlnet.XLNet(config, dataset)[source]¶
Bases:
UnconditionalGenerator
XLnet is an extension of the Transformer-XL model pre-trained using an autoregressive method to learn bidirectional contexts by maximizing the expected likelihood over all permutations of the input sequence factorization order.
- forward(corpus, epoch_idx=- 1, nll_test=False)[source]¶
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- generate(batch_data, eval_data)[source]¶
Predict the texts conditioned on a noise or sequence.
- Parameters
batch_data (Corpus) – Corpus class of a single batch.
eval_data – Common data of all the batches.
- Returns
Generated text, shape: [batch_size, max_len]
- Return type
torch.Tensor
- training: bool¶