This file contains 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
def insertion_sort(array): | |
for i in range(1, len(array)): | |
data = array[i] | |
j = i | |
while j > 0 and array[j-1] > data: | |
array[j] = array[j - 1] | |
j -= 1 | |
array[j] = data | |
return array |
This file contains 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
/* | |
* A Java Script containing methods to manipulate a MongoDB | |
* Biney Kingsley - 07-04-2019 | |
* | |
* */ | |
package com.mongo; | |
import org.bson.Document; |
This file contains 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
def score_review(source=None, file_type=None): | |
''' | |
source: the text, as either a string or a list of strings | |
file_type: (str): indicating whether we expecting a file containing the | |
text data or a directory containing a list files holding the text | |
options: 'file' or 'dir' | |
''' | |
text_list = list() | |
if isinstance(source, str) and file_type is None: | |
text_list.append(source) |
This file contains 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
def decode_review(text_list): | |
word_index = tokenizer.word_index | |
sequences = tokenizer.texts_to_sequences(text_list) | |
data = pad_sequences(sequences, maxlen=500) | |
# decode the words | |
reverse_word_index = dict([(value, key) for (key, value) in word_index.items()]) | |
decoded_review = ' '.join([reverse_word_index.get(i, '?') for i in sequences[0]]) | |
return decoded_review, data |
This file contains 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
def review_rating(score, decoded_review): | |
if float(score) >= 0.9: | |
print('Review: {}\nSentiment: Strongly Positive\nScore: {}'.format(decoded_review, score)) | |
elif float(score) >= 0.7 and float(score) < 0.9: | |
print('Review: {}\nSentiment: Positive\nScore: {}'.format(decoded_review, score)) | |
elif float(score) >= 0.5 and float(score) < 0.7: | |
print('Review: {}\nSentiment: Okay\nScore: {}'.format(decoded_review, score)) | |
else: | |
print('Review: {}\nSentiment: Negative\nScore: {}'.format(decoded_review, score)) | |
print('\n\n') |
This file contains 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
tokenizer_path = 'tokenizer' | |
model_path = 'model' | |
model_file = os.path.join(model_path, 'movie_sentiment_m1.h5') | |
tokenizer_file = os.path.join(tokenizer_path, 'tokenizer_m1.pickle') | |
model = load_model(model_file) | |
# load tokenizer | |
with open(tokenizer_file, 'rb') as handle: | |
tokenizer = pickle.load(handle) |
This file contains 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
# save the tokenizer | |
with open(os.path.join(tokenizer_path, 'tokenizer_m1.pickle'), 'wb') as handle: | |
pk.dump(tokenizer, handle, protocol=pk.HIGHEST_PROTOCOL) |
This file contains 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
callback_list = [ | |
keras.callbacks.EarlyStopping( | |
patience=1, | |
monitor='acc', | |
), | |
keras.callbacks.TensorBoard( | |
log_dir='log_dir_m1', | |
histogram_freq=1, | |
embeddings_freq=1, |
This file contains 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
history = model.fit(x_train, y_train, epochs=50, batch_size=128, callbacks=callback_list, | |
validation_data=(x_val, y_val)) |
This file contains 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
# model developing | |
text_input_layer = Input(shape=(500,)) | |
embedding_layer = Embedding(max_words, 50)(text_input_layer) | |
text_layer = Conv1D(256, 3, activation='relu')(embedding_layer) | |
text_layer = MaxPooling1D(3)(text_layer) | |
text_layer = Conv1D(256, 3, activation='relu')(text_layer) | |
text_layer = MaxPooling1D(3)(text_layer) | |
text_layer = Conv1D(256, 3, activation='relu')(text_layer) | |
text_layer = MaxPooling1D(3)(text_layer) | |
text_layer = Conv1D(256, 3, activation='relu')(text_layer) |
NewerOlder