-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolve.py
66 lines (43 loc) · 1.24 KB
/
solve.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
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
import pandas as pd
from preprocess import load_data_set, get_encoder, filter_string
from train import forward
import numpy as np
def load_weights():
W = pd.read_csv("results/best_weights.csv", header=None)
W = W.as_matrix()
return W
def load_bias():
b = pd.read_csv("results/bias.csv", header=None)
b = b.as_matrix()
return b
def encoder():
return get_encoder(load_data_set()[0])
np.set_printoptions(threshold=np.nan)
def get_encoded_data(string, encoder):
string = filter_string(string)
data = encoder.transform([string]).toarray()
return data
def get_sentiment(word):
x = get_encoded_data(word, enc)
sentiment = forward(x, W, bias)
print(sentiment)
return sentiment[0][0]
def resolve_sentiment(sentiment):
result = "Neutral"
if sentiment < 0.3:
result = "Negative"
if sentiment > 0.7:
result = "Positive",
return result
from tools import serialize, deserialize
def start_solver():
global W, bias, enc
W = load_weights()
bias = load_bias()
enc = deserialize("encoder")
# enc = encoder()
while True:
print("Paste comment")
string = input()
result = get_sentiment(string)
print(resolve_sentiment(result))