paddlenlp/transformers/fnet/modeling.py
def forward(
            self,
            input_ids=None,
            token_type_ids=None,
            position_ids=None,
            inputs_embeds=None,
            labels=None,
            output_hidden_states=None,
            return_dict=None, ):
        r"""
         The FNetForSequenceClassification forward method.

         Args:
             input_ids (Tensor):
                 Indices of input sequence tokens in the vocabulary. They are
                 numerical representations of tokens that build the input sequence.
                 Its data type should be `int64` and it has a shape of [batch_size, sequence_length].
             token_type_ids (Tensor, optional):
                 Segment token indices to indicate different portions of the inputs.
                 Selected in the range ``[0, type_vocab_size - 1]``.
                 If `type_vocab_size` is 2, which means the inputs have two portions.
                 Indices can either be 0 or 1:

                 - 0 corresponds to a *sentence A* token,
                 - 1 corresponds to a *sentence B* token.

                 Its data type should be `int64` and it has a shape of [batch_size, sequence_length].
                 Defaults to `None`, which means we don't add segment embeddings.
             position_ids(Tensor, optional):
                 Indices of positions of each input sequence tokens in the position embeddings. Selected in the range ``[0,
                 max_position_embeddings - 1]``.
                 Shape as `(batch_size, num_tokens)` and dtype as int64. Defaults to `None`.
             inputs_embeds (Tensor, optional):
                If you want to control how to convert `inputs_ids` indices into associated vectors, you can
                pass an embedded representation directly instead of passing `inputs_ids`.
            output_hidden_states (bool, optional):
                Whether or not to return all hidden states. Default to `None`.
             return_dict (bool, optional):
                 Whether or not to return a dict instead of a plain tuple. Default to `None`.


         Returns:
            Tensor or Dict: Returns tensor `logits`, or a dict with `logits`, `hidden_states`, `attentions` fields.

            With the fields:

            - `logits` (Tensor):
                A tensor of the input text classification logits.
                Shape as `[batch_size, num_classes]` and dtype as float32.

            - `hidden_states` (Tensor):
                Hidden_states of all layers in the Transformer encoder. The length of `hidden_states` is `num_hidden_layers + 1`.
                For all element in the tuple, its data type should be float32 and its shape is [`batch_size, sequence_length, hidden_size`].

         Example:
             .. code-block::

                 import paddle
                 from paddlenlp.transformers.fnet.modeling import FNetForSequenceClassification
                 from paddlenlp.transformers.fnet.tokenizer import FNetTokenizer

                 tokenizer = FNetTokenizer.from_pretrained('fnet-base')
                 model = FNetModel.from_pretrained('fnet-base')

                 inputs = tokenizer("Welcome to use PaddlePaddle and PaddleNLP!")
                 inputs = {k:paddle.to_tensor([v]) for (k, v) in inputs.items()}
                 output = model(**inputs)
         """
        outputs = self.fnet(
            input_ids,
            token_type_ids=token_type_ids,
            position_ids=position_ids,
            inputs_embeds=inputs_embeds,
            output_hidden_states=output_hidden_states,
            return_dict=return_dict, )
        pooled_output = outputs[1]
        pooled_output = self.dropout(pooled_output)
        logits = self.classifier(pooled_output)

        if return_dict:
            return {
                "logits": logits,
                "hidden_states": outputs["all_hidden_states"],
            }
        return logits
r"""
         The FNetForSequenceClassification forward method.

         Args:
             input_ids (Tensor):
                 Indices of input sequence tokens in the vocabulary. They are
                 numerical representations of tokens that build the input sequence.
                 Its data type should be `int64` and it has a shape of [batch_size, sequence_length].
             token_type_ids (Tensor, optional):
                 Segment token indices to indicate different portions of the inputs.
                 Selected in the range ``[0, type_vocab_size - 1]``.
                 If `type_vocab_size` is 2, which means the inputs have two portions.
                 Indices can either be 0 or 1:

                 - 0 corresponds to a *sentence A* token,
                 - 1 corresponds to a *sentence B* token.

                 Its data type should be `int64` and it has a shape of [batch_size, sequence_length].
                 Defaults to `None`, which means we don't add segment embeddings.
             position_ids(Tensor, optional):
                 Indices of positions of each input sequence tokens in the position embeddings. Selected in the range ``[0,
                 max_position_embeddings - 1]``.
                 Shape as `(batch_size, num_tokens)` and dtype as int64. Defaults to `None`.
             inputs_embeds (Tensor, optional):
                If you want to control how to convert `inputs_ids` indices into associated vectors, you can
                pass an embedded representation directly instead of passing `inputs_ids`.
            output_hidden_states (bool, optional):
                Whether or not to return all hidden states. Default to `None`.
             return_dict (bool, optional):
                 Whether or not to return a dict instead of a plain tuple. Default to `None`.


         Returns:
            Tensor or Dict: Returns tensor `logits`, or a dict with `logits`, `hidden_states`, `attentions` fields.

            With the fields:

            - `logits` (Tensor):
                A tensor of the input text classification logits.
                Shape as `[batch_size, num_classes]` and dtype as float32.

            - `hidden_states` (Tensor):
                Hidden_states of all layers in the Transformer encoder. The length of `hidden_states` is `num_hidden_layers + 1`.
                For all element in the tuple, its data type should be float32 and its shape is [`batch_size, sequence_length, hidden_size`].

         Example:
             .. code-block::

                 import paddle
                 from paddlenlp.transformers.fnet.modeling import FNetForSequenceClassification
                 from paddlenlp.transformers.fnet.tokenizer import FNetTokenizer

                 tokenizer = FNetTokenizer.from_pretrained('fnet-base')
                 model = FNetModel.from_pretrained('fnet-base')

                 inputs = tokenizer("Welcome to use PaddlePaddle and PaddleNLP!")
                 inputs = {k:paddle.to_tensor([v]) for (k, v) in inputs.items()}
                 output = model(**inputs)
         
r"""
The FNetForSequenceClassification forward method.
r " " " The FNetForSequenceClassification forward method .
def forward(
            self,
            input_ids=None,
            token_type_ids=None,
            position_ids=None,
            inputs_embeds=None,
            labels=None,
            output_hidden_states=None,
            return_dict=None, ):
        outputs = self.fnet(
            input_ids,
            token_type_ids=token_type_ids,
            position_ids=position_ids,
            inputs_embeds=inputs_embeds,
            output_hidden_states=output_hidden_states,
            return_dict=return_dict, )
        pooled_output = outputs[1]
        pooled_output = self.dropout(pooled_output)
        logits = self.classifier(pooled_output)
        if return_dict:
            return {
                "logits": logits,
                "hidden_states": outputs["all_hidden_states"],
            }
        return logits
def forward ( self , input_ids = None , token_type_ids = None , position_ids = None , inputs_embeds = None , labels = None , output_hidden_states = None , return_dict = None , ) : outputs = self . fnet ( input_ids , token_type_ids = token_type_ids , position_ids = position_ids , inputs_embeds = inputs_embeds , output_hidden_states = output_hidden_states , return_dict = return_dict , ) pooled_output = outputs [ 1 ] pooled_output = self . dropout ( pooled_output ) logits = self . classifier ( pooled_output ) if return_dict : return { "logits" : logits , "hidden_states" : outputs [ "all_hidden_states" ] , } return logits
r"""
The FNetForSequenceClassification forward method.
r " " " The FNetForSequenceClassification forward method .
r"""
         The FNetForSequenceClassification forward method.

         Args:
             input_ids (Tensor):
                 Indices of input sequence tokens in the vocabulary. They are
                 numerical representations of tokens that build the input sequence.
                 Its data type should be `int64` and it has a shape of [batch_size, sequence_length].
             token_type_ids (Tensor, optional):
                 Segment token indices to indicate different portions of the inputs.
                 Selected in the range ``[0, type_vocab_size - 1]``.
                 If `type_vocab_size` is 2, which means the inputs have two portions.
                 Indices can either be 0 or 1:

                 - 0 corresponds to a *sentence A* token,
                 - 1 corresponds to a *sentence B* token.

                 Its data type should be `int64` and it has a shape of [batch_size, sequence_length].
                 Defaults to `None`, which means we don't add segment embeddings.
             position_ids(Tensor, optional):
                 Indices of positions of each input sequence tokens in the position embeddings. Selected in the range ``[0,
                 max_position_embeddings - 1]``.
                 Shape as `(batch_size, num_tokens)` and dtype as int64. Defaults to `None`.
             inputs_embeds (Tensor, optional):
                If you want to control how to convert `inputs_ids` indices into associated vectors, you can
                pass an embedded representation directly instead of passing `inputs_ids`.
            output_hidden_states (bool, optional):
                Whether or not to return all hidden states. Default to `None`.
             return_dict (bool, optional):
                 Whether or not to return a dict instead of a plain tuple. Default to `None`.


         Returns:
            Tensor or Dict: Returns tensor `logits`, or a dict with `logits`, `hidden_states`, `attentions` fields.

            With the fields:

            - `logits` (Tensor):
                A tensor of the input text classification logits.
                Shape as `[batch_size, num_classes]` and dtype as float32.

            - `hidden_states` (Tensor):
                Hidden_states of all layers in the Transformer encoder. The length of `hidden_states` is `num_hidden_layers + 1`.
                For all element in the tuple, its data type should be float32 and its shape is [`batch_size, sequence_length, hidden_size`].

         Example:
             .. code-block::

                 import paddle
                 from paddlenlp.transformers.fnet.modeling import FNetForSequenceClassification
                 from paddlenlp.transformers.fnet.tokenizer import FNetTokenizer

                 tokenizer = FNetTokenizer.from_pretrained('fnet-base')
                 model = FNetModel.from_pretrained('fnet-base')

                 inputs = tokenizer("Welcome to use PaddlePaddle and PaddleNLP!")
                 inputs = {k:paddle.to_tensor([v]) for (k, v) in inputs.items()}
                 output = model(**inputs)
         """
Tensor or Dict: Returns tensor `logits`, or a dict with `logits`, `hidden_states`, `attentions` fields.

With the fields.

`logits` (Tensor):
A tensor of the input text classification logits.
Shape as `[batch_size, num_classes]` and dtype as float32.

`hidden_states` (Tensor):
Hidden_states of all layers in the Transformer encoder. The length of `hidden_states` is `num_hidden_layers + 1`.
For all element in the tuple, its data type should be float32 and its shape is [`batch_size, sequence_length, hidden_size`].
Tensor or Dict : Returns tensor ` logits ` or a dict with ` logits ` ` hidden_states ` ` attentions ` fields . With the fields . ` logits ` ( Tensor ) : A tensor of the input text classification logits . Shape as ` [ batch_size num_classes ] ` and dtype as float32 . ` hidden_states ` ( Tensor ) : Hidden_states of all layers in the Transformer encoder . The length of ` hidden_states ` is ` num_hidden_layers + 1 ` . For all element in the tuple its data type should be float32 and its shape is [ ` batch_size sequence_length hidden_size ` ] .
self
input_ids
Indices of input sequence tokens in the vocabulary. They are
numerical representations of tokens that build the input sequence.
Its data type should be `int64` and it has a shape of [batch_size, sequence_length].
Indices of input sequence tokens in the vocabulary . They are numerical representations of tokens that build the input sequence . Its data type should be ` int64 ` and it has a shape of [ batch_size sequence_length ] .
token_type_ids
Segment token indices to indicate different portions of the inputs.
Selected in the range ``[0, type_vocab_size - 1]``.
If `type_vocab_size` is 2, which means the inputs have two portions.
Indices can either be 0 or 1.

0 corresponds to a *sentence A* token,
1 corresponds to a *sentence B* token.

Its data type should be `int64` and it has a shape of [batch_size, sequence_length].
Defaults to `None`, which means we don't add segment embeddings.
Segment token indices to indicate different portions of the inputs . Selected in the range ` ` [ 0 type_vocab_size - 1 ] ` ` . If ` type_vocab_size ` is 2 which means the inputs have two portions . Indices can either be 0 or 1 . 0 corresponds to a * sentence A * token 1 corresponds to a * sentence B * token . Its data type should be ` int64 ` and it has a shape of [ batch_size sequence_length ] . Defaults to ` None ` which means we don ' t add segment embeddings .
position_ids
Indices of positions of each input sequence tokens in the position embeddings. Selected in the range ``[0,
max_position_embeddings - 1]``.
Shape as `(batch_size, num_tokens)` and dtype as int64. Defaults to `None`.
Indices of positions of each input sequence tokens in the position embeddings . Selected in the range ` ` [ 0 max_position_embeddings - 1 ] ` ` . Shape as ` ( batch_size num_tokens ) ` and dtype as int64 . Defaults to ` None ` .
inputs_embeds
If you want to control how to convert `inputs_ids` indices into associated vectors, you can
pass an embedded representation directly instead of passing `inputs_ids`.
output_hidden_states (bool, optional):
Whether or not to return all hidden states. Default to `None`.
If you want to control how to convert ` inputs_ids ` indices into associated vectors you can pass an embedded representation directly instead of passing ` inputs_ids ` . output_hidden_states ( bool optional ) : Whether or not to return all hidden states . Default to ` None ` .
labels
output_hidden_states
return_dict
Whether or not to return a dict instead of a plain tuple. Default to `None`.
Whether or not to return a dict instead of a plain tuple . Default to ` None ` .
examples
code-block:.

import paddle
from paddlenlp.transformers.fnet.modeling import FNetForSequenceClassification
from paddlenlp.transformers.fnet.tokenizer import FNetTokenizer

tokenizer = FNetTokenizer.from_pretrained('fnet-base')
model = FNetModel.from_pretrained('fnet-base')

inputs = tokenizer("Welcome to use PaddlePaddle and PaddleNLP!")
inputs = {k:paddle.to_tensor([v]) for (k, v) in inputs.items()}
output = model(**inputs)
code - block : . import paddle from paddlenlp . transformers . fnet . modeling import FNetForSequenceClassification from paddlenlp . transformers . fnet . tokenizer import FNetTokenizer tokenizer = FNetTokenizer . from_pretrained ( ' fnet - base ' ) model = FNetModel . from_pretrained ( ' fnet - base ' ) inputs = tokenizer ( " Welcome to use PaddlePaddle and PaddleNLP! " ) inputs = { k : paddle . to_tensor ( [ v ] ) for ( k v ) in inputs . items () } output = model ( ** inputs )