-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
54 lines (41 loc) · 2.24 KB
/
models.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
from keras.models import Model, Sequential
from keras.layers import SimpleRNN, Dense, TimeDistributed, Dropout, LSTM, Embedding
from keras.optimizers import Adam
from keras.losses import sparse_categorical_crossentropy
def motor(input_shape,
dict_en_size,
dict_fr_size,
type_model,
length_vector_word,
n_neurons_rnn,
n_neurons_lstm,
n_neurons_timedistributed,
learning_rate):
model = Sequential()
if type_model == "Rnn":
model.add(SimpleRNN(n_neurons_rnn, input_shape=input_shape[1:], return_sequences=True))
model.add(TimeDistributed(Dense(n_neurons_timedistributed, activation='relu')))
model.add(Dropout(0.5))
model.add(TimeDistributed(Dense(dict_fr_size, activation='softmax')))
elif type_model == "Rnn_Embd":
model.add(Embedding(dict_en_size, length_vector_word, input_length=input_shape[1], input_shape=input_shape[1:]))
model.add(SimpleRNN(n_neurons_rnn, return_sequences=True))
model.add(TimeDistributed(Dense(n_neurons_timedistributed, activation='relu')))
model.add(Dropout(0.5))
model.add(TimeDistributed(Dense(dict_fr_size, activation='softmax')))
elif type_model == "Lstm":
model.add(LSTM(n_neurons_lstm, input_shape=input_shape[1:], return_sequences=True))
model.add(TimeDistributed(Dense(n_neurons_timedistributed, activation='relu')))
model.add(Dropout(0.5))
model.add(TimeDistributed(Dense(dict_fr_size, activation='softmax')))
elif type_model == "Lstm_Embd":
model.add(Embedding(dict_en_size, length_vector_word, input_length=input_shape[1], input_shape=input_shape[1:]))
model.add(LSTM(n_neurons_lstm, return_sequences=True))
model.add(TimeDistributed(Dense(n_neurons_timedistributed, activation='relu')))
model.add(Dropout(0.5))
model.add(TimeDistributed(Dense(dict_fr_size, activation='softmax')))
print(model.summary())
model.compile(loss=sparse_categorical_crossentropy,
optimizer=Adam(learning_rate),
metrics=['accuracy'])
return model