r""" Return: :obj:`tuple(torch.FloatTensor)` comprising various elements depending on the configuration (:class:`~transformers.XLNetConfig`) and inputs: last_hidden_state (:obj:`torch.FloatTensor` of shape :obj:`(batch_size, num_predict, hidden_size)`): Sequence of hi
(
self,
input_ids=None,
attention_mask=None,
mems=None,
perm_mask=None,
target_mapping=None,
token_type_ids=None,
input_mask=None,
head_mask=None,
inputs_embeds=None,
use_cache=True,
output_attentions=None,
output_hidden_states=None,
)
| 753 | @add_start_docstrings_to_callable(XLNET_INPUTS_DOCSTRING.format("(batch_size, sequence_length)")) |
| 754 | @add_code_sample_docstrings(tokenizer_class=_TOKENIZER_FOR_DOC, checkpoint="xlnet-base-cased") |
| 755 | def forward( |
| 756 | self, |
| 757 | input_ids=None, |
| 758 | attention_mask=None, |
| 759 | mems=None, |
| 760 | perm_mask=None, |
| 761 | target_mapping=None, |
| 762 | token_type_ids=None, |
| 763 | input_mask=None, |
| 764 | head_mask=None, |
| 765 | inputs_embeds=None, |
| 766 | use_cache=True, |
| 767 | output_attentions=None, |
| 768 | output_hidden_states=None, |
| 769 | ): |
| 770 | r""" |
| 771 | Return: |
| 772 | :obj:`tuple(torch.FloatTensor)` comprising various elements depending on the configuration (:class:`~transformers.XLNetConfig`) and inputs: |
| 773 | last_hidden_state (:obj:`torch.FloatTensor` of shape :obj:`(batch_size, num_predict, hidden_size)`): |
| 774 | Sequence of hidden-states at the last layer of the model. |
| 775 | `num_predict` corresponds to `target_mapping.shape[1]`. If `target_mapping` is `None`, then `num_predict` corresponds to `sequence_length`. |
| 776 | mems (:obj:`List[torch.FloatTensor]` of length :obj:`config.n_layers`): |
| 777 | Contains pre-computed hidden-states (key and values in the attention blocks). |
| 778 | Can be used (see `mems` input) to speed up sequential decoding. The token ids which have their past given to this model |
| 779 | should not be passed as input ids as they have already been computed. |
| 780 | hidden_states (:obj:`tuple(torch.FloatTensor)`, `optional`, returned when ``output_hidden_states=True`` is passed or when ``config.output_hidden_states=True``): |
| 781 | Tuple of :obj:`torch.FloatTensor` (one for the output of the embeddings + one for the output of each layer) |
| 782 | of shape :obj:`(batch_size, sequence_length, hidden_size)`. |
| 783 | |
| 784 | Hidden-states of the model at the output of each layer plus the initial embedding outputs. |
| 785 | attentions (:obj:`tuple(torch.FloatTensor)`, `optional`, returned when ``output_attentions=True`` is passed or when ``config.output_attentions=True``): |
| 786 | Tuple of :obj:`torch.FloatTensor` (one for each layer) of shape |
| 787 | :obj:`(batch_size, num_heads, sequence_length, sequence_length)`. |
| 788 | |
| 789 | Attentions weights after the attention softmax, used to compute the weighted average in the self-attention |
| 790 | heads. |
| 791 | """ |
| 792 | output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions |
| 793 | output_hidden_states = ( |
| 794 | output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states |
| 795 | ) |
| 796 | |
| 797 | # the original code for XLNet uses shapes [len, bsz] with the batch dimension at the end |
| 798 | # but we want a unified interface in the library with the batch size on the first dimension |
| 799 | # so we move here the first dimension (batch) to the end |
| 800 | if input_ids is not None and inputs_embeds is not None: |
| 801 | raise ValueError("You cannot specify both input_ids and inputs_embeds at the same time") |
| 802 | elif input_ids is not None: |
| 803 | input_ids = input_ids.transpose(0, 1).contiguous() |
| 804 | qlen, bsz = input_ids.shape[0], input_ids.shape[1] |
| 805 | elif inputs_embeds is not None: |
| 806 | inputs_embeds = inputs_embeds.transpose(0, 1).contiguous() |
| 807 | qlen, bsz = inputs_embeds.shape[0], inputs_embeds.shape[1] |
| 808 | else: |
| 809 | raise ValueError("You have to specify either input_ids or inputs_embeds") |
| 810 | |
| 811 | token_type_ids = token_type_ids.transpose(0, 1).contiguous() if token_type_ids is not None else None |
| 812 | input_mask = input_mask.transpose(0, 1).contiguous() if input_mask is not None else None |
nothing calls this directly
no test coverage detected