r""" start_positions (:obj:`torch.LongTensor` of shape :obj:`(batch_size,)`, `optional`, defaults to :obj:`None`): Labels for position (index) of the start of the labelled span for computing the token classification loss. Positions are clamped to the length of the seq
(
self,
input_ids=None,
attention_mask=None,
token_type_ids=None,
position_ids=None,
head_mask=None,
inputs_embeds=None,
start_positions=None,
end_positions=None,
output_attentions=None,
output_hidden_states=None,
)
| 1487 | @add_start_docstrings_to_callable(BERT_INPUTS_DOCSTRING.format("(batch_size, sequence_length)")) |
| 1488 | @add_code_sample_docstrings(tokenizer_class=_TOKENIZER_FOR_DOC, checkpoint="bert-base-uncased") |
| 1489 | def forward( |
| 1490 | self, |
| 1491 | input_ids=None, |
| 1492 | attention_mask=None, |
| 1493 | token_type_ids=None, |
| 1494 | position_ids=None, |
| 1495 | head_mask=None, |
| 1496 | inputs_embeds=None, |
| 1497 | start_positions=None, |
| 1498 | end_positions=None, |
| 1499 | output_attentions=None, |
| 1500 | output_hidden_states=None, |
| 1501 | ): |
| 1502 | r""" |
| 1503 | start_positions (:obj:`torch.LongTensor` of shape :obj:`(batch_size,)`, `optional`, defaults to :obj:`None`): |
| 1504 | Labels for position (index) of the start of the labelled span for computing the token classification loss. |
| 1505 | Positions are clamped to the length of the sequence (`sequence_length`). |
| 1506 | Position outside of the sequence are not taken into account for computing the loss. |
| 1507 | end_positions (:obj:`torch.LongTensor` of shape :obj:`(batch_size,)`, `optional`, defaults to :obj:`None`): |
| 1508 | Labels for position (index) of the end of the labelled span for computing the token classification loss. |
| 1509 | Positions are clamped to the length of the sequence (`sequence_length`). |
| 1510 | Position outside of the sequence are not taken into account for computing the loss. |
| 1511 | |
| 1512 | Returns: |
| 1513 | :obj:`tuple(torch.FloatTensor)` comprising various elements depending on the configuration (:class:`~transformers.BertConfig`) and inputs: |
| 1514 | loss (:obj:`torch.FloatTensor` of shape :obj:`(1,)`, `optional`, returned when :obj:`labels` is provided): |
| 1515 | Total span extraction loss is the sum of a Cross-Entropy for the start and end positions. |
| 1516 | start_scores (:obj:`torch.FloatTensor` of shape :obj:`(batch_size, sequence_length,)`): |
| 1517 | Span-start scores (before SoftMax). |
| 1518 | end_scores (:obj:`torch.FloatTensor` of shape :obj:`(batch_size, sequence_length,)`): |
| 1519 | Span-end scores (before SoftMax). |
| 1520 | hidden_states (:obj:`tuple(torch.FloatTensor)`, `optional`, returned when ``output_hidden_states=True`` is passed or when ``config.output_hidden_states=True``): |
| 1521 | Tuple of :obj:`torch.FloatTensor` (one for the output of the embeddings + one for the output of each layer) |
| 1522 | of shape :obj:`(batch_size, sequence_length, hidden_size)`. |
| 1523 | |
| 1524 | Hidden-states of the model at the output of each layer plus the initial embedding outputs. |
| 1525 | attentions (:obj:`tuple(torch.FloatTensor)`, `optional`, returned when ``output_attentions=True`` is passed or when ``config.output_attentions=True``): |
| 1526 | Tuple of :obj:`torch.FloatTensor` (one for each layer) of shape |
| 1527 | :obj:`(batch_size, num_heads, sequence_length, sequence_length)`. |
| 1528 | |
| 1529 | Attentions weights after the attention softmax, used to compute the weighted average in the self-attention |
| 1530 | heads. |
| 1531 | """ |
| 1532 | |
| 1533 | outputs = self.bert( |
| 1534 | input_ids, |
| 1535 | attention_mask=attention_mask, |
| 1536 | token_type_ids=token_type_ids, |
| 1537 | position_ids=position_ids, |
| 1538 | head_mask=head_mask, |
| 1539 | inputs_embeds=inputs_embeds, |
| 1540 | output_attentions=output_attentions, |
| 1541 | output_hidden_states=output_hidden_states, |
| 1542 | ) |
| 1543 | |
| 1544 | sequence_output = outputs[0] |
| 1545 | |
| 1546 | logits = self.qa_outputs(sequence_output) |
nothing calls this directly
no outgoing calls
no test coverage detected