Layers
Layers in a neural network are very important as we saw earlier an artificial neural network consists of 3 layers an input layer, hidden layer, output layer. The input layer consists of the features and values that need to be analyzed inside a neural network. Basically, this is a layer that will read our input features onto an Artificial neural network.
A hidden layer is a layer where all the magic happens when all the input neurons pass the features to the hidden layer with a weight and a bias each and every neuron inside the hidden layer will sum up all the weighted features from all the input layers and apply an activation function to keep the values between 0 and 1 for easier learning. Here we need to choose the number of neurons in each layer manually and it must be the best value for the network.
Here the real decision-makers are the weights between each layer which will finally pass a value of 0 to 1 to the output layer. Till this, we have seen the importance of each level of layers in an artificial neural network. There are many types of layers in TensorFlow but the one that we will use a lot is Dense
syntax: tf.keras.layers.Dense()
This is a fully connected layer in which each and every feature input will be connected somehow with the result.
Artificial Neural Network in TensorFlow
In this article, we are going to see some basics of ANN and a simple implementation of an artificial neural network. Tensorflow is a powerful machine learning library to create models and neural networks.
So, before we start What are Artificial neural networks? Here is a simple and clear definition of artificial neural networks. So long story in short artificial neural networks is a technology that mimics a human brain to learn from some key features and classify or predict in the real world. An artificial neural network is composed of numbers of neurons which is compared to the neurons in the human brain.
It is designed to make a computer learn from small insights and features and make them autonomous to learn from the real world and provide solutions in real-time faster than a human.
A neuron in an artificial neural network, will perform two operations inside it
- Sum of all weights
- Activation function
So a basic Artificial neural network will be in a form of,
- Input layer – To get the data from the user or a client or a server to analyze and give the result.
- Hidden layers – This layer can be in any number and these layers will analyze the inputs with passing through them with different biases, weights, and activation functions to provide an output
- Output Layer – This is where we can get the result from a neural network.
So as we know the outline of the neural networks, now we shall move to the important functions and methods that help a neural network to learn correctly from the data.
Note: Any neural network can learn from the data but without good parameter values a neural network might not able to learn from the data correctly and will not give you the correct result.
Some of the features that determine the quality of our neural network are:
- Layers
- Activation function
- Loss function
- Optimizer
Now we shall discuss each one of them in detail,
The first stage of our model building is:
Python3
# Defining the model model = keras.Sequential([ keras.layers.Dense( 32 , input_shape = ( 2 ,), activation = 'relu' ), keras.layers.Dense( 16 , activation = 'relu' ), keras.layers.Dense( 2 , activation = 'sigmoid' ) ]) |