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

Method forward

modelscope/models/nlp/deberta_v2/backbone.py:1093–1222  ·  view source on GitHub ↗

r""" Args: input_ids (`torch.LongTensor` of shape `('batch_size, sequence_length')`): Indices of input sequence tokens in the vocabulary. attention_mask (`torch.FloatTensor` of shape `('batch_size, sequence_length')`, *optional*): Mask

(
        self,
        input_ids: Optional[torch.Tensor] = None,
        attention_mask: Optional[torch.Tensor] = None,
        token_type_ids: Optional[torch.Tensor] = None,
        position_ids: Optional[torch.Tensor] = None,
        inputs_embeds: Optional[torch.Tensor] = None,
        output_attentions: Optional[bool] = None,
        output_hidden_states: Optional[bool] = None,
        return_dict: Optional[bool] = None,
    )

Source from the content-addressed store, hash-verified

1091 'The prune function is not implemented in DeBERTa model.')
1092
1093 def forward(
1094 self,
1095 input_ids: Optional[torch.Tensor] = None,
1096 attention_mask: Optional[torch.Tensor] = None,
1097 token_type_ids: Optional[torch.Tensor] = None,
1098 position_ids: Optional[torch.Tensor] = None,
1099 inputs_embeds: Optional[torch.Tensor] = None,
1100 output_attentions: Optional[bool] = None,
1101 output_hidden_states: Optional[bool] = None,
1102 return_dict: Optional[bool] = None,
1103 ) -> Union[Tuple, AttentionBackboneModelOutput]:
1104 r"""
1105 Args:
1106 input_ids (`torch.LongTensor` of shape `('batch_size, sequence_length')`):
1107 Indices of input sequence tokens in the vocabulary.
1108
1109 attention_mask (`torch.FloatTensor` of shape `('batch_size, sequence_length')`, *optional*):
1110 Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:
1111
1112 - 1 for tokens that are **not masked**,
1113 - 0 for tokens that are **masked**.
1114
1115 token_type_ids (`torch.LongTensor` of shape `('batch_size, sequence_length')`, *optional*):
1116 Segment token indices to indicate first and second portions of the inputs. Indices are selected in `[0,
1117 1]`:
1118
1119 - 0 corresponds to a *sentence A* token,
1120 - 1 corresponds to a *sentence B* token.
1121
1122 position_ids (`torch.LongTensor` of shape `('batch_size, sequence_length')`, *optional*):
1123 Indices of positions of each input sequence tokens in the position embeddings. Selected in the range
1124 `[0,config.max_position_embeddings - 1]`.
1125
1126 inputs_embeds (`torch.FloatTensor` of shape `('batch_size, sequence_length', hidden_size)`, *optional*):
1127 Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation.
1128 This is useful if you want more control over how to convert *input_ids* indices into associated
1129 vectors than the model's internal embedding lookup matrix.
1130 output_attentions (`bool`, *optional*):
1131 Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
1132 tensors for more detail.
1133 output_hidden_states (`bool`, *optional*):
1134 Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
1135 more detail.
1136 return_dict (`bool`, *optional*):
1137 Whether or not to return a dataclass instead of a plain tuple.
1138
1139 Returns:
1140 Returns `modelscope.outputs.AttentionBackboneModelOutput`
1141
1142 Examples:
1143 >>> from modelscope.models import Model
1144 >>> from modelscope.preprocessors import Preprocessor
1145 >>> model = Model.from_pretrained('damo/nlp_debertav2_fill-mask_chinese-lite', task='backbone')
1146 >>> preprocessor = Preprocessor.from_pretrained('damo/nlp_debertav2_fill-mask_chinese-lite')
1147 >>> print(model(**preprocessor('这是个测试')))
1148 """
1149
1150 output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions

Callers

nothing calls this directly

Calls 7

encoderMethod · 0.80
get_rel_embeddingMethod · 0.80
get_attention_maskMethod · 0.80
get_rel_posMethod · 0.80
sizeMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected