Python has become an essential part of modern AI development and is the preferred language for many AI developers and researchers. Because of its simplicity and readability, developers can focus on the logic and implementation of complex AI algorithms without getting bogged down in language syntax. This means Python is suitable for both beginners interested in AI as well as advanced AI developers.
Please note that many of the underlying computational libraries for AI are written in C++, primarily because C++ is fast and can be compiled to run on GPUs. An example here is TensorFlow. Although it can be used with Python, its core libraries are written in C++. But nearly all the rest of the libraries and frameworks are written in Python—and that means Python can be used in virtually all other areas of AI. Let’s explore these different areas and where Python fits in.
Pro tip: Most of the frameworks mentioned here are for building apps that work with AI. But these frameworks are themselves written in Python, which opens up additional opportunities for Python developers: you can help build the next version of these tools. We’ll have a few words about that at the end.
Machine Learning
Traditional programming involves coding specific algorithms to perform tasks, then saving the data in databases. Machine learning, on the other hand, reads and finds patterns in the data, and from there makes predictions or identifies similar patterns in later datasets.
For example, with traditional programming, a visual recognition app would have an algorithm for spotting a bear in an image, and a separate algorithm for spotting a horse, and so on. But with machine learning, the app would be fed hundreds of examples of bear images, and then told to look for common traits of bears, and then use those learnings to identify bears in future images. The same process would be used for horses and other animals. The process of feeding such data into the app is called training.
Such apps can be trained with other types of data, too, not just visual data. A common example in the finance world is identifying fraud. As millions of credit card transactions are processed daily, AI models can be trained to recognize transactions that match a fraudulent pattern. The consumer can then be notified that one of the transactions looks unusual.
TensorFlow and PyTorch are two frameworks for Python that can be used for machine learning, and there are multiple approaches you can go with. For example, you can start with pre-trained models that can spot the patterns the model is already aware of. If you’re building an app that can identify trees and plants based on their leaves, you might find a model pre-trained for such identification.
Or you might build such a model yourself, filling it with new leaf information until it’s useful for biologists or lay naturists. You might use the model yourself in your own app, or market the model to be used by researchers who build apps. There are many different directions you can take your machine language knowledge.
Deep Learning
Think of deep learning as the next evolution of machine learning. Deep learning can handle much larger data sets compared to machine learning, and it operates using what are called neural networks. Deep learning also requires significantly more computing power than machine learning, and provides the foundation to generative AI, such as ChatGPT.
Python is an ideal language for use in deep learning, as it can use libraries like PyTorch and Keras to create neural networks. Here are two types of neural networks you can study if you’re interested in learning about deep learning with Python:
Python can also be used to train deep learning models. Like any AI model, deep learning models can continue to learn and from there improve their perceived intelligence. You can use Python, for example, to build algorithms with names like:
- Stochastic Gradient Descent (SGD): This is an algorithm that trains a deep learning model by repeatedly updating the model’s parameters, basically continually tweaking the model.
- Adam (Adaptive Moment Estimation) Optimization Algorithm: This is another algorithm for training deep learning models, and it’s popular because it has low memory requirements.
Pro tip: These algorithms are extremely complex. You can use pre-built implementations of them, or, if you really want to do a deep dive, learn how the algorithms work from a mathematical perspective. But at the very least, you’ll want to read the basics about them and how they fit into the bigger picture. That’s why we linked mostly to the Wikipedia pages, which provide great summaries.
One framework in particular that’s useful here that you could learn is called Horovod, which works together with other frameworks such as TensorFlow and PyTorch.
Natural Language Processing
Natural Language Processing (NLP) is an AI specialty that we see with chat tools such as ChatGPT. NLP gives these tools the ability to understand and give responses in human language. NLP also allows these tools to learn by consuming enormous volumes of text (such as the entirety of Wikipedia). NLP is how, for example, you can ask ChatGPT the same question but phrased in wildly different ways. For example, a human and a chatbot trained in NLP could recognize that these two sentences are similar:
- “It’s a beautiful day outside, so I’m going to go for a walk.”
- “I noticed the sun is shining, and so I’m going to head over to the park.”
Python works well with NLP. For example, you could build a chat bot using a pretrained model, and add natural language features to your app. Or you can use Python to build an app that refines the knowledge in a model. The latter of these requires a deeper understanding of both NLP and how models are trained.
Here are some libraries you can use in your Python app to handle Natural Language Processing:
- NLTK (Natural Language Toolkit): This is an open-source library written in Python for providing natural language in an application.
- SpaCy: This is an open-source library for doing what its developers call “industrial strength natural language processing.” The developers claim that unlike NLTK, which is mostly used in research, SpaCy is for production applications.
- Transformers is a Python library created by Hugging Face that can add NLP to your application, as well as computer vision, speech recognition, audio classification, among others.
If you want to take your knowledge to the next level, learn the algorithms behind these libraries. All of these are open source. Then if you take your training to the next level, you could even learn enough to contribute to these libraries.
Predictive Analysis
Predictive analysis puts the aforementioned technologies to use by analyzing historical data to determine the statistical likelihood that something will occur. The hope is that users of such software can make informed decisions. A great example here is in healthcare, wherein medical professionals can enter data about a patient who is sick, and the app will be able to make predictions about the patient’s progression under different treatment plans based on historical data. This will help the doctors and nurses pick the best plan for the patient.
If you want to do predictive analysis with Python, your best bet is to use the library called scikit-learn, along with general data libraries such as pandas, numpy, and matplotlib.
There are many directions you go if you’re interested in predictive analysis. Using tools such as Jupyter Notebooks, you can write Python code and immediately run it to perform the analysis. You do this by loading the libraries directly into a Jupyter environment.
Or you can build apps that use tools like scikit-learn and make it easy for end users to perform predictive analysis without having to learn Python. Such apps could be general purpose, or you might build an app specific to an industry (like the healthcare example mentioned earlier).
You can also learn as much as you can about predictive analysis and, as with the other technologies described here, contribute to the libraries such as scikit-learn. Let’s now discuss that in more detail.
Contributing to the Tools and Frameworks
Most of the popular libraries and frameworks are open source. For example, PyTorch lives in a GitHub repo here. This means you can spend time going through the code, learning how it works, and getting a better understanding of the underlying algorithms and mathematics.
Most of these have contribution guides; for example, you can find the PyTorch contribution guide here. Study these carefully before attempting to contribute your own changes.
Pro tip: With any open-source project in general, not just AI frameworks, you’ll need to be comfortable with Git and GitHub, and especially concepts like branching, merging, and pull requests.
Conclusion
The more you understand how the frameworks work internally, the stronger your understanding of AI will be. What we’ve covered here barely scratches the surface but will hopefully get you started.