Generative AI with Python and PyTorch - Joseph Babcock - E-Book

Generative AI with Python and PyTorch E-Book

Joseph Babcock

0,0
39,59 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

Become an expert in Generative AI through immersive, hands-on projects that leverage today’s most powerful models for Natural Language Processing (NLP) and computer vision. Generative AI with Python and PyTorch is your end-to-end guide to creating advanced AI applications, made easy by Raghav Bali, a seasoned data scientist with multiple patents in AI, and Joseph Babcock, a PhD and machine learning expert. Through business-tested approaches, this book simplifies complex GenAI concepts, making learning both accessible and immediately applicable.
From NLP to image generation, this second edition explores practical applications and the underlying theories that power these technologies. By integrating the latest advancements in LLMs, it prepares you to design and implement powerful AI systems that transform data into actionable intelligence.
You’ll build your versatile LLM toolkit by gaining expertise in GPT-4, LangChain, RLHF, LoRA, RAG, and more. You’ll also explore deep learning techniques for image generation and apply styler transfer using GANs, before advancing to implement CLIP and diffusion models.
Whether you’re generating dynamic content or developing complex AI-driven solutions, this book equips you with everything you need to harness the full transformative power of Python and AI.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB
MOBI

Seitenzahl: 524

Veröffentlichungsjahr: 2025

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Generative AI with Python and PyTorch

Second Edition

Navigating the AI frontier with LLMs, Stable Diffusion, and next-gen AI applications

Joseph Babcock

Raghav Bali

Generative AI with Python and PyTorch

Second Edition

Copyright © 2025 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

Portfolio Director: Gebin George

Relationship Lead: Vignesh Raju

Project Manager: Prajakta Naik

Content Engineer: Deepayan Bhattacharjee

Technical Editor: Rahul Limbachiya

Copy Editor: Safis Editing

Indexer: Rekha Nair

Proofreader: Safis Editing

Production Designer: Ajay Patule

Growth Lead: Kunal Sawant

First published: April 2021

Second edition: March 2025

Production reference: 3101125

Published by Packt Publishing Ltd.

Grosvenor House

11 St Paul’s Square

Birmingham

B3 1RB, UK.

ISBN 978-1-83588-444-7

www.packtpub.com

Contributors

About the authors

Joseph Babcock has spent over a decade working with big data and AI in the e-commerce, digital streaming, and quantitative finance domains. Throughout his career, he has worked on recommender systems, petabyte-scale cloud data pipelines, A/B testing, causal inference, and time-series analysis. He completed his PhD studies at Johns Hopkins University, applying machine learning to drug discovery and genomics.

Raghav Bali is a Principal Data Scientist at Delivery Hero. With more than 14 years of experience, is involved in the research and development of data-driven, enterprise-level solutions based on machine learning, deep learning, and natural language processing. He has published multiple peer-reviewed papers at leading conferences, eight well-received books with major publishers, and is a co-inventor of more than 10 patents across various domains. His recent books include Generative AI with Python and TensorFlow 2 and Hands-On Transfer Learning with Python.

To my wife, parents, and teachers, without whom this would not have been possible. To all the researchers whose work continues to inspire me to learn. And to my co-author, Joseph, the reviewers, and the Packt team (especially Pradeep, Namrata, Bhavesh, Deepayan, Vignesh, and Prajakta) for their hard work in transforming our work into this amazing book.

About the reviewers

Ajinkya Pahinka is an ML engineer with expertise in deep learning, computer vision, and NLP. He has worked on projects spanning the tire industry, agriculture, and satellite imaging. Ajinkya holds a master’s degree in data science from Indiana University Bloomington, where he conducted research in biomedical image segmentation and NLP. His work on tire defect detection using CNNs was published at an IEEE conference, and he has authored research on computer vision in internationally recognized journals. Ajinkya has contributed to machine learning initiatives for agricultural pest prediction and satellite image enhancement as part of an ISRO-funded project. He is currently a software developer at ServiceLink, a subsidiary of Fidelity National Financial, where he works on cutting-edge financial products in the mortgage industry.

Darshil Modi is an AI research engineer at DeGirum Corp, a semiconductor company that ships AI models on its hardware. He earned a master’s degree in computer science from Santa Clara University and has over five years of experience in NLP and AI. He has helped numerous Silicon Valley startups build LLM-based products and is the creator of the LLM framework AutoMeta RAG, published by LlamaIndex and Qdrant. A tech speaker, Darshil has been invited to various conferences and events to discuss tackling real-world challenges using AI and LLMs. He is also a technical reviewer for several publications and is co-authoring a book on RAG with Manning Publications. His expertise lies in bridging business problems with comprehensive, end-to-end AI solution architectures and executing them efficiently.

Join our Discord and Reddit Space

You’re not the only one navigating fragmented tools, constant updates, and unclear best practices. Join a growing community of professionals exchanging insights that don’t make it into documentation.

Join our Discord at https://packt.link/z8ivB

or scan the QR code below:

Follow us on Reddit at https://packt.link/0rExL

or scan the QR code below:

Share your thoughts

Once you’ve read Generative AI with Python and PyTorch, Second Edition, we’d love to hear your thoughts! Please click here to go straight to the Amazon review page for this book and share your feedback.

Your review is important to us and the tech community and will help us make sure we’re delivering excellent quality content.

Free Benefits with Your Book

This book comes with free benefits to support your learning. Activate them now for instant access (see the “How to Unlock” section for instructions).

Here’s a quick overview of what you can instantly unlock with your purchase:

PDF and ePub Copies

Next-Gen Web-Based Reader

Access a DRM-free PDF copy of this book to read anywhere, on any device.

Multi-device progress sync: Pick up where you left off, on any device.

Use a DRM-free ePub version with your favorite e-reader.

Highlighting and notetaking: Capture ideas and turn reading into lasting knowledge.

Bookmarking: Save and revisit key sections whenever you need them.

Dark mode: Reduce eye strain by switching to dark or sepia themes.

How to Unlock

Scan the QR code (or go to packtpub.com/unlock). Search for this book by name, confirm the edition, and then follow the steps on the page.

Note: Keep your invoice handy. Purchases made directly from Packt don’t require one.

2

Building Blocks of Deep Neural Networks

The wide range of generative AI models that we will implement in this book are all built on the foundation of advances over the last 15 years in deep learning and neural networks. While, in practice, we could implement these projects without reference to historical developments, it will give you a richer understanding of how and why these models work to retrace their underlying components. In this chapter, we will dive into this background, showing you how generative AI models are built from the ground up, how smaller units are assembled into complex architectures, how the loss functions in these models are optimized, and some current theories as to why these models are so effective. Armed with this background knowledge, you should be able to understand, in greater depth, the reasoning behind the more advanced models and topics that we look at from Chapter 11,Painting Pictures with Neural Networks Using VAEs, of this book. Generally speaking, we can group the architecture, transforms, and optimization methods of neural network models into a number of choices regarding how the model is constructed and trained, which we will cover in this chapter as follows.

Which neural network architecture to use:

PerceptronMultilayer Perceptron (MLP)/feedforwardConvolutional Neural Networks (CNNs)Recurrent Neural Networks (RNNs)Long Short-Term Memory Networks (LSTMs)Gated Recurrent Units (GRUs)Transformers

Which activation functions to use in the network:

LinearSigmoidTanhRectified Linear Unit (ReLU)Parametric Rectified Linear Unit (PReLU)Exponential Linear Unit (ELU)Gaussian Error Linear Unit (GELU)Sigmoid Linear Unit (SiLU)Swish and Gaussian Error Linear Unit (SwiGLU)Positional encoding

Which optimization algorithm to use to tune the parameters of the network:

Stochastic Gradient Descent (SGD)Root Mean Square Propagation (RMSProp)Adaptive Gradient (AdaGrad)Adaptive Moment Estimation (ADAM)ADAM Weighted (ADAMW)Adaptive Delta (AdaDelta)Hessian-free optimization

How to initialize the parameters of the network:

RandomXavier initializationHe initialization

As you can appreciate, the products of these decisions can lead to a huge number of potential neural network variants, and one of the challenges of developing these models is determining the right search space within each of these choices. In the course of describing the history of neural networks, we will discuss the implications of each of these model parameters in more detail. Our overview of this field begins with the origin of the discipline: the humble perceptron model.

Perceptrons: A brain in a function

The simplest neural network architecture—the perceptron—was inspired by biological research to understand the basis of mental processing in an attempt to represent the function of the brain with mathematical formulae. In this section, we will cover some of this early research and how it inspired what is now the field of deep learning and generative AI.

From tissues to TLUs

The recent popularity of AI algorithms might give the false impression that this field is new. Many recent models are based on discoveries made decades ago that have been reinvigorated by the massive computational resources available in the cloud and customized hardware for parallel matrix computations such as Graphical Processing Units (GPUs), Tensor Processing Units (TPUs), and Field-Programmable Gate Array (FPGAs). If we consider research on neural networks to include their biological inspiration as well as computational theory, this field is over a hundred years old. Indeed, one of the first neural networks described appears in the detailed anatomical illustrations of the 19th-century scientist Santiago Ramón y Cajal, whose illustrations based on experimental observations of layers of interconnected neuronal cells inspired the neuron doctrine—the idea that the brain is composed of individual, physically distinct, and specialized cells rather than a single continuous network.1 The distinct layers of the retina observed by Cajal were also the inspiration for particular neural network architectures such as CNNs, which we will discuss later in this chapter.

Figure 2.1: The networks of interconnected neurons illustrated by Santiago Ramón y Cajal2

This observation of simple neuronal cells interconnected in large networks led computational researchers to hypothesize how mental activity might be represented by simple, logical operations that, combined, yield complex mental phenomena. The original “automata theory” is usually traced to a 1943 article by Warren McCulloch and Walter Pitts of the Massachusetts Institute of Technology (MIT).3 They described a simple model known as the Threshold Logic Unit (TLU