Book Image

Hands-On Neural Networks with Keras

By : Niloy Purkait
Book Image

Hands-On Neural Networks with Keras

By: Niloy Purkait

Overview of this book

Neural networks are used to solve a wide range of problems in different areas of AI and deep learning. Hands-On Neural Networks with Keras will start with teaching you about the core concepts of neural networks. You will delve into combining different neural network models and work with real-world use cases, including computer vision, natural language understanding, synthetic data generation, and many more. Moving on, you will become well versed with convolutional neural networks (CNNs), recurrent neural networks (RNNs), long short-term memory (LSTM) networks, autoencoders, and generative adversarial networks (GANs) using real-world training datasets. We will examine how to use CNNs for image recognition, how to use reinforcement learning agents, and many more. We will dive into the specific architectures of various networks and then implement each of them in a hands-on manner using industry-grade frameworks. By the end of this book, you will be highly familiar with all prominent deep learning models and frameworks, and the options you have when applying deep learning to real-world scenarios and embedding artificial intelligence as the core fabric of your organization.
Table of Contents (16 chapters)
Free Chapter
1
Section 1: Fundamentals of Neural Networks
5
Section 2: Advanced Neural Network Architectures
10
Section 3: Hybrid Model Architecture
13
Section 4: Road Ahead

Vectorizing features

The following function will take our training data of 25,000 lists of integers, where each list is a review. In return, it spits out one-hot encoded vectors for each of the integer lists it received from our training set. Then, we simply redefine our training and test features by using this function to transform our integer lists into a 2D tensor of one-hot encoded review vectors:

import numpy as np
def vectorize_features(features):

#Define the number of total words in our corpus
#make an empty 2D tensor of shape (25000, 12000)
dimension=12000
review_vectors=np.zeros((len(features), dimension))

#interate over each review
#set the indices of our empty tensor to 1s
for location, feature in enumerate(features):
review_vectors[location, feature]=1
return review_vectors

x_train = vectorize_features(x_train)
x_test = vectorize_features(x_test)

You can see the result of...