forked from yang-zhang/deep-learning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
number_parameters_rnn_lstm.py
64 lines (33 loc) · 951 Bytes
/
number_parameters_rnn_lstm.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
55
56
57
58
59
60
61
62
63
# coding: utf-8
# - https://datascience.stackexchange.com/questions/10615/number-of-parameters-in-an-lstm-model
# - https://github.com/fchollet/keras/blob/master/examples/lstm_text_generation.py
# In[1]:
import utilities
# In[2]:
maxlen_sentence = 43
num_chars = 57
# In[3]:
from keras.models import Sequential
from keras.layers import SimpleRNN, LSTM
units = 128
model = Sequential([
SimpleRNN(units, input_shape=(maxlen_sentence, num_chars)),
])
model.summary()
# In[4]:
utilities.print_weights_shape(model)
# In[5]:
assert units*units + units*(num_chars+1) == 23808
# In[6]:
from keras.models import Sequential
from keras.layers import LSTM
units = 128
model = Sequential([
LSTM(units, input_shape=(maxlen_sentence, num_chars)),
])
model.summary()
assert 4 * units * (units + (num_chars+1)) == 95232
# In[7]:
utilities.print_weights_shape(model)
# In[8]:
assert 4*units*units + 4*units*(num_chars + 1) == 95232