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
decoded_imgs_test_32, x_test_32 = plot_mnist_predict(x_test, | |
x_test_noisy, | |
autoencoder_32, | |
y_test, | |
labels=[3, 6, 8]) |
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
from keras import models | |
from keras import layers | |
from keras.applications import VGG16 | |
conv_base = VGG16(weights='imagenet', | |
include_top=False, | |
input_shape=(150, 150, 3)) | |
train_features = conv_base.predict(inputs) |
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
import tensorflow as tf | |
# defining the graph | |
a = tf.constant([5,3], name="input_a") | |
b = tf.reduce_prod(a, name="prod_b") | |
c = tf.reduce_sum(a, name="sum_c") | |
d = tf.add(b,c, name="add_d") | |
# running the graph | |
sess = tf.Session() |
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
import numpy as np | |
from keras.datasets import imdb | |
from keras.preprocessing import sequence | |
# number of distinct words | |
vocabulary_size = 10000 | |
# number of words per review | |
max_review_length = 500 |
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
# A dictionary mapping words to an integer index | |
word_index = imdb.get_word_index() | |
# The first indices are reserved | |
word_index = {k:(v+3) for k,v in word_index.items()} | |
word_index["<PAD>"] = 0 | |
word_index["<START>"] = 1 | |
word_index["<UNK>"] = 2 # unknown | |
word_index["<UNUSED>"] = 3 | |
reverse_word_index = dict([(value, key) for (key, value) in word_index.items()]) | |
# display review |
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
from keras.models import Sequential | |
from keras.layers import Dense, LSTM, SimpleRNN, Flatten | |
from keras.layers.embeddings import Embedding | |
from keras.layers.convolutional import Conv1D, MaxPooling1D | |
import pandas as pd | |
# Fully connected neural network | |
model_ffn = Sequential() | |
model_ffn.add(Dense(250, activation='relu',input_dim=max_review_length)) | |
model_ffn.add(Dense(1, activation='sigmoid')) |
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
def movie_sentiment(reviews, | |
models=[model_ffn, model_ffne, model_cnn, model_rnn, model_cnn_rnn], | |
titles=['FFN', 'FFNE', 'CNN', 'RNN', 'CNN+RNN']): | |
df = pd.DataFrame(columns=['review']+titles) | |
i =0 | |
for review in reviews: | |
words = set(text_to_word_sequence(review)) | |
words = [word_index[w] for w in words] | |
words = sequence.pad_sequences([words], maxlen=max_review_length) | |
df.loc[i] = [review] + titles |
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
import pandas as pd | |
import numpy as np | |
# load English-Yemba dictionary as CSV file | |
df = pd.read_csv('https://gist.githubusercontent.com/michelkana/37ccb5c68b3c72148c2b490c917b13aa/raw/9badee0c1811fa03e8b981763e51ddc8ee56513b/english_yemba_dictionary.csv') | |
# display few words pairs | |
df.sample(frac=.1).head(15) |
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
max_word_len = df.yb.str.len().max() | |
max_word_len_utf8 = df.yb_utf8.str.len().max() | |
nb_labels = len(df.word_type.unique()) | |
nb_words = df.shape[0] | |
print("Number of words: ", nb_words) | |
print("Number of labels: ", nb_labels) | |
print("Max word length: {} characters and {} bytes".format(max_word_len, max_word_len_utf8)) |
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
# Create letter to token dictionary | |
chars = sorted(list(set(' '.join(df.yb)))) | |
letter2idx = dict((c, i+1) for i, c in enumerate(chars)) | |
# Create token to letter dictionary | |
idx2letter = dict((i, c) for c, i in letter2idx.items()) | |
vocabulary_size = len(letter2idx)+1 | |
print("Vocabulary size: ", vocabulary_size) |