-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtesttweet2.py
22 lines (19 loc) · 849 Bytes
/
testtweet2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import pickle
from tensorflow.python.keras.preprocessing.text import Tokenizer
from tensorflow.python.keras.preprocessing.sequence import pad_sequences
from keras.models import Sequential
from keras.layers import Dense, Embedding, LSTM, GRU
from keras.layers.embeddings import Embedding
import pandas as pd
import pickle
import numpy as np
from keras.models import load_model
mod1 = load_model('RNN_LSTM.h5')
tkobj = pickle.load(open('TOkenizer.pkl','rb'))
pred_map = {0:'Hate',1:'Offensive',2:'Neither'}
it = input('Text for RNN Model: ')
X_train_tkns = tkobj.texts_to_sequences([it])
X_train_pad = pad_sequences(X_train_tkns, maxlen=25, padding = 'post')
pred = mod1.predict(X_train_pad)
result = np.where(pred.flatten() == np.amax(pred))
print('The tweet ', it ,'is classified as', pred_map[np.where(pred.flatten() == np.amax(pred))[0][0]])