File size: 2,440 Bytes
360c1e8
 
42a5b31
 
8be57f7
 
 
3a6e4a2
 
 
360c1e8
 
bbd7c72
 
 
 
360c1e8
 
 
bbd7c72
360c1e8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bbd7c72
 
 
 
63d700f
bbd7c72
 
 
 
 
 
 
 
 
 
8be57f7
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
---
license: apache-2.0
base_model:
- facebook/bart-large
language:
- en
library_name: pytorch
pipeline_tag: text-generation
tags:
- question-generation
---

> This Question Generation model is a part of the [PlainQAFact](https://github.com/zhiwenyou103/PlainQAFact) factuality evaluation framework. 


## Generating Questions Given Context and Answers

Traditional BART model is not pre-trained on QG tasks. We fine-tuned `facebook/bart-large` model using 55k human-created question answering pairs with contexts collected by [Demszky et al. (2018)](https://arxiv.org/abs/1809.02922). The dataset includes SQuAD and QA2D question answering pairs associated with contexts.  

## How to use
Here is how to use this model in PyTorch:
```python
from transformers import BartForConditionalGeneration, BartTokenizer
import torch

tokenizer = BartTokenizer.from_pretrained('uzw/bart-large-question-generation')
model = BartForConditionalGeneration.from_pretrained('uzw/bart-large-question-generation')

context = "The Thug cult resides at the Pankot Palace."
answer = "The Thug cult"

inputs = tokenizer.encode_plus(
    context, 
    answer, 
    max_length=512, 
    padding='max_length', 
    truncation=True, 
    return_tensors='pt'
)

with torch.no_grad():
    generated_ids = model.generate(
        input_ids=inputs['input_ids'], 
        attention_mask=inputs['attention_mask'],
        max_length=64,  # Maximum length of generated question
        num_return_sequences=3,  # Generate multiple questions
        do_sample=True,  # Enable sampling for diversity
        temperature=0.7  # Control randomness of generation
    )

generated_questions = tokenizer.batch_decode(
    generated_ids, 
    skip_special_tokens=True
)

for i, question in enumerate(generated_questions, 1):
    print(f"Generated Question {i}: {question}")
```

Adjusting parameter `num_return_sequences` to generate multiple questions.


## Citation
If you use this QG model in your research, please cite with the following BibTex entry:
```
@misc{you2025plainqafactautomaticfactualityevaluation,
      title={PlainQAFact: Automatic Factuality Evaluation Metric for Biomedical Plain Language Summaries Generation}, 
      author={Zhiwen You and Yue Guo},
      year={2025},
      eprint={2503.08890},
      archivePrefix={arXiv},
      primaryClass={cs.CL},
      url={https://arxiv.org/abs/2503.08890}, 
}
```

> Code: https://github.com/zhiwenyou103/PlainQAFact