r""" labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*): Labels for computing the token classification loss. Indices should be in `[0, ..., config.num_labels - 1]`.
(
self,
input_ids: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.FloatTensor] = None,
token_type_ids: Optional[torch.LongTensor] = None,
position_ids: Optional[torch.LongTensor] = None,
head_mask: Optional[torch.FloatTensor] = None,
inputs_embeds: Optional[torch.FloatTensor] = None,
labels: Optional[torch.LongTensor] = None,
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
return_dict: Optional[bool] = None,
)
| 1386 | expected_loss=0.01, |
| 1387 | ) |
| 1388 | def forward( |
| 1389 | self, |
| 1390 | input_ids: Optional[torch.LongTensor] = None, |
| 1391 | attention_mask: Optional[torch.FloatTensor] = None, |
| 1392 | token_type_ids: Optional[torch.LongTensor] = None, |
| 1393 | position_ids: Optional[torch.LongTensor] = None, |
| 1394 | head_mask: Optional[torch.FloatTensor] = None, |
| 1395 | inputs_embeds: Optional[torch.FloatTensor] = None, |
| 1396 | labels: Optional[torch.LongTensor] = None, |
| 1397 | output_attentions: Optional[bool] = None, |
| 1398 | output_hidden_states: Optional[bool] = None, |
| 1399 | return_dict: Optional[bool] = None, |
| 1400 | ) -> Union[Tuple[torch.Tensor], TokenClassifierOutput]: |
| 1401 | r""" |
| 1402 | labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*): |
| 1403 | Labels for computing the token classification loss. Indices should be in `[0, ..., config.num_labels - 1]`. |
| 1404 | """ |
| 1405 | return_dict = return_dict if return_dict is not None else self.config.use_return_dict |
| 1406 | |
| 1407 | outputs = self.roberta( |
| 1408 | input_ids, |
| 1409 | attention_mask=attention_mask, |
| 1410 | token_type_ids=token_type_ids, |
| 1411 | position_ids=position_ids, |
| 1412 | head_mask=head_mask, |
| 1413 | inputs_embeds=inputs_embeds, |
| 1414 | output_attentions=output_attentions, |
| 1415 | output_hidden_states=output_hidden_states, |
| 1416 | return_dict=return_dict, |
| 1417 | # timestep=timestep, |
| 1418 | ) |
| 1419 | |
| 1420 | sequence_output = outputs[0] |
| 1421 | |
| 1422 | sequence_output = self.dropout(sequence_output) |
| 1423 | logits = self.classifier(sequence_output) |
| 1424 | |
| 1425 | loss = None |
| 1426 | if labels is not None: |
| 1427 | loss_fct = CrossEntropyLoss() |
| 1428 | loss = loss_fct(logits.view(-1, self.num_labels), labels.view(-1)) |
| 1429 | |
| 1430 | if not return_dict: |
| 1431 | output = (logits,) + outputs[2:] |
| 1432 | return ((loss,) + output) if loss is not None else output |
| 1433 | |
| 1434 | return TokenClassifierOutput( |
| 1435 | loss=loss, |
| 1436 | logits=logits, |
| 1437 | hidden_states=outputs.hidden_states, |
| 1438 | attentions=outputs.attentions, |
| 1439 | ) |
| 1440 | |
| 1441 | |
| 1442 | class RobertaClassificationHead(nn.Module): |
nothing calls this directly
no outgoing calls
no test coverage detected