Views
No views yet
Title: {title}. Section: {section}. Content: {content}. The output of the model is a list of propositions in JSON format.Title: Leaning Tower of Pisa. Section: . Content: Prior to restoration work performed between 1990 and 2001, Leaning Tower of Pisa leaned at an angle of 5.5 degrees, but the tower now leans at about 3.99 degrees. This means the top of the tower is displaced horizontally 3.9 meters (12 ft 10 in) from the center.["Prior to restoration work performed between 1990 and 2001, Leaning Tower of Pisa leaned at an angle of 5.5 degrees.", "Leaning Tower of Pisa now leans at about 3.99 degrees.", "The top of Leaning Tower of Pisa is displaced horizontally 3.9 meters (12 ft 10 in) from the center."]1from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
2import torch
3import json
4
5model_name = "chentong00/propositionizer-wiki-flan-t5-large"
6device = "cuda" if torch.cuda.is_available() else "cpu"
7tokenizer = AutoTokenizer.from_pretrained(model_name)
8model = AutoModelForSeq2SeqLM.from_pretrained(model_name).to(device)
9
10title = "Leaning Tower of Pisa"
11section = ""
12content = "Prior to restoration work performed between 1990 and 2001, Leaning Tower of Pisa leaned at an angle of 5.5 degrees, but the tower now leans at about 3.99 degrees. This means the top of the tower is displaced horizontally 3.9 meters (12 ft 10 in) from the center."
13
14input_text = f"Title: {title}. Section: {section}. Content: {content}"
15
16input_ids = tokenizer(input_text, return_tensors="pt").input_ids
17outputs = model.generate(input_ids.to(device), max_new_tokens=512).cpu()
18
19output_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
20try:
21 prop_list = json.loads(output_text)
22except:
23 prop_list = []
24 print("[ERROR] Failed to parse output text as JSON.")
25print(json.dumps(prop_list, indent=2))1[
2 "Prior to restoration work performed between 1990 and 2001, Leaning Tower of Pisa leaned at an angle of 5.5 degrees.",
3 "Leaning Tower of Pisa now leans at about 3.99 degrees.",
4 "The top of Leaning Tower of Pisa is displaced horizontally 3.9 meters (12 ft 10 in) from the center."
5]1@article{chen2023densex,
2 title={Dense X Retrieval: What Retrieval Granularity Should We Use?},
3 author={Tong Chen and Hongwei Wang and Sihao Chen and Wenhao Yu and Kaixin Ma and Xinran Zhao and Hongming Zhang and Dong Yu},
4 journal={arXiv preprint arXiv:2312.06648},
5 year={2023},
6 URL = {https://arxiv.org/pdf/2312.06648.pdf}
7}