uzw commited on
Commit
360c1e8
·
verified ·
1 Parent(s): 7657987

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +49 -3
README.md CHANGED
@@ -1,3 +1,49 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ ---
4
+
5
+ ### Generating Questions Given Context and Answers
6
+
7
+ 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.
8
+
9
+ ### How to use
10
+ Here is how to use this model in PyTorch:
11
+ ```python
12
+ from transformers import BartForConditionalGeneration, BartTokenizer
13
+ import torch
14
+
15
+ tokenizer = BartTokenizer.from_pretrained('uzw/bart-large-question-generation')
16
+ model = BartForConditionalGeneration.from_pretrained('uzw/bart-large-question-generation')
17
+
18
+ context = "The Thug cult resides at the Pankot Palace."
19
+ answer = "The Thug cult"
20
+
21
+ inputs = tokenizer.encode_plus(
22
+ context,
23
+ answer,
24
+ max_length=512,
25
+ padding='max_length',
26
+ truncation=True,
27
+ return_tensors='pt'
28
+ )
29
+
30
+ with torch.no_grad():
31
+ generated_ids = model.generate(
32
+ input_ids=inputs['input_ids'],
33
+ attention_mask=inputs['attention_mask'],
34
+ max_length=64, # Maximum length of generated question
35
+ num_return_sequences=3, # Generate multiple questions
36
+ do_sample=True, # Enable sampling for diversity
37
+ temperature=0.7 # Control randomness of generation
38
+ )
39
+
40
+ generated_questions = tokenizer.batch_decode(
41
+ generated_ids,
42
+ skip_special_tokens=True
43
+ )
44
+
45
+ for i, question in enumerate(generated_questions, 1):
46
+ print(f"Generated Question {i}: {question}")
47
+ ```
48
+
49
+ Adjusting parameter `num_return_sequences` to generate multiple questions.