Make Your First AI in 15 Minutes with Python

Mansi Sharma
2 min readJan 10, 2024

--

Python is a great language for AI development because of its ease of use and flexibility. There are many different libraries and frameworks available for AI development in Python, so it is important to choose one that is well suited for your project.

One popular library for AI development in Python is TensorFlow. TensorFlow is a powerful tool for deep learning, and it is perfect for building neural networks. If you are new to TensorFlow, then I recommend checking out the tutorials on the TensorFlow website.

Another popular library for AI development in Python is Keras. Keras is a high-level API that makes it easy to build neural networks. If you are new to Keras, then I recommend checking out the tutorials on the Keras website.

Once you have chosen a library or framework, you need to install it. I recommend using a virtual environment for your AI development projects. This will allow you to keep your dependencies isolated from your other projects.

To create a virtual environment, you can use the virtualenv tool. Once you have installed virtualenv, you can create a new virtual environment for your project by running the following command:

virtualenv myproject

This will create a new directory called “myproject” containing the following: Copy of the Python interpreter and all included libraries installed.

To activate your virtual environment, you can run the following command:

source myproject/bin/activate

Once your virtual environment is activated, you can install the AI ​​library or framework of your choice. For example, to install TensorFlow, you can run the following command:

pip install tensorflow

Once the library or framework is installed, you can start developing your AI project.

After installing Python Tensorflow, you will need to create a new file. You can do this using your favorite text editor. Let’s call our file “ai.py”.

First we import the Tensorflow library into our “ai.py” file:

import tensorflow as tf

Next, let’s create a new Tensorflow graph:

g = tf.Graph()

Once we’ve created our graph, let’s now add some nodes. The nodes in a Tensorflow graph represent mathematical operations. We will add a node that will perform the addition operation:

with g.as_default():
x = tf.placeholder(tf.float32, name="x")
y = tf.placeholder(tf.float32, name="y")
z = tf.add(x, y, name="z")

Now that we have added our nodes, we need to create a session. Sessions are used to perform operations on our graph:

with tf.Session(graph=g) as sess:
# Run the graph and print the result

result = sess.run(z, feed_dict={

x: 1.0,

y: 2.0

})

print(result)p

In the code above, we first create a session. Then we run the graph and print the result. The result of our add operation is 3.0.

Now you can run your “ai.py” file to see the results:

python ai.py

--

--

Mansi Sharma
Mansi Sharma

Written by Mansi Sharma

Hi, I'm Mansi Sharma, B2B SaaS Front-End Developer with expertise in UX Prompt Design and DesignOps. https://lushaseex.com/4/6301786