from transformers import pipeline # ──────────────────────────────────────────────────────────────── # 3. Question Answering (extractive) # ──────────────────────────────────────────────────────────────── # Default model: deepset/roberta-base-squad2 # → Used for: very good balance of speed & accuracy on SQuAD-style questions # (finds answer spans in given context) # widely used in 2022–2024 documentation & tutorials # # Alternative model: deepset/deberta-v3-large-squad2 # → Used for: significantly higher accuracy (especially hard questions) # better at understanding complex context & negation # but slower & needs more memory (~435M params) pipe = pipeline("question-answering") # pipe = pipeline("question-answering", model="deepset/deberta-v3-large-squad2") result = pipe( question="Which city in Punjab has the biggest textile market?", context="Ludhiana is famous for its huge textile and hosiery industry." ) print(result["answer"])