| 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"]) |