How To Write Your Very First Powerful Artificial Intelligence /s

Such clever, many intelligent, very human.

I know, you’re insanely busy so let’s keep this tutorial short and neat.

What is Machine Learning?

At the end of 2015, there was an article on HackerNews stating that Google’s Brain Team open-sourced their machine learning library called TensorFlow. Given the fact that there was a massive news coverage about it, I thought this must be something huge Google offered. Back then, I didn’t know what Machine Learning means. To gain more clarity, I started to dig deeper into this subject.

How can a computer learn by itself? Has the humanity finally developed a strong AI? Could AI become more intelligent than its creator? Thousands of questions crossed my mind, leaving me with the dedication to invest even more time into this great field.

Maybe it’s just me, but the more I learn, the more I want to learn.

Little did I know that Machine Learning will have a huge impact on my personal career as a developer.

Long story short, in the last 14 months, I’ve spent dozens of dozens of hours to become a true ML expert.

I think it’s time to share this interesting technology with you. Therefore, I want to give a brief introduction how to write your own AI.

Let’s face it, our AI that we’re going to create today won’t be groundbreaking, but it’ll be very worthwhile.

Let’s get started

I’m using Python 3 to develop the AI. Don’t worry, all the final code is on my GitHub Repo so you can easily copy-paste the code.

Nowadays, it’s important to have a catchy name for your AI. Apple started with Siri, Amazon came up with Alexa, so I’m gonna call mine Sirlexa. Go ahead and think of a fancy name for your AI.

Next, open up your code editor. I’m using Sublime Text 3. Make a new python file called “sirlexa.py” on your desktop. If you’re using macOS, here are the terminal commands:

cd Desktop
touch sirlexa.py

Open sirlexa.py with your code editor and write the following:

In the first line, we are importing the standard random module that we’re going to need later. Answers is a list with 3 different sentences, in case Sirlexa doesn’t understand, one of those sentences will be printed out in the console.

The most complicated chunk of code in sirlexa.py

Now follows the main part. It’s an infinite while loop. We store the input which the user types in the console in user_input, then we check if user_input equals ‘ hi ’, if not, Sirlexa prints randomly one of the sentences from our list answers. Instead of user_input.lower() we could also use .upper(), but then Sirlexa gets angry at you for yelling.

That’s it, you just created your own AI.

Sure, Sirlexa won’t trick anyone in a Turing Test, but hey, you just created a very, very basic sort of artificial intelligence.


P.S. Here is the GitHub Repo. Be sure to check it out!

P.P.S. Feel free to extend the code with elif (else if) statements to optimize your AI.

/s