-
Notifications
You must be signed in to change notification settings - Fork 0
/
RNN_model.py
26 lines (19 loc) · 924 Bytes
/
RNN_model.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
# https://github.com/Eligijus112/twitter-genuine-tweets/blob/master/RNN_model.py
# Deep learning:
from tensorflow.keras import Input, Model
from tensorflow.keras.layers import LSTM, Dense, Embedding, Dropout
class RnnModel():
"""
A recurrent neural network for semantic analysis
"""
def __init__(self, embedding_matrix, embedding_dim, max_len, X_additional=None):
inp1 = Input(shape=(max_len,))
x = Embedding(embedding_matrix.shape[0], embedding_dim, weights=[embedding_matrix])(inp1)
x = LSTM(256, return_sequences=True)(x)
x = LSTM(128)(x)
x = Dropout(0.1)(x)
x = Dense(64, activation="relu")(x)
x = Dense(1, activation="sigmoid")(x)
model = Model(inputs=inp1, outputs=x)
model.compile(loss = 'binary_crossentropy', optimizer = 'adam', metrics=['accuracy'])
self.model = model