Views
No views yet
1from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
2
3model_checkpoint = "InfAI/flan-t5-text2sparql-custom-tokenizer"
4question = "What was the population of Clermont-Ferrand on 1-1-2013?"
5gold_answer = "SELECT ?obj WHERE { wd:Q42168 p:P1082 ?s . ?s ps:P1082 ?obj . ?s pq:P585 ?x filter(contains(YEAR(?x),'2013')) }"
6
7model = AutoModelForSeq2SeqLM.from_pretrained(model_checkpoint)
8
9tokenizer_in = AutoTokenizer.from_pretrained("google/flan-t5-base")
10tokenizer_out = AutoTokenizer.from_pretrained("InfAI/sparql-tokenizer")
11
12sample = f"Create SPARQL Query: {question}"
13
14inputs = tokenizer_in([sample], return_tensors="pt")
15outputs = model.generate(**inputs)
16
17print(f"Gold answer: {gold_answer}")
18print(" Model:" + tokenizer_out.decode(outputs[0], skip_special_tokens=True))Gold answer: SELECT ?obj WHERE { wd:Q42168 p:P1082 ?s . ?s ps:P1082 ?obj . ?s pq:P585 ?x filter(contains(YEAR(?x),'2013'))
Model: SELECT?obj WHERE { wd:Q4754 p:P1082?s.?s ps:P1082?obj.?s pq:P585?x filter(contains(YEAR(?x),'2013')) }| Training Loss | Epoch | Step | Validation Loss |
|---|---|---|---|
| No log | 1.0 | 301 | 2.6503 |
| 3.2271 | 2.0 | 602 | 2.3894 |
| 3.2271 | 3.0 | 903 | 2.2532 |
| 2.3957 | 4.0 | 1204 | 2.1631 |
| 2.18 | 5.0 | 1505 | 2.0788 |
| 2.18 | 6.0 | 1806 | 2.0195 |
| 2.0209 | 7.0 | 2107 | 1.9681 |
| 2.0209 | 8.0 | 2408 | 1.9353 |
| 1.9087 | 9.0 | 2709 | 1.8936 |
| 1.8114 | 10.0 | 3010 | 1.8683 |
| 1.8114 | 11.0 | 3311 | 1.8556 |
| 1.7254 | 12.0 | 3612 | 1.8284 |
| 1.7254 | 13.0 | 3913 | 1.8099 |
| 1.6556 | 14.0 | 4214 | 1.7932 |
| 1.5891 | 15.0 | 4515 | 1.7823 |
| 1.5891 | 16.0 | 4816 | 1.7691 |
| 1.528 | 17.0 | 5117 | 1.7569 |
| 1.528 | 18.0 | 5418 | 1.7578 |
| 1.4784 | 19.0 | 5719 | 1.7561 |
| 1.4288 | 20.0 | 6020 | 1.7514 |
| 1.4288 | 21.0 | 6321 | 1.7372 |
| 1.3793 | 22.0 | 6622 | 1.7318 |
| 1.3793 | 23.0 | 6923 | 1.7244 |
| 1.3436 | 24.0 | 7224 | 1.7382 |
| 1.3073 | 25.0 | 7525 | 1.7254 |
| 1.3073 | 26.0 | 7826 | 1.7494 |
| 1.2692 | 27.0 | 8127 | 1.7378 |
| 1.2692 | 28.0 | 8428 | 1.7387 |
| 1.242 | 29.0 | 8729 | 1.7290 |
| 1.2107 | 30.0 | 9030 | 1.7391 |
| 1.2107 | 31.0 | 9331 | 1.7458 |
| 1.1817 | 32.0 | 9632 | 1.7528 |
| 1.1817 | 33.0 | 9933 | 1.7521 |
| 1.1661 | 34.0 | 10234 | 1.7672 |
| 1.136 | 35.0 | 10535 | 1.7594 |
| 1.136 | 36.0 | 10836 | 1.7564 |
| 1.1216 | 37.0 | 11137 | 1.7670 |
| 1.1216 | 38.0 | 11438 | 1.7724 |
| 1.1031 | 39.0 | 11739 | 1.7766 |
| 1.0834 | 40.0 | 12040 | 1.7756 |
| 1.0834 | 41.0 | 12341 | 1.7786 |
| 1.0707 | 42.0 | 12642 | 1.7947 |
| 1.0707 | 43.0 | 12943 | 1.7931 |
| 1.058 | 44.0 | 13244 | 1.7925 |
| 1.0489 | 45.0 | 13545 | 1.7939 |
| 1.0489 | 46.0 | 13846 | 1.7969 |
| 1.0421 | 47.0 | 14147 | 1.7982 |
| 1.0421 | 48.0 | 14448 | 1.7994 |
| 1.0357 | 49.0 | 14749 | 1.8018 |
| 1.03 | 50.0 | 15050 | 1.8039 |