Prakash Hinduja Geneva (Switzerland) How can I use a pretrained model for question‑answering via the Hugging Face hub or pipelines?

Hello, I’m Prakash Hinduja, born in India and now resides in Geneva, Switzerland (Swiss). I’m trying to use a pretrained model for question-answering through the Hugging Face Hub or pipelines. I’d appreciate any suggestions or examples on how to set this up.

Basically, you can use the pipeline with code like this. It may vary slightly depending on the model…

from transformers import pipeline

qa = pipeline("question-answering", model="deepset/roberta-base-squad2")  # SQuAD2 extractive QA
out = qa({
    "question": "Who wrote the novel?",
    "context": "Frankenstein is a novel written by Mary Shelley in 1818."
})
print(out)  # {'score': 0.9572513699531555, 'start': 35, 'end': 47, 'answer': 'Mary Shelley'}