Spaces:
Sleeping
Sleeping
Merge branch 'main' of https://huggingface.co/spaces/Homeskills/InstructABSA-ft
Browse files- lambda_function.py +0 -42
- simple_inference.py +0 -29
lambda_function.py
DELETED
@@ -1,42 +0,0 @@
|
|
1 |
-
from InstructABSA.utils import T5Generator
|
2 |
-
|
3 |
-
print('Mode set to: Individual sample inference')
|
4 |
-
|
5 |
-
|
6 |
-
# Create T5 model object along with instructions (taken from `instructions.py`)
|
7 |
-
model_checkpoint = "./Models/joint_task/kevinscariajoint_tk-instruct-base-def-pos-neg-neut-combined-robs_experiment"
|
8 |
-
t5_exp = T5Generator(model_checkpoint)
|
9 |
-
print("Model loaded from: ", model_checkpoint)
|
10 |
-
bos_instruction_id = """Definition: The output will be the aspects (both implicit and explicit) and the aspect's sentiment polarity. In cases where there are no aspects the output should be noaspectterm:none.
|
11 |
-
Positive example 1-
|
12 |
-
input: With the great variety on the menu , I eat here often and never get bored.
|
13 |
-
output: menu:positive
|
14 |
-
Positive example 2-
|
15 |
-
input: Great food, good size menu, great service and an unpretentious setting.
|
16 |
-
output: food:positive, menu:positive, service:positive, setting:positive
|
17 |
-
Negative example 1-
|
18 |
-
input: They did not have mayonnaise, forgot our toast, left out ingredients (ie cheese in an omelet), below hot temperatures and the bacon was so over cooked it crumbled on the plate when you touched it.
|
19 |
-
output: toast:negative, mayonnaise:negative, bacon:negative, ingredients:negative, plate:negative
|
20 |
-
Negative example 2-
|
21 |
-
input: The seats are uncomfortable if you are sitting against the wall on wooden benches.
|
22 |
-
output: seats:negative
|
23 |
-
Neutral example 1-
|
24 |
-
input: I asked for seltzer with lime, no ice.
|
25 |
-
output: seltzer with lime:neutral
|
26 |
-
Neutral example 2-
|
27 |
-
input: They wouldn't even let me finish my glass of wine before offering another.
|
28 |
-
output: glass of wine:neutral
|
29 |
-
Now complete the following example-
|
30 |
-
input: """
|
31 |
-
eos_instruction = ' \noutput:'
|
32 |
-
|
33 |
-
# Get input from user
|
34 |
-
user_input = input("Enter sentence for inference: ")
|
35 |
-
# format and tokenize input
|
36 |
-
model_input = bos_instruction_id + user_input + eos_instruction
|
37 |
-
input_ids = t5_exp.tokenizer(model_input, return_tensors="pt").input_ids
|
38 |
-
# generate output
|
39 |
-
outputs = t5_exp.model.generate(input_ids, max_length=128)
|
40 |
-
# decode output and print
|
41 |
-
print('Model output: ', t5_exp.tokenizer.decode(outputs[0], skip_special_tokens=True))
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|