-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
36 lines (27 loc) · 803 Bytes
/
main.py
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
# Imports
import os;
import numpy as np;
import tensorflow as tf;
import pandas as pd;
import numpy as np;
import pickle;
from tensorflow import keras;
from keras.preprocessing.sequence import pad_sequences
from keras.preprocessing.text import Tokenizer;
# Variables
maxlen = 40;
# Creating Tokenizer
with open("tokenizer.pickle", "rb") as handle:
tokenizer = pickle.load(handle);
# Main
model = keras.models.load_model("model.h5");
seed = "Three guys walked into a bar".split();
for x in range(20):
raw = model.predict(pad_sequences(tokenizer.texts_to_sequences([seed]), maxlen=maxlen))
predict = np.argmax(raw[0]);
for i in tokenizer.word_index:
if (tokenizer.word_index[i] == predict):
predict = i;
break;
seed.append(predict);
print(seed)