09.05.2023 Views

pdfcoffee

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Note that a hyperplane is a subspace whose dimension is one less than that of its

ambient space. See Figure 3 for an example:

Chapter 1

Figure 3: An example of a hyperplane

In other words, this is a very simple but effective algorithm! For example, given three

input features, the amounts of red, green, and blue in a color, the perceptron could

try to decide whether the color is white or not.

Note that the perceptron cannot express a "maybe" answer. It can answer "yes" (1)

or "no" (0), if we understand how to define w and b. This is the "training" process

that will be discussed in the following sections.

A first example of TensorFlow 2.0 code

There are three ways of creating a model in tf.keras: Sequential API , Functional

API, and Model subclassing. In this chapter we will use the simplest one,

Sequential(), while the other two are discussed in Chapter 2, TensorFlow 1.x and 2.x.

A Sequential() model is a linear pipeline (a stack) of neural network layers. This

code fragment defines a single layer with 10 artificial neurons that expects 784 input

variables (also known as features). Note that the net is "dense," meaning that each

neuron in a layer is connected to all neurons located in the previous layer, and to all

the neurons in the following layer:

import tensorflow as tf

from tensorflow import keras

NB_CLASSES = 10

RESHAPED = 784

model = tf.keras.models.Sequential()

model.add(keras.layers.Dense(NB_CLASSES,

input_shape=(RESHAPED,), kernel_initializer='zeros',

name='dense_layer', activation='softmax'))

[ 7 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!