stanlochten
commited on
Commit
•
9574c5d
1
Parent(s):
eb70544
Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
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:
|
2 |
+
|
3 |
+
`<A> answer node(s) <H> head <R> relation <T> tail <H> head <R> relation <T> tail ... etc ...`,
|
4 |
+
where `answer node(s)` refers to the node which should contain the answer of to the generated question.
|
5 |
+
|
6 |
+
|
7 |
+
To load the model:
|
8 |
+
|
9 |
+
```
|
10 |
+
from transformers import T5ForConditionalGeneration, T5TokenizerFast
|
11 |
+
model = T5ForConditionalGeneration.from_pretrained('stanlochten/t5-KGQgen')
|
12 |
+
tokenizer = T5TokenizerFast.from_pretrained('t5-base', extra_ids=0,
|
13 |
+
additional_special_tokens = ['<A>', '<H>', '<R>', '<T>'])
|
14 |
+
```
|
15 |
+
|
16 |
+
To generate questions from your graphs, where `graphs` is a list of strings for each graph:
|
17 |
+
```
|
18 |
+
print('Tokenizing...')
|
19 |
+
inputs = tokenizer(graphs, return_tensors="pt", padding=True, truncation=True)
|
20 |
+
print('Predicting...')
|
21 |
+
y_hats = model.generate(inputs.input_ids)
|
22 |
+
print('Decoding...')
|
23 |
+
preds = tokenizer.batch_decode(y_hats, skip_special_tokens=True, clean_up_tokenization_spaces=True)
|
24 |
+
```
|
25 |
+
|
26 |
+
Good luck!
|