Views
No views yet
1from typing import List, Tuple
2from transformers import pipeline
3
4
5def prepare_text(triplets: List[Tuple[str, str, str]]):
6 graph = "[graph]"
7 for triplet in triplets:
8 graph += f"[head] {triplet[0]} [relation] {triplet[1]} [tail] {triplet[2]} "
9 graph += "[text]</s>"
10 return graph
11
12
13g2t_model = pipeline(task="text2text-generation", model="s-nlp/g2t-t5-xl-webnlg")
14
15
16graph = prepare_text([
17 ("London", "capital_of", "United Kingdom"),
18 ("London", "population", "8,799,728")
19])
20g2t_model(graph)
21# [{'generated_text': 'London is the capital of the United Kingdom and has a population of 8,799,7'}]