Views
No views yet
1import json
2import torch
3from transformers import AutoTokenizer
4from transformers import AutoModelForCausalLM
5from datetime import datetime
6from transformers import T5Tokenizer, T5ForConditionalGeneration
7
8tokenizer = T5Tokenizer.from_pretrained("google/flan-t5-xl")
9model_id = "Sefika/semeval_base_1"
10model = T5ForConditionalGeneration.from_pretrained(model_id,
11 device_map="auto",
12 load_in_8bit=False,
13 torch_dtype=torch.float16)
14prompt = """Example Sentence:The purpose of the <e1>audit</e1> was to report on the <e2>financial statements</e2>.\n"""+\
15 """Sentence: Query Sentence:The most common <e1>audits</e1> were about <e2>waste</e2> and recycling.\n"""+\
16 """What is the relation type between e1: audits. and e2 : waste. according to given relation types below in the sentence?\n"""+\
17 """Relation types: Relation types: Cause-Effect(e2,e1), Content-Container(e1,e2), Member-Collection(e1,e2), Instrument-Agency(e1,e2), Product-Producer(e2,e1), Member-Collection(e2,e1), Message-Topic(e1,e2), Entity-Origin(e2,e1), Message-Topic(e2,e1), Instrument-Agency(e2,e1), Content-Container(e2,e1), Product-Producer(e1,e2), Entity-Origin(e1,e2), Component-Whole(e1,e2), Entity-Destination(e1,e2), Other, Cause-Effect(e1,e2), Component-Whole(e2,e1), Entity-Destination(e2,e1). \n"""
18inputs = self.tokenizer(prompt, add_special_tokens=True, max_length=526,return_tensors="pt").input_ids.to("cuda")
19
20outputs = self.model.generate(inputs, max_new_tokens=length, pad_token_id=self.tokenizer.eos_token_id)
21
22response = self.tokenizer.batch_decode(outputs, skip_special_tokens=True)
23print(response[0])
24#"Cause-Effect(e1,e2)"
25