Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lukas committed Nov 20, 2017
1 parent b372650 commit 91231da
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 19 deletions.
13 changes: 8 additions & 5 deletions keras-encoding/cnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,23 +73,26 @@
embedding_matrix[i] = embedding_vector

from keras.layers import Embedding, Input, Dense, Flatten, Conv1D
from keras.layers import MaxPooling1D
from keras.layers import MaxPooling1D, Dropout
from keras.models import Model

embedding_layer = Embedding(len(word_index) + 1,
embedding_dim,
weights=[embedding_matrix],
input_length=config.max_sequence_length,
trainable=True)
trainable=False)

sequence_input = Input(shape=(config.max_sequence_length,), dtype='int32')
embedded_sequences = embedding_layer(sequence_input)
x = Conv1D(128, 5, activation='relu')(embedded_sequences)
x = MaxPooling1D(5)(x)
x = Dropout(0.3)(embedded_sequences)
x = Conv1D(128, 5, activation='relu')(x)
x = MaxPooling1D(5)(x) # global max pooling
x = MaxPooling1D(5)(x)
x = Dropout(0.3)(x)
#x = Conv1D(128, 5, activation='relu')(x)
#x = MaxPooling1D(5)(x) # global max pooling
x = Flatten()(x)
x = Dense(128, activation='relu')(x)
x = Dropout(0.3)(x)
preds = Dense(num_labels, activation='softmax')(x)

model = Model(sequence_input, preds)
Expand Down
3 changes: 0 additions & 3 deletions keras-mlp/dropout.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,3 @@
# Fit the model
model.fit(X_train, y_train, validation_data=(X_test, y_test),
callbacks=[WandbKerasCallback()], epochs=config.epochs)

# Save the run
model.save(run.dir+'/two-layer.h5')
5 changes: 0 additions & 5 deletions keras-mlp/mlp.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@
# create model
model=Sequential()
model.add(Flatten(input_shape=(img_width,img_height)))
model.add(Dropout(0.4))
model.add(Dense(config.hidden_nodes, activation='relu'))
model.add(Dropout(0.4))
model.add(Dense(num_classes, activation='softmax'))
model.compile(loss='categorical_crossentropy', optimizer=config.optimizer,
metrics=['accuracy'])
Expand All @@ -41,6 +39,3 @@
# Fit the model
model.fit(X_train, y_train, validation_data=(X_test, y_test),
callbacks=[WandbKerasCallback()], epochs=config.epochs)

# Save the run
model.save(run.dir+'/two-layer.h5')
6 changes: 3 additions & 3 deletions keras-perceptron/perceptron.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
y_test = np_utils.to_categorical(y_test)

num_classes = y_train.shape[1]
print(y_train[1])

# create model
model=Sequential()
model.add(Flatten(input_shape=(img_width,img_height)))
model.add(Dense(num_classes, activation='softmax', kernel_initializer='zeros'))
model.add(Dense(num_classes, activation='softmax'))
model.compile(loss='categorical_crossentropy', optimizer='adam',
metrics=['accuracy'])

# Fit the model
model.fit(X_train, y_train, epochs=10, validation_data=(X_test, y_test),
batch_size=200,callbacks=[WandbKerasCallback()])
callbacks=[WandbKerasCallback()])
9 changes: 6 additions & 3 deletions movie-reviews-lstm/lstm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import numpy
from keras.datasets import imdb
from keras.models import Sequential
from keras.layers import Dense
from keras.layers import Dense, Conv1D, MaxPooling1D
from keras.layers import LSTM
from keras.layers.embeddings import Embedding
from keras.preprocessing import sequence
Expand All @@ -20,12 +20,15 @@
X_train = sequence.pad_sequences(X_train, maxlen=config.max_length)
X_test = sequence.pad_sequences(X_test, maxlen=config.max_length)
# create the model
embedding_vecor_length = 32
#embedding_vecor_length = 32
model = Sequential()
model.add(Embedding(config.num_words, config.embedding_vector_length, input_length=max_review_length))
model.add(Conv1D(32,3,activation='relu'))
model.add(MaxPooling1D(2))
model.add(LSTM(config.lstm_output_size))
model.add(Dense(1, activation='sigmoid'))
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
print(model.summary())
model.fit(X_train, y_train, epochs=config.epochs, batch_size=config.batch_size,
callbacks=[WandbKerasCallback()])
callbacks=[WandbKerasCallback()],
validation_data=(X_test, y_test))

0 comments on commit 91231da

Please sign in to comment.