File size: 1,436 Bytes
4cba82b
 
 
 
 
 
 
 
 
 
 
 
 
 
9574c5d
 
 
a9132bf
9574c5d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4cba82b
 
 
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
---
license: openrail
datasets:
- web_questions
language:
- en
metrics:
- bleu
- bertscore
library_name: transformers
tags:
- knowledge_graphs
- question_generation
---
T5-base model fine-tuned for question generation from knowledge graphs. Can be used to generate questions from linearized knowledge graphs, meaning graphs in the form of its all its triples listed in the following format:

`<A> answer node(s) <H> head <R> relation <T> tail <H> head <R> relation <T> tail ... etc ...`,
where `answer node(s)` refers to the node(s) which should contain the answer to the generated question.


To load the model:

```
from transformers import T5ForConditionalGeneration, T5TokenizerFast
model = T5ForConditionalGeneration.from_pretrained('stanlochten/t5-KGQgen')
tokenizer = T5TokenizerFast.from_pretrained('t5-base',  extra_ids=0, 
            additional_special_tokens = ['<A>', '<H>', '<R>', '<T>'])
```

To generate questions from your graphs, where `graphs` is a list of strings for each graph:
```
print('Tokenizing...')
inputs = tokenizer(graphs, return_tensors="pt", padding=True, truncation=True)
print('Predicting...')
y_hats = model.generate(inputs.input_ids)
print('Decoding...')
preds = tokenizer.batch_decode(y_hats, skip_special_tokens=True, clean_up_tokenization_spaces=True)
```

Good luck!

[Associated research report](https://dspace.uba.uva.nl/server/api/core/bitstreams/fee95174-b7d4-4cd8-8545-f7ec8ab29e2d/content)