I built my own AI - It's not that hard! ๐Ÿ˜Ž

in #programming โ€ข 7 years ago (edited)

smiley-ai.png

I am a software developer and I am fascinated by AI. So I started to learn about neural networks and play around with it. As I was mostly concerned with building websites over the last few years, I looked for an implementation that runs on a webserver and so recently I built a little website that recognizes self drawn smileys. It looked like this:

smiley-ai-1.png

I think the image tells you what it does. You can draw a simple smiley into the circle and then either train the neural network by telling it what you have drawn or, after you did that a few dozens of time, you can let the overwhelmingly smart AI decide.

And guess what... It's quite accurate! ๐Ÿ˜Š

Of course AI and neural networks are not an easy topic at all and I am far from being an expert. But I tried to break it down to the basics and make my own simple example. I did a lot of research to get a general understanding of how a neural network works and how to implement one.

The basic concept is, that you have some kind of input and an algorithm that transforms this input into some output. The process of "learning" is actually the adjustment of this algorithm so that, for a given input, the output is what you want it to be.

So in my example the input is the smiley image and the output should be a number between 0 and 1. And I want the number to be 1 or at least close to 1 for a happy smiley and close to 0 for a sad one.

In a neural network you work with neurons in multiple layers. One layer for the input data, one for the output and one or more, so called "hidden" layers in between, to run the algorithm, so to say. In the input layer I have one neuron for each pixel in a smiley image, which are 75 x 75 pixels, so we get 5625 input neurons with values of 1 or 0 for black or white pixels. Then there are a few hidden layers, each with hundreds of neurons... just to make sure this "brain" can get "smart enough". And then the output layer is just a single neuron representing the resulting number.

smiley-ai-network.png

You can see that all the neurons of one layer are connected to all the neurons of the adjacent layers. And this is now where the magic happens. Each connection has a so called "weight", a number that tells the algorithm how "important" this connection is for calculating the end result. By adjusting these weights you can now adjust the result for a given smiley image. But unfortunately there are millions of connections, so adjusting them manually to give us the right result would take quite a long time. Luckily mathematics has another great algorithm at hand. It will do the job for us and we only have to say if a result is right or wrong. The algorithm then "tries" to adjust the weights in our neural network so that the result will be more appropriate.

This process now has to be repeated so many times and with so many different smileys that eventually our lovely algorithm can calculate if a smiley is happy or sad. I have to feed my neural network with round about 100 smileys until it gets "confident".

smiley-ai-trainingset.png

Basically you can train it to distinguish between any two different patterns.

smiley-ai-trainingset2.png

or

smiley-ai-trainingset3.png

I found out that the basics of AI aren't that hard to understand. The real magic, of course, lies in the algorithms which are far beyond my mathematical understanding. And there are so many other aspects of AI and machine learning. But I'm just not that far yet.

By the way, I would love to show you a live demo but unfortunately my hoster doesn't support the required PHP extension but if you want to take a look at the code, you can find it on github.


Hope you liked it and thank you for reading!

๐Ÿ˜˜ ๐Ÿ˜‰

Sort: ย 

Oh you better watch out Elon Musk has a plan to save humanity from AI.

ย 7 years agoย ย 

What if my AI has the plan to follow Elon on twitter, find out where he lives, hack his Tesla and bring him to a secret place where my AI will implant a neura link in his brain to infiltrate him and become a really really smart badass AI with the looks of Elon Musk?

Neat! It would be cool to distinguish an image that is or isn't a smiley for even further accuracy.

ย 7 years agoย (edited)ย 

In this setup it would it make less accurate actually. But you can adjust the neurons as you wish. You could have more than one output neuron and therefor depict a more detailed result. But this example should really just be a proof of concept. It was literally a learning project. :)