AbhilashDatta
commited on
Commit
•
b6dc06c
1
Parent(s):
5d68cf3
Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: afl-3.0
|
3 |
+
---
|
4 |
+
|
5 |
+
# Question generation using T5 transformer trained on SQuAD
|
6 |
+
|
7 |
+
<h2> <i>Input format: context: "..." answer(optional): "..." </i></h2>
|
8 |
+
|
9 |
+
Import the pretrained model as well as tokenizer:
|
10 |
+
```
|
11 |
+
from transformers import T5ForConditionalGeneration, T5Tokenizer
|
12 |
+
|
13 |
+
model = T5ForConditionalGeneration.from_pretrained('AbhilashDatta/T5_qgen-squad_v2')
|
14 |
+
tokenizer = T5Tokenizer.from_pretrained('AbhilashDatta/T5_qgen-squad_v2')
|
15 |
+
```
|
16 |
+
|
17 |
+
Then use the tokenizer to encode/decode and model to generate:
|
18 |
+
|
19 |
+
```
|
20 |
+
input = "context: My name is Abhilash Datta. answer: Abhilash"
|
21 |
+
batch = tokenizer(input, padding='longest', max_length=512, return_tensors='pt')
|
22 |
+
inputs_batch = batch['input_ids'][0]
|
23 |
+
inputs_batch = torch.unsqueeze(inputs_batch, 0)
|
24 |
+
|
25 |
+
ques_id = model.generate(inputs_batch, max_length=100, early_stopping=True)
|
26 |
+
ques_batch = [tokenizer.decode(g, skip_special_tokens=True, clean_up_tokenization_spaces=False) for g in ques_id]
|
27 |
+
|
28 |
+
print(ques_batch)
|
29 |
+
```
|
30 |
+
|
31 |
+
Output:
|
32 |
+
```
|
33 |
+
['what is my name']
|
34 |
+
```
|