MCPcopy Create free account
hub / github.com/modelscope/modelscope / forward

Method forward

modelscope/models/nlp/ponet/backbone.py:698–900  ·  view source on GitHub ↗

r""" Args: input_ids (:obj:`torch.LongTensor` of shape :obj:`(batch_size, sequence_length)`): Indices of input sequence tokens in the vocabulary. Indices can be obtained using :class:`~modelscope.models.nlp.ponet.PoNetTokenizer`. See

(
        self,
        input_ids=None,
        attention_mask=None,
        token_type_ids=None,
        segment_ids=None,
        position_ids=None,
        head_mask=None,
        inputs_embeds=None,
        encoder_hidden_states=None,
        encoder_attention_mask=None,
        past_key_values=None,
        use_cache=None,
        output_attentions=None,
        output_hidden_states=None,
        return_dict=None,
    )

Source from the content-addressed store, hash-verified

696 self.encoder.layer[layer].attention.prune_heads(heads)
697
698 def forward(
699 self,
700 input_ids=None,
701 attention_mask=None,
702 token_type_ids=None,
703 segment_ids=None,
704 position_ids=None,
705 head_mask=None,
706 inputs_embeds=None,
707 encoder_hidden_states=None,
708 encoder_attention_mask=None,
709 past_key_values=None,
710 use_cache=None,
711 output_attentions=None,
712 output_hidden_states=None,
713 return_dict=None,
714 ):
715 r"""
716 Args:
717 input_ids (:obj:`torch.LongTensor` of shape :obj:`(batch_size, sequence_length)`):
718 Indices of input sequence tokens in the vocabulary.
719
720 Indices can be obtained using :class:`~modelscope.models.nlp.ponet.PoNetTokenizer`. See
721 :meth:`transformers.PreTrainedTokenizer.encode` and :meth:`transformers.PreTrainedTokenizer.__call__`
722 for details.
723
724 attention_mask (:obj:`torch.FloatTensor` of shape :obj:`(batch_size, sequence_length)`, `optional`):
725 Mask to avoid performing attention on padding token indices. Mask values selected in ``[0, 1]``:
726
727 - 1 for tokens that are **not masked**,
728 - 0 for tokens that are **masked**.
729
730 token_type_ids (:obj:`torch.LongTensor` of shape :obj:`(batch_size, sequence_length)`, `optional`):
731 Segment token indices to indicate first and second portions of the inputs. Indices are selected in
732 ``[0,1]``:
733
734 - 0 corresponds to a `sentence A` token,
735 - 1 corresponds to a `sentence B` token.
736
737 position_ids (:obj:`torch.LongTensor` of shape :obj:`(batch_size, sequence_length)`, `optional`):
738 Indices of positions of each input sequence tokens in the position embeddings. Selected in the range
739 ``[0,config.max_position_embeddings - 1]``.
740
741 head_mask (:obj:`torch.FloatTensor` of shape :obj:`(num_heads,)` or :obj:`(num_layers, num_heads)`,
742 `optional`):
743 Mask to nullify selected heads of the self-attention modules. Mask values selected in ``[0, 1]``:
744
745 - 1 indicates the head is **not masked**,
746 - 0 indicates the head is **masked**.
747
748 inputs_embeds (:obj:`torch.FloatTensor` of shape :obj:`(batch_size, sequence_length, hidden_size)`,
749 `optional`):
750 Optionally, instead of passing :obj:`input_ids` you can choose to directly pass an embedded
751 representation. This is useful if you want more control over how to convert :obj:`input_ids`
752 indices into associated vectors than the model's internal embedding lookup matrix.
753 output_attentions (:obj:`bool`, `optional`):
754 Whether or not to return the attentions tensors of all attention layers. See ``attentions`` under
755 returned tensors for more detail.

Callers

nothing calls this directly

Calls 7

get_segment_indexFunction · 0.85
get_token_type_maskFunction · 0.85
encoderMethod · 0.80
poolerMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected