How can I implement basic question answering with hugging-face?
I have:

from transformers import XLNetTokenizer, XLNetForQuestionAnswering
import torch

tokenizer =  XLNetTokenizer.from_pretrained('xlnet-base-cased')
model = XLNetForQuestionAnswering.from_pretrained('xlnet-base-cased')

input_ids = torch.tensor(tokenizer.encode("What is my name?", add_special_tokens=True)).unsqueeze(0)  # Batch size 1
start_positions = torch.tensor([1])
end_positions = torch.tensor([3])
outputs = model(input_ids, start_positions=start_positions, end_positions=end_positions)
loss = outputs[0]

print(outputs)
print(loss)


As per the docs. This does something giving:

(tensor(2.3008, grad_fn=&lt;DivBackward0&gt;),)
tensor(2.3008, grad_fn=&lt;DivBackward0&gt;)


However, I want an actual answer if possible?

Thanks to Joe Davison for providing the answer on Twitter:

from transformers import pipeline

qa = pipeline('question-answering')
response = qa(context='I like to eat apples, but hate bananas.',
              question='What do I like?')

print(response)


gives a response of:

{'score': 0.282511100858045, 'start': 31, 'end': 38, 'answer': 'bananas.'}


Not quite right, but at least the score is low.
