-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodels.py
More file actions
102 lines (94 loc) · 3.85 KB
/
Copy pathmodels.py
File metadata and controls
102 lines (94 loc) · 3.85 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
from keras.models import Sequential
from keras.layers import Dense
from keras.layers import LSTM
from keras.layers import Activation
from keras.layers import Bidirectional
from keras.layers import Dropout
def nn_01(network_input, num_pitches):
""" Super basic neural network for text generation taken from
https://keras.io/examples/lstm_text_generation/ """
model = Sequential()
model.add(LSTM(128, input_shape=(network_input.shape[1], network_input.shape[2])))
model.add(Dense(num_pitches))
model.add(Activation('softmax'))
model.compile(loss='categorical_crossentropy', optimizer='rmsprop')
return model
def nn_02(network_input, num_pitches):
""" Double the number of LSTM cells as nn_01 """
model = Sequential()
model.add(LSTM(256, input_shape=(network_input.shape[1], network_input.shape[2])))
model.add(Dense(num_pitches))
model.add(Activation('softmax'))
model.compile(loss='categorical_crossentropy', optimizer='rmsprop')
return model
def nn_03(network_input, num_pitches):
""" 2 Stacked LSTMs """
model = Sequential()
model.add(LSTM(256, input_shape=(network_input.shape[1], network_input.shape[2]), return_sequences=True))
model.add(LSTM(256))
model.add(Dense(num_pitches))
model.add(Activation('softmax'))
model.compile(loss='categorical_crossentropy', optimizer='rmsprop')
return model
def nn_04(network_input, num_pitches):
""" 2 Stacked LSTMs with dropout in between """
model = Sequential()
model.add(LSTM(256, input_shape=(network_input.shape[1], network_input.shape[2]), return_sequences=True))
model.add(Dropout(0.3))
model.add(LSTM(256))
model.add(Dense(num_pitches))
model.add(Activation('softmax'))
model.compile(loss='categorical_crossentropy', optimizer='rmsprop')
return model
def nn_04_1(network_input, num_pitches):
""" 2 Stacked LSTMs with dropout at end """
model = Sequential()
model.add(LSTM(256, input_shape=(network_input.shape[1], network_input.shape[2]), return_sequences=True))
model.add(LSTM(256))
model.add(Dropout(0.3))
model.add(Dense(num_pitches))
model.add(Activation('softmax'))
model.compile(loss='categorical_crossentropy', optimizer='rmsprop')
return model
def nn_05(network_input, num_pitches):
""" 3 Stacked LSTM-256s with dropouts """
model = Sequential()
model.add(LSTM(256, input_shape=(network_input.shape[1], network_input.shape[2]), return_sequences=True))
model.add(Dropout(0.3))
model.add(LSTM(256, return_sequences=True))
model.add(Dropout(0.25))
model.add(LSTM(256))
model.add(Dense(num_pitches))
model.add(Dropout(0.2))
model.add(Activation('softmax'))
model.compile(loss='categorical_crossentropy', optimizer='rmsprop')
return model
def nn_05_1(network_input, num_pitches):
""" 3 Stacked LSTM-512s with dropouts """
model = Sequential()
model.add(LSTM(512, input_shape=(network_input.shape[1], network_input.shape[2]), return_sequences=True))
model.add(Dropout(0.3))
model.add(LSTM(512, return_sequences=True))
model.add(Dropout(0.25))
model.add(LSTM(512))
model.add(Dense(num_pitches))
model.add(Dropout(0.2))
model.add(Activation('softmax'))
model.compile(loss='categorical_crossentropy', optimizer='rmsprop')
return model
def nn_06(network_input, num_pitches):
""" LSTM with BiDirectional LSTMs """
model = Sequential()
model.add(LSTM(
256,
input_shape=(network_input.shape[1], network_input.shape[2]), return_sequences=True)
)
model.add(Dropout(0.3))
model.add(Bidirectional(LSTM(256, return_sequences=True)))
model.add(Dropout(0.25))
model.add(Bidirectional(LSTM(256)))
model.add(Dense(num_pitches))
model.add(Dropout(0.2))
model.add(Activation('softmax'))
model.compile(loss='categorical_crossentropy', optimizer='rmsprop')
return model