risha_testing / QandA.py
rishach's picture
Upload full fitnetuned model + tokenizer +generation config
9e5fc05 verified
Raw
History Blame Contribute Delete
1.3 kB
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"])