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
import numpy as np | |
class Embeddings(): | |
""" | |
A class to read the word embedding file and to create the word embedding matrix | |
""" | |
def __init__(self, path, vector_dimension): | |
self.path = path |
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
mport numpy as np | |
from keras.preprocessing.sequence import pad_sequences | |
class TextToTensor(): | |
def __init__(self, tokenizer, max_len): | |
self.tokenizer = tokenizer | |
self.max_len = max_len |
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
# Deep learning: | |
from keras.models import Input, Model | |
from keras.layers import LSTM, Dense, Embedding, concatenate, Dropout, concatenate | |
from keras.layers import Bidirectional | |
class RnnModel(): | |
""" | |
A recurrent neural network for semantic analysis | |
""" |
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
import numpy as np | |
# The main model class | |
from RNN_model import RnnModel | |
# Importing the word preprocesing class | |
from text_preprocessing import TextToTensor, clean_text | |
# Importing the word embedding class | |
from embeddings import Embeddings |
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
# Importing the packages | |
import tensorflow as tf | |
# Downloading data | |
# The default split is 60k images in the training set and 10k in the test set | |
mnist = tf.keras.datasets.fashion_mnist | |
(training_images, training_labels), (test_images, test_labels) = mnist.load_data() | |
# Normalizing the pixel values | |
training_images = training_images / 255.0 |
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
import tensorflow as tf | |
# Initiating the class | |
mnist = tf.keras.datasets.fashion_mnist | |
# Downloading the data | |
(training_images, training_labels), (test_images, test_labels) = mnist.load_data() | |
# Reshaping the images for the convolutional input | |
training_images=training_images.reshape(60000, 28, 28, 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
# Extracting the trained layers from the model | |
successive_outputs = [layer.output for layer in model.layers[1:]] | |
visualization_model = tf.keras.models.Model(inputs = model.input, outputs = successive_outputs) | |
# Getting an image from the training set | |
image = training_images[1] | |
# Intermediate representations for this image | |
successive_feature_maps = visualization_model.predict(image.reshape(1, 28, 28, 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
import cv2 | |
import numpy as np | |
from scipy import misc | |
import matplotlib.pyplot as plt | |
# Getting the image of ascent | |
i = misc.ascent() | |
# Ploting the original image | |
plt.grid(False) |
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 create_X_Y(ts: np.array, lag=1, n_ahead=1, target_index=0) -> tuple: | |
""" | |
A method to create X and Y matrix from a time series array for the training of | |
deep learning models | |
""" | |
# Extracting the number of features that are passed from the array | |
n_features = ts.shape[1] | |
# Creating placeholder lists | |
X, Y = [], [] |
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
class NNMultistepModel(): | |
def __init__( | |
self, | |
X, | |
Y, | |
n_outputs, | |
n_lag, | |
n_ft, | |
n_layer, |