# T5 for closed book QA

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ft5-for-closed-book-qa%2F11475%3E%5C
**Category:** Beginners\
**Created:** [November 8, 2021, 6:08pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ft5-for-closed-book-qa%2F11475 "2021-11-08T18:08:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![AntonioLopardo](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/antoniolopardo/32/2970_2.png) [@AntonioLopardo](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FAntonioLopardo)%5C
**Post date:** [November 8, 2021, 6:08pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ft5-for-closed-book-qa%2F11475%2F1 "2021-11-08T18:08:59Z")

</div>

How can I use T5 for abstractive QA, I don’t want to work on a SQUAD-like dataset, but rather get answers from general questions. Is there a prefix for this kind of QA for T5?

Thank you in advance!

---

<div class="post-metadata">

**Author:** ![nielsr](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/nielsr/32/39617_2.png) [@nielsr](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fnielsr)%5C
**Post date:** [November 9, 2021, 11:37am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ft5-for-closed-book-qa%2F11475%2F2 "2021-11-09T11:37:05Z")

</div>

Hi,

For open-domain question answering, no prefix is required. Google released several checkpoints (which you can find on our hub, such as [this one](https://huggingface.co/google/t5-small-ssm-nq)) from their [paper](https://arxiv.org/abs/2002.08910), you can use them as follows:

```auto
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer

t5_qa_model = AutoModelForSeq2SeqLM.from_pretrained("google/t5-small-ssm-nq")
t5_tok = AutoTokenizer.from_pretrained("google/t5-small-ssm-nq")

input_ids = t5_tok("When was Franklin D. Roosevelt born?", return_tensors="pt").input_ids
gen_output = t5_qa_model.generate(input_ids)[0]

print(t5_tok.decode(gen_output, skip_special_tokens=True))

```

---

<div class="post-metadata">

**Author:** ![moustafa123](https://avatars.discourse-cdn.com/v4/letter/m/c5a1d2/32.png) [@moustafa123](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fmoustafa123)%5C
**Post date:** [March 22, 2023, 3:38pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ft5-for-closed-book-qa%2F11475%2F3 "2023-03-22T15:38:22Z")

</div>

Hi Nielsr, If I have my own Q/A dataset, is it possible to fine-tune the T5 model based on it, if it is possible do you have a ready-made code to start from?

---

<div class="post-metadata">

**Author:** ![nielsr](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/nielsr/32/39617_2.png) [@nielsr](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fnielsr)%5C
**Post date:** [March 22, 2023, 8:07pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ft5-for-closed-book-qa%2F11475%2F4 "2023-03-22T20:07:26Z")

</div>

Hi,

You can use the seq2seq QA script for that: [transformers/trainer\_seq2seq\_qa.py at main · huggingface/transformers · GitHub](https://github.com/huggingface/transformers/blob/main/examples/pytorch/question-answering/trainer_seq2seq_qa.py)

---

<div class="post-metadata">

**Author:** ![moustafa123](https://avatars.discourse-cdn.com/v4/letter/m/c5a1d2/32.png) [@moustafa123](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fmoustafa123)%5C
**Post date:** [March 23, 2023, 3:03am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ft5-for-closed-book-qa%2F11475%2F5 "2023-03-23T03:03:47Z")

</div>

Thanks nielsr for the directions; however, I still have 2 enquiries and it will be great if you can help:

1. The code provider is for an open book QA problem as it requires the context and in closed book problems, the context is not given as the model needs to answer from its memory:

python run\_seq2seq\_qa.py   
–model\_name\_or\_path t5-small   
–dataset\_name squad\_v2   
\*_–context\_column context \*_  
–question\_column question   
–answer\_column answers   
–do\_train   
–do\_eval   
–per\_device\_train\_batch\_size 12   
–learning\_rate 3e-5   
–num\_train\_epochs 2   
–max\_seq\_length 384   
–doc\_stride 128   
–output\_dir /tmp/debug\_seq2seq\_squad/

1. Any idea if the script is using a prefix while training since as per the T5 paper, a prefix needs to be added to the training data so that the model concentrate on the required task (translation, summarization, Question Answering …)
