Inhaltsverzeichnis

Alle Kapitel aufklappen
Alle Kapitel zuklappen
Preface
15
Target Group
15
Requirements
15
Structure of the Book
16
How to Use This Book
18
Downloading Code and Additional Materials
18
Preparing the System
19
Installing Python
19
Installing an Integrated Development Environment
20
Installing Git
21
Downloading Course Material
21
Setting Up the Local Python Environment
22
Acknowledgements
24
Conventions Used in This Book
25
1 Introduction to Deep Learning
27
1.1 What is Deep Learning?
27
1.2 What Can You Use Deep Learning For?
28
1.3 How Does Deep Learning Work?
31
1.3.1 Model Training
31
1.3.2 Model Inference
32
1.4 Historical Development
33
1.5 Perceptrons
34
1.6 Network Structure and Layers
34
1.7 Activation Functions
35
1.7.1 Rectified Linear Units
36
1.7.2 Hyperbolic Tangents
37
1.7.3 Sigmoid
37
1.7.4 Softmax
37
1.8 Loss Functions
38
1.8.1 Regression Problems
39
1.8.2 Binary Classification
39
1.8.3 Multiclass Classification
40
1.9 Optimizers and Updating Parameters
40
1.9.1 Optimizers
40
1.9.2 Updating Parameters
41
1.10 Tensor Handling
42
1.10.1 What are Tensors?
43
1.10.2 Coding: Tensor Creation and Attributes
43
1.10.3 Coding: The Calculation Graph and Training
45
1.11 Summary
50
2 Creating Your First PyTorch Model
51
2.1 Data Preparation
51
2.1.1 Feature Types
52
2.1.2 Data Types
54
2.1.3 One-Hot Encoding
54
2.1.4 Exploratory Data Analysis
56
2.1.5 Data Scaling
59
2.2 Model Creation
60
2.2.1 Data Import
61
2.2.2 Model Training
62
2.2.3 Model Evaluation
64
2.2.4 Model Inference
65
2.3 The Model Class and the Optimizer
68
2.4 Batches
72
2.4.1 What Are Batches?
72
2.4.2 Advantages of Using Batches
72
2.4.3 Optimal Batch Size
73
2.4.4 Coding: Implementation of Batches
74
2.5 Coding: Implementation of Dataset and DataLoader
76
2.6 Loading and Saving a Model
80
2.6.1 Saving Model Parameters
80
2.6.2 Loading a Model
81
2.7 Data Sampling
83
2.7.1 What Is Data Sampling?
83
2.7.2 Cross-Validation
85
2.7.3 Why Is Data Sampling Needed?
85
2.7.4 Coding: Separation of Training and Validation Data
86
2.8 Summary
92
3 Classification Models
93
3.1 Classification Types
93
3.2 Confusion Matrix
95
3.3 Receiver Operator Characteristic Curve
97
3.4 Coding: Binary Classification
99
3.4.1 Data Preparation
99
3.4.2 Modeling
104
3.4.3 Evaluation
108
3.5 Coding: Multiclass Classification
112
3.5.1 Data Preparation
113
3.5.2 Modeling
117
3.5.3 Evaluation
121
3.6 Summary
124
4 Computer Vision
127
4.1 How Do Models Handle Images?
128
4.2 Network Architecture
129
4.2.1 Convolutional Neural Networks
130
4.2.2 Vision Transformers
132
4.3 Coding: Image Classification
134
4.3.1 Binary Classification
135
4.3.2 Multiclass Classification
151
4.4 Object Detection
163
4.4.1 How Does Object Detection Work?
164
4.4.2 Data Preparation
165
4.4.3 Model Training
171
4.4.4 Model Evaluation
172
4.4.5 Model Inference
175
4.5 Semantic Segmentation
178
4.5.1 How Does Semantic Segmentation Work?
179
4.5.2 Segmentation Masks
180
4.5.3 Data Preparation
181
4.5.4 Model Training
182
4.5.5 Model Evaluation
186
4.6 Style Transfer
188
4.6.1 How Does Style Transfer Work?
189
4.6.2 Data Preparation
190
4.6.3 Model Training
193
4.6.4 Model Evaluation
196
4.7 Summary
197
5 Recommendation Systems
199
5.1 Theoretical Foundations
199
5.1.1 Basic Concepts
199
5.1.2 Matrix Factorization
201
5.2 Coding: Recommendation Systems
202
5.2.1 Data Preparation
202
5.2.2 Modeling
206
5.2.3 Model Evaluation
209
5.3 Summary
218
6 Autoencoders
219
6.1 Architecture
220
6.2 Coding: Autoencoder
220
6.2.1 Data Preparation
221
6.2.2 Modeling
223
6.2.3 Model Training
226
6.2.4 Model Validation
228
6.3 Variational Autoencoders
230
6.4 Coding: Variational Autoencoder
231
6.4.1 Network Architecture
231
6.4.2 Loss Function
235
6.5 Summary
240
7 Graph Neural Networks
241
7.1 Introduction to Graph Theory
241
7.1.1 Graphs and the Adjacency Matrix
242
7.1.2 Features
243
7.1.3 Passing Messages
244
7.1.4 Use Cases
245
7.2 Coding: Developing a Graph
246
7.3 Coding: Training a Graph Neural Network
250
7.4 Summary
259
8 Time Series Forecasting
261
8.1 Modeling Approaches
261
8.1.1 Special Features of Time Series Models
261
8.1.2 Data Modeling
262
8.1.3 Long Short-Term Memory
263
8.1.4 One-Dimensional Convolutional Neural Networks
264
8.1.5 Transformer
265
8.2 Coding: Custom Model
266
8.2.1 Data Preparation
266
8.2.2 Long Short-Term Memory
271
8.2.3 Convolutional Neural Network
274
8.2.4 Transformers
277
8.3 Coding: Using PyTorch Forecasting
280
8.3.1 Data Preparation
280
8.3.2 Model Training
284
8.3.3 Evaluation
286
8.4 Summary
288
9 Language Models
289
9.1 Using Large Language Models with Python
290
9.1.1 Coding: Using OpenAI
291
9.1.2 Coding: Using Groq
294
9.1.3 Coding: Multimodal Models
297
9.1.4 Coding: Using Large Language Models Locally
300
9.2 Model Parameters
304
9.2.1 Model Temperature
304
9.2.2 Top-p and Top-k
305
9.2.3 Best Practices
307
9.3 Model Selection
307
9.3.1 Performance
307
9.3.2 Cutoff Date
308
9.3.3 On-Premise Versus Cloud Hosting
309
9.3.4 Open-Source, Open-Weight, and Proprietary Models
309
9.3.5 Cost
309
9.3.6 Context Window
310
9.3.7 Latency
310
9.4 Message Types
310
9.4.1 User/Human Messages
310
9.4.2 System Messages
311
9.4.3 Assistant Messages
311
9.5 Prompt Templates
311
9.5.1 Coding: ChatPromptTemplates
312
9.5.2 Coding: Improving a Prompt with LangChain Hub
313
9.6 Chains
315
9.6.1 A Simple Sequential Chain
315
9.6.2 Coding: A Simple Sequential Chain
316
9.7 Structured Outputs
317
9.7.1 What Are Structured Outputs?
317
9.7.2 Coding: Structured Outputs
318
9.8 Deep Dive: How Do Transformers Work?
320
9.8.1 Tokenization
321
9.8.2 Word Embeddings
323
9.8.3 Positional Encoding
324
9.8.4 Attention
325
9.9 Summary
327
10 Pretrained Networks and Fine-Tuning
329
10.1 Pretrained Networks with Hugging Face
329
10.2 Transfer Learning
332
10.2.1 Advantages of Transfer Learning
332
10.2.2 Transfer Learning Approaches
334
10.3 Coding: Fine-Tuning a Computer Vision Model
335
10.3.1 Data Preparation
336
10.3.2 Model Training
339
10.3.3 Model Evaluation
341
10.4 Coding: Fine-Tuning a Language Model
343
10.4.1 Data Preparation
344
10.4.2 Model Training
346
10.4.3 Model Evaluation
348
10.5 Summary
348
11 PyTorch Lightning
351
11.1 PyTorch Versus PyTorch Lightning
351
11.2 Coding: Model Training
352
11.3 Callbacks
359
11.3.1 Model Checkpoints
359
11.3.2 Early Stopping
361
11.4 Summary
362
12 Model Evaluation, Logging, and Monitoring
363
12.1 TensorBoard
363
12.1.1 How It Works
364
12.1.2 Using TensorBoard
364
12.1.3 TensorBoard Dashboard
370
12.2 MLflow
372
12.2.1 Data Logging
373
12.2.2 Saving and Loading the Model
375
12.2.3 MLflow Dashboard
376
12.3 Weights & Biases: WandB
377
12.3.1 Initialization
378
12.3.2 Logging Metrics
379
12.3.3 Logging Artifacts
380
12.3.4 Sweeps
382
12.4 Summary
384
13 Deployment
385
13.1 Deployment Strategies
385
13.2 Local Deployment
387
13.2.1 API Development
388
13.2.2 Deployment
391
13.2.3 Test
391
13.3 Heroku
393
13.3.1 Command Line Interface and Login
393
13.3.2 Deployment
394
13.3.3 Test
397
13.3.4 Stopping and Deleting the App
398
13.4 Microsoft Azure
399
13.4.1 First Steps
399
13.4.2 App Development
401
13.4.3 Local Test
403
13.4.4 Function App Development in the Azure Portal
404
13.4.5 Cloud Deployment
406
13.5 Summary
407
The Author
409
Index
411