Last active
June 27, 2018 19:58
-
-
Save ravishchawla/486dd44dd8c88f77fca7de894437071a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
embeddings_index = dict(); | |
with open('data/glove.6B.100d.txt') as f: | |
for line in f: | |
values = line.split(); | |
word = values[0]; | |
coefs = np.asarray(values[1:], dtype='float32'); | |
embeddings_index[word] = coefs; | |
vocab_size = len(sequence_dict); | |
embeddings_matrix = np.zeros((vocab_size, 100)); | |
for word, i in sequence_dict.items(): | |
embedding_vector = embeddings_index.get(word); | |
if embedding_vector is not None: | |
embeddings_matrix[i] = embedding_vector; | |
max_cap = 100; | |
#Re-generate reviews_encoded, X, and Y after changing max_cap | |
model = Sequential(); | |
model.add(Embedding(len(word_dict), max_cap, input_length=max_cap, weights=[embeddings_matrix], trainable=False)); | |
model.add(LSTM(60, return_sequences=True, recurrent_dropout=0.5)); | |
model.add(Dropout(0.5)) | |
model.add(LSTM(60, recurrent_dropout=0.5)); | |
model.add(Dense(60, activation='relu')); | |
model.add(Dense(2, activation='softmax')); | |
print(model.summary()); | |
optimizer = Adam(lr=0.01, decay=0.001); | |
model.compile(loss='binary_crossentropy', optimizer=optimizer, metrics=['accuracy']) | |
# fit model | |
model.fit(X_train, Y_train, batch_size=64, epochs=10, validation_data=(X_dev, Y_dev)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment