Introduction to Generative AI with Julia and Python From Theory to Practice (Pierluigi Riti)(Z-Library)

Author: Pierluigi Riti

编程

Elevate your coding capabilities and gain the skills necessary for maximized performance and career opportunities in the field of Artificial Intelligence. This book is a step-by-step guide designed to equip software engineers with solid foundation of Generative AI basics. The book begins by introducing Generative AI using Google Colab to establish a solid foundation, before demonstrating how to leverage Python and Julia’s AI capabilities to construct Artificial Neural Networks. You’ll then explore advanced AI models, such as variational autoencoders, in order to generative images and text. Author Pierluigi Riti not only navigates the complexities of this emerging topic but fills a crucial gap by guiding software engineers through theory before leading them to produce different types of models using only free resources. What You Will Learn Acquire a solid foundation of Generative AI basics. Utilize the capabilities of Python and Julia to constructure Artificial Neural Networks Explore advanced AI models including variational autoencoders, to generate images Survey different architectures for AI and utilize free resources to produce different AI Who This Book Is For Programmers new to artificial intelligence, but with a fundamental grasp of Python.

📄 File Format: PDF
💾 File Size: 9.3 MB
11
Views
0
Downloads
0.00
Total Donations

📄 Text Preview (First 20 pages)

ℹ️

Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

📄 Page 1
Introduction to Generative AI with Julia and Python From Theory to Practice — Pierluigi Riti
📄 Page 2
Introduction to Generative AI with Julia and Python From Theory to Practice Pierluigi Riti
📄 Page 3
Introduction to Generative AI with Julia and Python: From Theory to Practice ISBN-13 (pbk): 979-8-8688-2328-2 ISBN-13 (electronic): 979-8-8688-2329-9 https://doi.org/10.1007/979-8-8688-2329-9 Copyright © 2026 by Pierluigi Riti This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein. Managing Director, Apress Media LLC: Welmoed Spahr Acquisitions Editor: Melissa Duffy Development Editor: James Markham Copy Editor: Kezia Endsley Editorial Assistant: Gryffin Winkler Cover designed by eStudioCalamar Cover Photo by Dim Gunger on Unsplash.com Distributed to the book trade worldwide by Springer Science+Business Media New York, 1 New York Plaza, New York, NY 10004. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-sbm.com, or visit www.springeronline.com. Apress Media, LLC is a Delaware LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation. For information on translations, please e-mail booktranslations@springernature.com; for reprint, paperback, or audio rights, please e-mail bookpermissions@springernature.com. Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales web page at http://www.apress.com/bulk-sales. Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub. For more detailed information, please visit https://www.apress.com/gp/services/ source-code. If disposing of this product, please recycle the paper Pierluigi Riti Mullingar, Westmeath, Ireland
📄 Page 4
To my family.
📄 Page 5
v Table of Contents About the Author ����������������������������������������������������������������������������������������������������� ix About the Technical Reviewer ��������������������������������������������������������������������������������� xi Introduction ����������������������������������������������������������������������������������������������������������� xiii Chapter 1: Artificial Intelligence: A Gentle Introduction ������������������������������������������� 1 What Is Artificial Intelligence? 1 Machine Learning: Teaching a Machine to Learn  3 Different Types of Machine Learning  4 Artificial Neural Network: The Emulation of a Human Neuron  10 The Perceptron Formula  11 Implementing a Basic Perceptron with Python  12 Deep Learning Emulates the Human Brain  14 Learning from the Data 17 Gradient Descent  18 Generative AI  20 Understanding Uncertainty  22 Different Types of Generative Models  23 Autoregressive Models: Learning from the Past  23 Flow-Based Model: The Complexity Behind the Simplicity  27 Latent-Variable Models: Observing Reality to Find the Hidden Factor  28 Discriminative vs Generative  30 Conclusion  31 Chapter 2: Introduction to Julia ������������������������������������������������������������������������������ 33 The Reason Behind Julia 33 Core Languages Feature  34 Installing Julia  35
📄 Page 6
vi Command-Line Iteration with Julia  36 Variables  37 Variable Types  39 Operators  46 Functions  50 Control Flow  56 Collections in Julia  61 Arrays in Julia  62 Tuples  65 Dictionaries  65 Sets  67 Working with Files in Julia  68 Configuring Julia in Google Colab  70 Managing the Package in Julia  72 Conclusion  73 Chapter 3: Introduction to Python �������������������������������������������������������������������������� 75 Python Overview  75 Using REPL in Python  76 Indentation in Python  78 Basic Python Data Types  79 Variables in Python  79 Numeric Data Types  80 Containers  81 Boolean  94 Conditional Statements  96 Functions  97 Loops in Python  100 Conclusion  103 Table of ConTenTs
📄 Page 7
vii Chapter 4: Introduction to Generative Artificial Intelligence �������������������������������� 105 Generative AI Is All Around  105 Deep Generative Modelling  106 Sample Space 107 Density Function  107 Parametric Modelling  108 Maximum Likelihood Estimation  109 Your First Generative Model  109 How Important Is Probability in Generative AI?  112 Different Types of Generative Models  116 Flow-Based Networks and Residual Networks  121 Latent Variable Models  126 Foundation Models  129 Conclusion  131 Chapter 5: Generative Adversarial Networks (GANs) �������������������������������������������� 133 Basic GAN Architecture  133 The Generator  135 The Discriminator  136 Training a GAN  136 Evaluating the Result of GANs  139 GAN Use Cases  141 Your First Vanilla GAN  142 Implementing a Vanilla GAN with Julia  153 Final Thoughts  164 Conclusion  165 Chapter 6: Autoencoders �������������������������������������������������������������������������������������� 167 Introduction to Autoencoders  167 Different Types of Autoencoders  169 Denoising Autoencoder  186 Conclusion  196 Table of ConTenTs
📄 Page 8
viii Chapter 7: Variational Autoencoders �������������������������������������������������������������������� 199 How Variational Autoencoders (VAEs) Work  199 The Importance of Latent Space  200 The Variational Autoencoder Architecture  201 Examples of Variational Autoencoders  202 The Convolutional Variational Autoencoder in Python  202 The Denoising Variational Autoencoder  211 The Convolutional Variational Autoencoder in Julia  220 The Denoising Variational Autoencoder in Julia  228 Looking Ahead and Conclusion  237 Index ��������������������������������������������������������������������������������������������������������������������� 239 Table of ConTenTs
📄 Page 9
ix About the Author Pierluigi Riti is currently a technical leader with Mastercard. Before that, he was a senior software engineer at Coupa, Synchronos, Ericsson, and Tata. His experience includes designing and implementing complex software architectures. He also has over 20 years of experience in general design and development of applications at different scales, particularly in the telco and financial industries. Pierluigi holds a Master’s degree in Science of Artificial Intelligence from the University of Limerick and is a researcher with South-East Technological University in Ireland, focusing on high-tech startups in the field of AI.
📄 Page 10
xi About the Technical Reviewer Mohit Taneja is an AI humanist and currently works as an AI Engineering Manager at Workhuman, with over a decade of experience building scalable, human-centric AI products. At Workhuman, he leads cross-functional teams developing AI-driven solutions that elevate workplace engagement and empower people. His background spans industry, research, and academia, bringing together deep technical expertise, product thinking, and a commitment to responsible innovation. Previously at Mastercard, Mohit led multiple AI and Generative AI initiatives, contributing 14 invention disclosures and 12 patent applications. He has also lectured in computing and conducted research at the Walton Institute and CONNECT Centre, focusing on AI, IoT, and distributed systems. Driven by the belief that technology should meaningfully serve people, Mohit focuses on the intersection of AI, business value, and human impact—building systems that solve complex challenges and create lasting global change.
📄 Page 11
xiii Introduction This book explains what generative artificial intelligence (GenAI) is, which is not a passing trend. It’s a technology that has come to stay. If you ask to someone for an example of GenAI, they might mention ChatGPT, Gemini, Claude, or any other Large Language Model (LLM), which are very good examples. However, the field is much bigger than that. This book presents different uses of the GenAI, including generative adversarial networks, autoencoders, and variational-autoencoders. You will learn how these models learn and reproduce the data. This book also explains how to use Python and Julia to code for different flavors of the same architecture. Every chapter is mixed with theory and practice, which will give you the basics to expand your knowledge and improve your skill. The book is not intended to explain the entire topic, but to be an introduction that you can use to improve and start your own journey in the field of the GenAI.
📄 Page 12
1 © Pierluigi Riti 2026 P. Riti, Introduction to Generative AI with Julia and Python, https://doi.org/10.1007/979-8-8688-2329-9_1 CHAPTER 1 Artificial Intelligence: A Gentle Introduction We live in an interesting era. We are witnessing the rise of artificial intelligence and all the new opportunities it has created. However, to get the best results from these opportunities, we need to learn new skills and acquire knowledge. This book explains the field of generative artificial intelligence (GenAI). This is one of the most interesting fields to be in. The book explains the basic theory and covers some practical examples. This type of combined work will help you understand the concepts behind some well-known AI models, including ChatGPT, Hugging Face, and DALL-E. This chapter introduces the basic science of artificial intelligence, which in my opinion is one of the most exciting sub-fields of computer science. You can use this information as a foundation for understanding the differences between artificial intelligence, machine learning, and deep learning. What Is Artificial Intelligence? Nowadays it is not difficult to hear something new about artificial intelligence, such as a new AI model or application. If you are curious like me, you probably start to ask yourself, what is artificial intelligence? What is the difference between artificial intelligence and machine learning? The first step is to define “artificial intelligence”. This definition is based on an Alan Tuning article published in the 1950s called “Computing and Machinery Intelligence,” which states: The science and engineering of making computer machines able to perform a task that normally requires human intelligence.
📄 Page 13
2 Based on this definition, we can see that artificial intelligence is a science. This is the first difference between machine learning and artificial intelligence. Machine learning is defined this way: The field of study in artificial intelligence that explores the use of statistical algorithms that can learn from data. The last term we need to define is deep learning. Deep learning is defined this way: A sub-field of machine learning based on the use of artificial neural net- works for learning and identifying the underlying patterns in data. As you can see from the definition, artificial intelligence is the science. The application of the science is machine learning or deep learning. They have in common the use of data, which is used to learn how the “problem” is defined and how to solve it. Figure 1-1 shows a graphical representation of the science of artificial intelligence and its sub-fields. When you hear about a new artificial intelligence model developed by some organization, they probably are referring to a new machine learning or deep learning model that’s designed to solve a specific problem, which is solved by learning from the data. This is important to remember when we talk about machine learning or deep learning. We always talk about a statistical or probabilistic algorithm that learns the underlying pattern of the data. This technology does not have any critical thinking capacity. The first discipline you need to learn about is machine learning. It gives you the foundation for better understanding generative artificial intelligence. Or, better termed as generative deep learning. Because artificial intelligence is the name of the science, while deep learning is the application of the science itself. I use the term “Generative AI” or “Generative Artificial Intelligence” in this book, because this is the term used in the outside world. But in reality, the model you create is a deep learning model, as you will soon see. ChApter 1 ArtIfICIAl IntellIGenCe: A Gentle IntroduCtIon
📄 Page 14
3 Figure 1-1. The relationship between artificial intelligence, machine learning, and deep learning Machine Learning: Teaching a Machine to Learn Machine learning was the first implementation of the science of artificial intelligence. Machine learning comes directly from the article published by Alan Turing. It is the use of statistics to allow a computer (a “machine”) to learn from the data. This is probably one of the most interesting fields to be in at this stage. If you imagine yourself in the future looking back at this time, you can easily say this is the start of the “age of the data”. Every day people produce and consume trillions of data. Consider your daily routine. You wake up and your mobile phone downloads your emails. Maybe you listen to some music on Spotify or browse the Internet. You read your favorite online newspaper. Your kids watch YouTube videos or a cartoon from a streaming platform during breakfast. You get a coffee at your favorite place on the way to work, pay with a debit card, and possibly use your fidelity card to collect points. If you need directions to somewhere, you ChApter 1 ArtIfICIAl IntellIGenCe: A Gentle IntroduCtIon
📄 Page 15
4 just put the address into Google Maps and the application finds the best journey based on your preferences. These are just a few examples of the kinds of data people generate every day. Based on a study by Statistica.com in 2020, generated data reached 64.2 zettabytes, and the site forecasted over 180 zettabytes generated by 2025. With this incredible amount of data, machine learning plays a vital role in our daily lives. As an engineer, it is very important to understand it and learn to use it. But what exactly is machine learning, and how many types of machine learning are there? Different Types of Machine Learning As mentioned, machine learning is a sub-field of artificial intelligence. So, it is a science. It is the science of using statistical algorithms to create self-learning algorithms. These algorithms learn from the data and turn it into knowledge. The way machine learning turns data into knowledge is the interesting part. There are three categories you can use to learn from the data: • Supervised learning • Unsupervised learning • Reinforcement learning Each category is designed to solve a specific class of problems. Because of that, they use specific algorithms to solve their problems. note that I don’t mention deep learning or the artificial neural network here, because they are more architecture than a specific set of algorithms. the section describes the basics of machine learning as a foundation to build the rest of the knowledge. Supervised Learning: Learning from Labelled Data Supervised learning is a model that learns from labelled data. The algorithm learns the underlying data’s pattern using labelled data. After learning the main characteristics of the data’s main features, it applies the same knowledge to unseen data. ChApter 1 ArtIfICIAl IntellIGenCe: A Gentle IntroduCtIon
📄 Page 16
5 Supervised learning has these specific characteristics: • The algorithm is fed with labelled data • There is direct feedback about the data • The algorithm can predict the outcome of the unseen data To illustrate how supervised learning works, Figure 1-2 shows a 10,000-foot overview. The labelled data used for the training, in this case, the image of the different dogs, is fed to the machine learning model. Figure 1-2. An overview of a supervised learning model The model learns the specific characteristics of the dogs and then, as a result, you get a predictive model. ChApter 1 ArtIfICIAl IntellIGenCe: A Gentle IntroduCtIon
📄 Page 17
6 This is the result of the training done by the machine learning algorithm on the labelled data. With the model trained, you can make predictions on the unseen data. For example, if you were to try to classify a picture of a golden retriever as a dog or a cat, the model would correctly classify it as a dog. The main goal of a classification algorithm is to predict the categorical class of unlabeled data. The model does this by learning the fundamental structure of past data. In this example, that’s the training data. This previous example—the cat and the dog—is called binary classification. The algorithm learns how to classify one type of data. However, classification can also be used for multiple types of data, which is called multiclass classification. The labelled data represents different types of data. One example is the classification of a handwritten digit. The MINST dataset contains different digits, 0 to 9. The algorithm will learn to recognize each digit and then properly classify any digit between 0 and 9. Another type of classification is called regression analysis. In this type of analysis, there are several explanatory variables, called features in the field of machine learning, as well as continuous response outcome variables, called target variables in the field of machine learning. The goal of the algorithm is to find a correlation between the explanatory variables and the outcome variables so it can predict the outcome from unseen data. Regression can be used, for example, if you want to predict the price of a house. Imagine that you want to know how the number of rooms and the square feet influence the price of a home in your town. When you train the algorithm, you can use it to predict the outcome of new data. Unsupervised Learning: Discover Hidden Information in the Data Supervised learning uses labelled data to learn the main features of the data and predict the outcome. In unsupervised learning, you can extract meaningful information without any previous knowledge of the data or the expected results. In supervised learning, you know the label. But, in unsupervised learning, you have no idea about the data. In unsupervised learning, you classify through clustering. Clustering is a type of exploratory data analysis (EDA). Its main goal is to group the data based on common characteristics. The different types of groups are called clusters. Each object in a cluster is similar. By the same token, they are less similar to objects in other clusters. ChApter 1 ArtIfICIAl IntellIGenCe: A Gentle IntroduCtIon
📄 Page 18
7 Figure 1-3 shows a visual example of clustering. The two clusters show dogs and cats. The data in the cluster is split based on the features of X1 and X2. Figure 1-3. An example of clustering Figure 1-4 shows an example of how a machine learning model for clustering works. The inputs are all unlabeled. The model identifies the unique features of the object and creates the cluster based on similarities. It creates the clusters based on major similarities. ChApter 1 ArtIfICIAl IntellIGenCe: A Gentle IntroduCtIon
📄 Page 19
8 Figure 1-4. An example of clustering workflow Another unsupervised learning technique is called dimensionality reduction. It is commonly used when you need to preprocess data to reduce its noise. Removing the noise from data is important. For example, removing the outliers increases any predictive information. Reinforcement Learning: Learning from Errors Reinforcement learning is another type of machine learning. This technique is most similar to the way humans learn. Reinforcement learning’s goal is to make the agent learn by interacting with the system. The interaction between the agent and the system produces a reward. The agent uses this reward to enhance the interactions and achieve the goal. The agent can learn in two ways. One way is via exploratory approaches, where the agent explores the entire system before making a decision. The other way is through the trial-and-error approach, where every action made by the agent will return a positive or negative response. ChApter 1 ArtIfICIAl IntellIGenCe: A Gentle IntroduCtIon
📄 Page 20
9 The final goal of a reinforcement learning model is to maximize the reward. This type of machine learning had a huge impact on the development and creation of generative deep learning applications. The most commonly known example of this is ChatGPT. There are different subtypes of reinforcement learning, but in general, the reinforcement learning schema can be defined similar to what is shown in Figure 1-5. An agent executes an action on the environment; it then receives a new state and the reward connected to the action. Figure 1-5. A schema that represents the reinforcement learning method One difference between reinforcement learning and the other machine learning methodologies is the goal of a reinforced learning algorithm. In reinforcement learning, the only concern is identifying the set of actions that maximize the total reward. This reward could be earned by an immediate action or via delayed feedback. You use reinforced learning when you want to create a system that can learn by specific actions. the capacity to get a reward via delayed feedback is important when we talk about the architecture behind the famous openAI software ChatGpt. this model uses reinforcement learning from human feedback, rlhf. In this type of architecture, the agent gets delayed feedback from the human. In this case, the human can provide a different reward to the action chosen by the model and the model will improve the action in order to maximize the reward. ChApter 1 ArtIfICIAl IntellIGenCe: A Gentle IntroduCtIon
The above is a preview of the first 20 pages. Register to read the complete e-book.

💝 Support Author

0.00
Total Amount (¥)
0
Donation Count

Login to support the author

Login Now

Recommended for You

Loading recommended books...
Failed to load, please try again later
Back to List