input params in RobertaForQuestionAnswering
can anyone please help me understand what are `start_positions`  and `end_positions` vars that are being passed in the model? 
(example from documentation)
[link](https://huggingface.co/transformers/model_doc/roberta.html#tfrobertaforquestionanswering): 
below is code example:
```
>>> from transformers import RobertaTokenizer, RobertaForQuestionAnswering
>>> import torch

>>> tokenizer = RobertaTokenizer.from_pretrained('roberta-base')
>>> model = RobertaForQuestionAnswering.from_pretrained('roberta-base')

>>> question, text = "Who was Jim Henson?", "Jim Henson was a nice puppet"
>>> inputs = tokenizer(question, text, return_tensors='pt')
>>> start_positions = torch.tensor([1])
>>> end_positions = torch.tensor([3])

>>> outputs = model(**inputs, start_positions=start_positions, end_positions=end_positions)
>>> loss = outputs.loss
>>> start_scores = outputs.start_logits
>>> end_scores = outputs.end_logits
```



I also have the same question as you.<|||||>The `start_positions` and `end_positions` are the labels that you provide to the model. With these, you tell the model which token is at the start of the answer, and which token is at the end of the answer.

In the example you list above, we have a single question + text. The answer to the question is "a nice puppet". So what should be the start and end positions here?

Well, first we need to tokenize the question + text using the tokenizer. We can do this as follows:

```
from transformers import RobertaTokenizer

tokenizer = RobertaTokenizer.from_pretrained("roberta-base")
question, text = "Who was Jim Henson?", "Jim Henson was a nice puppet"
encoding = tokenizer(question, text, return_tensors="pt")
```
We can now check the tokens, by converting the `input_ids` back to text using the tokenizer's `decode` method:

```
for idx, id in enumerate(encoding.input_ids.squeeze().tolist()):
  print(idx, tokenizer.decode([id]))
```
This prints:
```
0 <s>
1 Who
2  was
3  Jim
4  H
5 enson
6 ?
7 </s>
8 </s>
9 Jim
10  H
11 enson
12  was
13  a
14  nice
15  puppet
16 </s>
```
So in this case, the start position should be 13 and the end position should be 15. 

Note that the `start_positions` and `end_positions` should be of shape (batch_size,), indicating the start token index and end token index respectively for every example in the batch. As we only have a single example in this case, `start_positions` should be `torch.tensor([[13]])`. Similarly, `end_positions` should be `torch.tensor([[15]])`. 

The reason `start_positions` and `end_positions` are set to 1 and 3 in the docs is to just illustrate it, they are actually incorrect.

<|||||>Note: this is explained in detail in the official [question-answering notebook](https://github.com/huggingface/notebooks/blob/master/examples/question_answering.ipynb).<|||||>Thank you so much @NielsRogge. I finally understood the topic. 