nomsgadded commited on
Commit
b0143d9
1 Parent(s): 69f9adf

Upload Inference_Restaurant_Review.py

Browse files
Files changed (1) hide show
  1. Inference_Restaurant_Review.py +32 -0
Inference_Restaurant_Review.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ Spyder Editor
4
+
5
+ This is a temporary script file.
6
+ """
7
+
8
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
9
+ import torch
10
+
11
+ tokenizer = AutoTokenizer.from_pretrained("nomsgadded/opt_RestaurantReview")
12
+
13
+ model = AutoModelForSequenceClassification.from_pretrained("nomsgadded/opt_RestaurantReview", num_labels=9)
14
+
15
+ prefix = "##Rating: "
16
+
17
+ text1 = "Bad"
18
+ text2 = "It was really nice to dine there, however the waiter is very mean."
19
+ text3 = "Nice"
20
+
21
+ def inference(text):
22
+ text = prefix + text
23
+ inputs = tokenizer(text, return_tensors="pt")
24
+ classifier = pipeline("text-classification", model=model, tokenizer=tokenizer)
25
+ with torch.no_grad():
26
+ logits = model(**inputs).logits
27
+ predicted_class_id = logits.argmax().item()
28
+ print(predicted_class_id)
29
+
30
+ inference(text1)
31
+ inference(text2)
32
+ inference(text3)