Logo

dev-resources.site

for different kinds of informations.

Adding the Layers - Neural Networks Part 1.5

Published at
9/9/2023
Categories
ai
python
neuralnetworks
beginners
Author
vishalkamath
Author
12 person written this
vishalkamath
open
Adding the Layers - Neural Networks Part 1.5

We have worked with a single neuron in the previous blog, now let us look at the code part

Coding Neurons in Python

Neuron

We can calculate the value using Python's dot product, Here's how

Dot product

Dot product equation

So the output of a neuron can also be calculated as

Implementing neuron calculation using dot product

Implementation in Python

import numpy as np

inputs = [1, 2, 3, 2.5]
weights = [0.2, 0.8, -0.5, 1.0]
bias = 2

output = np.dot(inputs, weights) + bias
print(output)
Enter fullscreen mode Exit fullscreen mode

Working with Layers

Now that we have found a way to calculate the output of a neuron we can move up by calculating the output of a layer with 3 neurons. The inputs for all three neurons will be the same the input is the output of the previous layer so the only way for us to influence the output of each neuron is with the help of weights and biases. We will pass weights as a 2D array of shapes (3,4), and biases as an array of shape (4,).

Layer

import numpy as np

inputs = [1, 2, 3, 2.5]
weights = [[0.2, 0.8, -0.5, 1.0],
          [0.5, -0.91, 0.26, -0.5],
          [-0.26, -0.27, 0.17, 0.87]]
biases = [2, 3, 0.5]

output = np.dot(weights, inputs ) + biases
# output [4.8  , 1.21 , 2.385]
Enter fullscreen mode Exit fullscreen mode

Note: It is important to note that weights are passed before inputs as the shape of weights is (3,4) and inputs is (4,). If we were to put inputs before weights the (4,) and (3,4) will clash and give an ERROR as 4 doesn't match with 3.


Previous Part
Neural Networks describe the World!! - Neural Networks Part 1


GitHub: https://github.com/Vishal-Kamath.
LinkedIn: https://www.linkedin.com/in/vishalkamath853
Medium: https://medium.com/@vishalkamath853
Twitter: https://twitter.com/VishalKamath853

neuralnetworks Article's
30 articles in total
Favicon
Unlocking the Power of AI in the Palm of Your Hand with NVIDIA Jetson Nano
Favicon
Understanding Large Language Models (LLMs)
Favicon
A Comprehensive Overview of Neural Networks and Their Applications in Modern AI
Favicon
Understanding Recursive Neural Networks
Favicon
AI Driven Encryption Harnessing Neural Networks for Enhanced Security
Favicon
AI Driven Encryption Harnessing Neural Networks for Enhanced Security
Favicon
AIDrivenEncryptionHarnessingNeuralNetworksforEnhancedSecurity
Favicon
How Deep Learning Works
Favicon
Neural Networks
Favicon
What are Neural Networks? Deep Learning Explained for Beginners
Favicon
What are Convolutional Neural Networks (CNN)? The Art of Computer Vision For Beginners
Favicon
All in 1 Image Classification using CNN's
Favicon
Classical ML vs Neural Networks: Image Classification
Favicon
Revolutionizing AI: How a New Transformer Tweak Slashed Validation Loss by up to 30%!
Favicon
The Easiest Guide To Understand Neural Networks
Favicon
Recurrent Neural Networks (RNNs) - Easily Explained 🚀
Favicon
Adding the Layers - Neural Networks Part 1.5
Favicon
Neural Networks describe the World!! - Neural Networks Part 1
Favicon
Are there any examples of job enhancement through AI augmentation?
Favicon
Mastering Optimizers with Tensorflow: A Deep Dive Into Efficient Model Training
Favicon
"In the Eye of the Tech-Storm: Navigating Crime with Neural Networks"
Favicon
“Shadows of Intent: Probing the Mind to Protect”
Favicon
Moving metrics in Batch Normalization
Favicon
AI & Ruby: an introduction to neural networks
Favicon
Breaking the ice: How to solve OpenAI Frozen Lake with the cross-entropy method
Favicon
Neural networks 101: The basics of forward and backward propagation
Favicon
How to change hair styles using AI ?
Favicon
WhyML - New YouTube Channel for ML
Favicon
AI Relationships
Favicon
Python Machine Learning

Featured ones: