-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path02_Test_the_model.py
More file actions
94 lines (66 loc) · 2.97 KB
/
02_Test_the_model.py
File metadata and controls
94 lines (66 loc) · 2.97 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# Import Dependencies
import tkinter
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import random
from keras.utils import to_categorical
from keras import models
from keras import layers
from keras.datasets import imdb
from data import encode_sentence
from keras.models import load_model
from keras.utils import to_categorical
from keras import models
from keras import layers
# Spliting data for test and training
(training_data, training_targets), (testing_data, testing_targets) = imdb.load_data(num_words=10000)
data = np.concatenate((training_data, testing_data), axis=0)
targets = np.concatenate((training_targets, testing_targets), axis=0)
## Verifiy the model
from tkinter import Tk, Label, Button, Message
class MyFirstGUI:
def __init__(self, master):
master.geometry("600x600")
self.master = master
master.title("Neural Network Lesson by Jair Ribeiro")
self.label = Label(master, text="Sentiment Analysis with Keras")
## self.label = Label(master, text="Current Model Accuracy: " + str(output) +" %")
self.label.pack()
# Checking the data
ReviewNumber= random.randint(1, 1000)
index = imdb.get_word_index()
reverse_index = dict([(value, key) for (key, value) in index.items()])
decoded = " ".join( [reverse_index.get(i - ReviewNumber, "#") for i in data[0]] )
self.label = Label(master, text="Analyzing randomly the Review n. " + str(ReviewNumber) + " from IMDB")
self.label.pack()
self.label = Label(master, text="Unknown words were replaced with #")
self.label.pack()
self.message = Message(master, text=" " + str(decoded))
self.message.pack()
# Exploring the data
self.label = Label(master, text="Exploring the data")
self.label.pack()
self.label = Label(master, text="Categories: " + str(np.unique(targets)))
self.label.pack()
Sentiment = "Positive" if targets[0] > 0 else "Negative"
self.label = Label(master, text="Sentiment Analysis: " + Sentiment + " (" + str(targets[0])+ ").")
self.label.pack()
self.label = Label(master, text="Analyzing the data.")
self.label.pack()
self.label = Label(master, text="Number of unique words: " + str(len(np.unique(np.hstack(data))))+".")
self.label.pack()
self.label = Label(master, text="Averages")
self.label.pack()
length = [len(i) for i in data]
self.label = Label(master, text="Average Review length: " + str("%6.0f" % np.mean(length))+" words.")
self.label.pack()
self.label = Label(master, text="Standard Deviation: " + str("%6.0f" % round(np.std(length)))+" words.")
self.label.pack()
### Close Button
self.close_button = Button(master, text="Close", command=master.quit)
self.close_button.pack()
root = Tk()
my_gui = MyFirstGUI(root)
root.mainloop()