-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsimple_model.py
27 lines (21 loc) · 913 Bytes
/
simple_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
27
from keras.layers.embeddings import Embedding
from keras.models import Sequential
from keras.layers import Dense
from keras.layers import GlobalAveragePooling1D, GlobalMaxPooling1D
class SimpleModel(object):
def __init__(self):
self.model = None
def build(self, embedding_matrix, max_features=20000, maxlen=500, embedding_dims=100):
model = Sequential()
print(embedding_matrix)
model.add(Embedding(max_features,
embedding_dims,
weights=[embedding_matrix],
input_length=maxlen,
trainable=True))
model.add(GlobalAveragePooling1D())
model.add(Dense(1, activation='sigmoid'))
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
print(model.summary())
self.model = model
return self