BilalHasan
commited on
Commit
•
d620d23
1
Parent(s):
046f45a
Create inference.py
Browse files- inference.py +31 -0
inference.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import tensorflow as tf
|
2 |
+
from tensorflow.keras.models import load_model
|
3 |
+
import json
|
4 |
+
import keras_nlp
|
5 |
+
|
6 |
+
fnet_classifier = load_model("Sentiments classifier.keras")
|
7 |
+
|
8 |
+
review_example = input("Input your review: ")
|
9 |
+
|
10 |
+
with open("vocab.json", "r") as f:
|
11 |
+
vocab = json.load(f)
|
12 |
+
|
13 |
+
seq_max_length = 512
|
14 |
+
tokenizer = keras_nlp.tokenizers.WordPieceTokenizer(
|
15 |
+
vocabulary=vocab,
|
16 |
+
lowercase=False,
|
17 |
+
sequence_length=seq_max_length,
|
18 |
+
)
|
19 |
+
|
20 |
+
def make_prediction(sentence):
|
21 |
+
tokens = tokenizer(review_example)
|
22 |
+
tokens = tf.expand_dims(tokens, 0)
|
23 |
+
prediction = fnet_classifier.predict(tokens, verbose=0)
|
24 |
+
|
25 |
+
if prediction[0][0] > 0.5:
|
26 |
+
result = "The review is POSITIVE"
|
27 |
+
else:
|
28 |
+
result = "The review is NEGATIVE"
|
29 |
+
return result
|
30 |
+
result = make_prediction(review_example)
|
31 |
+
print(result)
|