Spaces:
Sleeping
Sleeping
Delete simple_inference.py
Browse files- simple_inference.py +0 -29
simple_inference.py
DELETED
@@ -1,29 +0,0 @@
|
|
1 |
-
from InstructABSA.utils import T5Generator
|
2 |
-
from instructions import InstructionsHandler
|
3 |
-
|
4 |
-
# Set Global Values
|
5 |
-
instruct_handler = InstructionsHandler()
|
6 |
-
|
7 |
-
# Load instruction set 2 for ASPE
|
8 |
-
instruct_handler.load_instruction_set2()
|
9 |
-
|
10 |
-
print('Mode set to: Individual sample inference')
|
11 |
-
|
12 |
-
|
13 |
-
# Create T5 model object
|
14 |
-
model_checkpoint = "./Models/joint_task/kevinscariajoint_tk-instruct-base-def-pos-neg-neut-combined-robs_experiment"
|
15 |
-
t5_exp = T5Generator(model_checkpoint)
|
16 |
-
print("Model loaded from: ", model_checkpoint)
|
17 |
-
bos_instruction_id = instruct_handler.aspe['bos_instruct2']
|
18 |
-
eos_instruction = instruct_handler.aspe['eos_instruct']
|
19 |
-
|
20 |
-
# Get input from user
|
21 |
-
user_input = input("Enter sentence for inference: ")
|
22 |
-
# format and tokenize input
|
23 |
-
model_input = bos_instruction_id + user_input + eos_instruction
|
24 |
-
input_ids = t5_exp.tokenizer(model_input, return_tensors="pt").input_ids
|
25 |
-
# generate output
|
26 |
-
outputs = t5_exp.model.generate(input_ids, max_length=128)
|
27 |
-
# decode output and print
|
28 |
-
print('Model output: ', t5_exp.tokenizer.decode(outputs[0], skip_special_tokens=True))
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|