-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquantify.py
More file actions
26 lines (21 loc) · 753 Bytes
/
quantify.py
File metadata and controls
26 lines (21 loc) · 753 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import os
os.environ['TF_ENABLE_ONEDNN_OPTS'] = '0'
from tensorflow.keras.models import load_model
import pickle
from tensorflow.keras.preprocessing.sequence import pad_sequences
# Load the model
loaded_model = load_model('./model/knowledge_density.keras')
# Load the tokenizer
with open('model/tokenizer.pkl', 'rb') as file:
loaded_tokenizer = pickle.load(file)
def quantify(text):
new_seq = loaded_tokenizer.texts_to_sequences([text])
new_data = pad_sequences(new_seq, maxlen=1000)
prediction = loaded_model.predict(new_data, verbose=0)
predicted = prediction[0][0]
if predicted < 0:
predicted = 0
if predicted > 100:
predicted = 100
return predicted
print(quantify("The speed of light is 3km/s."))