-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpredictor.py
More file actions
49 lines (37 loc) · 1.2 KB
/
predictor.py
File metadata and controls
49 lines (37 loc) · 1.2 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Importing the Libraries
from tensorflow.keras.models import load_model
import numpy as np
import pickle
# Load the model and tokenizer
model = load_model('nextword1.h5')
tokenizer = pickle.load(open('tokenizer1.pkl', 'rb'))
def Predict_Next_Words(model, tokenizer, text):
for i in range(3):
sequence = tokenizer.texts_to_sequences([text])[0]
sequence = np.array(sequence)
preds = model.predict_classes(sequence)
# print(preds)
predicted_word = ""
for key, value in tokenizer.word_index.items():
if value == preds:
predicted_word = key
break
print(predicted_word)
return predicted_word
# text1 = "at the dull"
# text2 = "collection of textile"
# text3 = "what a strenuous"
# text4 = "stop the script"
while(True):
text = input("Enter your line: ")
if text == "stop the script":
print("Ending The Program.....")
break
else:
try:
text = text.split(" ")
text = text[-1]
text = ''.join(text)
Predict_Next_Words(model, tokenizer, text)
except:
continue