Вы находитесь на странице: 1из 67

Productionizing AI: How to Deliver AI

B2B Solutions with Cloud and Python


1st Edition Barry Walsh
Visit to download the full and correct content document:
https://ebookmass.com/product/productionizing-ai-how-to-deliver-ai-b2b-solutions-wit
h-cloud-and-python-1st-edition-barry-walsh/
Productionizing AI
How to Deliver AI B2B Solutions
with Cloud and Python

Barry Walsh
Productionizing AI: How to Deliver AI B2B Solutions with Cloud and Python
Barry Walsh
Ely, UK

ISBN-13 (pbk): 978-1-4842-8816-0 ISBN-13 (electronic): 978-1-4842-8817-7


https://doi.org/10.1007/978-1-4842-8817-7

Copyright © 2023 by Barry Walsh


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: Celestin John Suresh
Development Editor: Laura Berendson
Coordinating Editor: Mark Powers
Cover designed by eStudioCalamar
Cover image by Vackground on Unsplash (www.unsplash.com)
Distributed to the book trade worldwide by Springer Science+Business Media New York, 1 New York Plaza,
Suite 4600, New York, NY 10004-1562, USA. 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 California 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 (github.com/apress). For more detailed information, please visit http://www.apress.com/
source-code.
Printed on acid-free paper
To all those who put up with my whining and those who don't.
Table of Contents
About the Author���������������������������������������������������������������������������������������������������xvii

About the Technical Reviewer��������������������������������������������������������������������������������xix


Preface�������������������������������������������������������������������������������������������������������������������xxi

Prologue���������������������������������������������������������������������������������������������������������������xxiii

Chapter 1: Introduction to AI and the AI Ecosystem������������������������������������������������� 1


The AI Ecosystem�������������������������������������������������������������������������������������������������������������������������� 2
The Hype Cycle������������������������������������������������������������������������������������������������������������������������ 2
Historical Context�������������������������������������������������������������������������������������������������������������������� 3
AI – Some Definitions�������������������������������������������������������������������������������������������������������������� 4
AI Today����������������������������������������������������������������������������������������������������������������������������������� 4
What Is Artificial Intelligence��������������������������������������������������������������������������������������������������� 6
Cloud Computing��������������������������������������������������������������������������������������������������������������������� 7
CSPs – What Do They Offer ?��������������������������������������������������������������������������������������������������� 7
The Wider AI Ecosystem���������������������������������������������������������������������������������������������������������� 9
Full-Stack AI�������������������������������������������������������������������������������������������������������������������������� 10
AI Ethics and Risk: Issues and Concerns������������������������������������������������������������������������������� 11
The AI ecosystem: Hands-on Practise����������������������������������������������������������������������������������� 11
Applications of AI������������������������������������������������������������������������������������������������������������������������ 13
Machine Learning������������������������������������������������������������������������������������������������������������������ 13
Deep Learning����������������������������������������������������������������������������������������������������������������������� 14
Natural Language Processing (NLP)�������������������������������������������������������������������������������������� 16
Cognitive Robotic Process Automation (CRPA)���������������������������������������������������������������������� 17
Other AI Applications������������������������������������������������������������������������������������������������������������� 18
AI Applications: Hands-on Practice���������������������������������������������������������������������������������������� 19

v
Table of Contents

Data Ingestion and AI Pipelines��������������������������������������������������������������������������������������������������� 20


AI Engineering����������������������������������������������������������������������������������������������������������������������� 21
What Is a Data Pipeline?�������������������������������������������������������������������������������������������������������� 21
Extract, Transform, and Load (ETL)���������������������������������������������������������������������������������������� 22
Data Wrangling���������������������������������������������������������������������������������������������������������������������� 22
Performance Benchmarking�������������������������������������������������������������������������������������������������� 23
AI Pipeline Automation – AutoAI�������������������������������������������������������������������������������������������� 24
Build Your Own AI Pipeline: Hands-on Practice��������������������������������������������������������������������� 25
Neural Networks and Deep Learning������������������������������������������������������������������������������������������ 25
Machine Learning������������������������������������������������������������������������������������������������������������������ 26
What Is a Neural Network?���������������������������������������������������������������������������������������������������� 27
The Simple Perceptron���������������������������������������������������������������������������������������������������������� 28
Deep Learning����������������������������������������������������������������������������������������������������������������������� 28
Neural Networks – terminology��������������������������������������������������������������������������������������������� 30
Tools for Deep Learning��������������������������������������������������������������������������������������������������������� 31
Introduction to Neural Networks and DL: Hands-­on Practice������������������������������������������������ 31
Productionizing AI����������������������������������������������������������������������������������������������������������������������� 33
Compute and Storage������������������������������������������������������������������������������������������������������������ 33
The CSPs – Why No-one Can Be Successful in AI Without Investing in
Amazon, Microsoft, or Google������������������������������������������������������������������������������������������������ 34
Containerization�������������������������������������������������������������������������������������������������������������������� 36
Productionizing AI: Hands-on Practice���������������������������������������������������������������������������������� 37
Wrap-up�������������������������������������������������������������������������������������������������������������������������������������� 39

Chapter 2: AI Best Practice and DataOps��������������������������������������������������������������� 41


Introduction to DataOps and MLOps������������������������������������������������������������������������������������������� 42
DataOps��������������������������������������������������������������������������������������������������������������������������������� 42
The Data “Factory”���������������������������������������������������������������������������������������������������������������� 43
The Problem with AI: From DataOps to MLOps���������������������������������������������������������������������� 43
Enterprise AI�������������������������������������������������������������������������������������������������������������������������� 45
GCP/BigQuery: Hands-on Practice����������������������������������������������������������������������������������������� 45
Event Streaming with Kafka: Hands-on Practice������������������������������������������������������������������� 46

vi
Table of Contents

Agile�������������������������������������������������������������������������������������������������������������������������������������������� 47
Agile Teams and Collaboration���������������������������������������������������������������������������������������������� 47
Development/Product Sprints������������������������������������������������������������������������������������������������ 48
Benefits of Agile�������������������������������������������������������������������������������������������������������������������� 50
Adaptability���������������������������������������������������������������������������������������������������������������������������� 50
react.js: Hands-on Practice��������������������������������������������������������������������������������������������������� 51
VueJS: Hands-on Practise����������������������������������������������������������������������������������������������������� 52
Code Repositories����������������������������������������������������������������������������������������������������������������������� 53
Git and GitHub������������������������������������������������������������������������������������������������������������������������ 53
Version Control���������������������������������������������������������������������������������������������������������������������� 54
Branching and Merging��������������������������������������������������������������������������������������������������������� 55
Git Workflows������������������������������������������������������������������������������������������������������������������������ 56
GitHub and Git: Hands-on Practice���������������������������������������������������������������������������������������� 57
Deploying an App to GitHub Pages: Hands-on Practice��������������������������������������������������������� 59
Continuous Integration and Continuous Delivery (CI/CD)������������������������������������������������������������ 60
CI/CD in DataOps������������������������������������������������������������������������������������������������������������������� 60
Introduction to Jenkins���������������������������������������������������������������������������������������������������������� 61
Maven������������������������������������������������������������������������������������������������������������������������������������ 62
Containerization�������������������������������������������������������������������������������������������������������������������� 63
Play With Docker: Hands-on Practice������������������������������������������������������������������������������������ 64
Testing, Performance Evaluation, and Monitoring����������������������������������������������������������������������� 66
Selenium������������������������������������������������������������������������������������������������������������������������������� 66
TestNG����������������������������������������������������������������������������������������������������������������������������������� 67
Issue Management���������������������������������������������������������������������������������������������������������������� 68
Monitoring and Alerts������������������������������������������������������������������������������������������������������������ 70
Jenkins CI/CD and Selenium Test Scripts: Hands-­on Practice���������������������������������������������� 72
Wrap-up�������������������������������������������������������������������������������������������������������������������������������������� 74

Chapter 3: Data Ingestion for AI����������������������������������������������������������������������������� 75


Introduction to Data Ingestion����������������������������������������������������������������������������������������������������� 75
Data Ingestion – The Challenge Today����������������������������������������������������������������������������������� 76
The AI Ladder������������������������������������������������������������������������������������������������������������������������� 76

vii
Table of Contents

Cloud Architectures/Cloud “Stack”���������������������������������������������������������������������������������������� 77


Scheduled (OLAP) vs. Streaming (OLTP) Data������������������������������������������������������������������������ 78
Data Types (Structured vs. Unstructured)������������������������������������������������������������������������������ 80
File Types������������������������������������������������������������������������������������������������������������������������������� 81
Automated Data Ingestion: Hands-on Practice���������������������������������������������������������������������� 82
Working with Parquet: Hands-on Practise����������������������������������������������������������������������������� 83
Data Stores for AI������������������������������������������������������������������������������������������������������������������������ 85
Data Stores: Data Lakes and Data Warehouses��������������������������������������������������������������������� 85
Scoping Project Data Requirements�������������������������������������������������������������������������������������� 87
OLTP/OLAP – Determining the Best Approach����������������������������������������������������������������������� 88
ETL vs. ELT����������������������������������������������������������������������������������������������������������������������������� 88
SQL vs. NoSQL Databases����������������������������������������������������������������������������������������������������� 89
Elasticity vs. Scalability��������������������������������������������������������������������������������������������������������� 90
Data Stores for AI: Hands-on Practice����������������������������������������������������������������������������������� 90
Cloud Services for Data Ingestion����������������������������������������������������������������������������������������������� 92
Cloud (SQL) Data Warehouses����������������������������������������������������������������������������������������������� 92
Data Lake Storage����������������������������������������������������������������������������������������������������������������� 92
Stream Processing and Stream Analytics����������������������������������������������������������������������������� 94
Simple Data Streaming: Hands-on Practise�������������������������������������������������������������������������� 95
Data Pipeline Orchestration – Best Practice������������������������������������������������������������������������������� 97
Storage Considerations��������������������������������������������������������������������������������������������������������� 97
Data Ingestion Schedules������������������������������������������������������������������������������������������������������ 98
Building a Delivery Pipeline������������������������������������������������������������������������������������������������� 100
Data Pipeline Orchestration: Hands-on Practice������������������������������������������������������������������ 106
Wrap-up������������������������������������������������������������������������������������������������������������������������������������ 107

Chapter 4: Machine Learning on Cloud����������������������������������������������������������������� 109


ML Fundamentals��������������������������������������������������������������������������������������������������������������������� 110
Supervised Machine Learning�������������������������������������������������������������������������������������������������� 110
Classification and Regression��������������������������������������������������������������������������������������������� 110
Time Series Forecasting������������������������������������������������������������������������������������������������������ 111
Introduction to fbprophet: Hands-on Practice��������������������������������������������������������������������� 112

viii
Table of Contents

Unsupervised Machine Learning����������������������������������������������������������������������������������������������� 113


Clustering���������������������������������������������������������������������������������������������������������������������������� 113
Dimensionality Reduction���������������������������������������������������������������������������������������������������� 114
Unsupervised Machine Learning (Clustering): Hands-­on Practice�������������������������������������� 114
Semisupervised Machine Learning������������������������������������������������������������������������������������������� 115
Machine Learning Implementation������������������������������������������������������������������������������������������� 115
Exploratory Data Analysis (EDA)������������������������������������������������������������������������������������������������ 116
Data Wrangling�������������������������������������������������������������������������������������������������������������������������� 117
Feature Engineering������������������������������������������������������������������������������������������������������������ 118
Shuffling and Data Partitioning/Splitting����������������������������������������������������������������������������� 119
Sampling����������������������������������������������������������������������������������������������������������������������������� 120
End-to-End Wrangling: Hands-on Practice�������������������������������������������������������������������������� 121
Algorithmic Modelling��������������������������������������������������������������������������������������������������������������� 122
Performance Benchmarking����������������������������������������������������������������������������������������������������� 125
Continual Improvement������������������������������������������������������������������������������������������������������� 127
Machine Learning Classifiers: Hands-on Practice��������������������������������������������������������������� 128
Model Selection, Deployment, and Inference���������������������������������������������������������������������������� 129
Inference: Hands-on Practice���������������������������������������������������������������������������������������������� 130
Reinforcement Learning����������������������������������������������������������������������������������������������������������� 130
Wrap-up������������������������������������������������������������������������������������������������������������������������������������ 131

Chapter 5: Neural Networks and Deep Learning��������������������������������������������������� 133


Introduction to Deep Learning�������������������������������������������������������������������������������������������������� 134
What Is Deep Learning�������������������������������������������������������������������������������������������������������� 134
Deep Learning – Why Now?������������������������������������������������������������������������������������������������ 135
AI and Deep Learning Hype Cycle���������������������������������������������������������������������������������������� 136
High-Level Architectures����������������������������������������������������������������������������������������������������� 137
TensorFlow Playground: Hands-on Practice������������������������������������������������������������������������ 138
Stochastic Processes���������������������������������������������������������������������������������������������������������������� 139
Generative vs. Discriminative���������������������������������������������������������������������������������������������� 139
Random Walks��������������������������������������������������������������������������������������������������������������������� 140

ix
Table of Contents

Markov Chains and Markov Processes�������������������������������������������������������������������������������� 141


Other Stochastic Processes: Martingales���������������������������������������������������������������������������� 141
Implementing a Random Walk in Python: Hands-­on Practice���������������������������������������������� 142
Introduction to Neural Networks����������������������������������������������������������������������������������������������� 143
Artificial Neural Networks (ANNs)���������������������������������������������������������������������������������������� 143
The Simple Perceptron�������������������������������������������������������������������������������������������������������� 144
Multilayer Perceptron (MLP)������������������������������������������������������������������������������������������������ 145
Convolutional Neural Networks (CNN)��������������������������������������������������������������������������������� 146
Recurrent Neural Networks (RNN)��������������������������������������������������������������������������������������� 147
Other Types of Neural Networks������������������������������������������������������������������������������������������ 149
A Simple Deep Learning Solution – MNIST: Hands-­on Practice������������������������������������������� 153
Autoencoders in Keras: Hands-on Practice������������������������������������������������������������������������� 155
Deep Learning Tools������������������������������������������������������������������������������������������������������������������ 156
Tools for Deep Learning������������������������������������������������������������������������������������������������������� 156
TensorFlow�������������������������������������������������������������������������������������������������������������������������� 156
Keras����������������������������������������������������������������������������������������������������������������������������������� 157
PyTorch�������������������������������������������������������������������������������������������������������������������������������� 158
Other Important Deep Learning Tools���������������������������������������������������������������������������������� 158
Frameworks for Deep Learning and Implementation��������������������������������������������������������������� 159
Tensors�������������������������������������������������������������������������������������������������������������������������������� 160
Key TensorFlow Concepts���������������������������������������������������������������������������������������������������� 160
The Deep Learning Modeling Lifecycle�������������������������������������������������������������������������������� 161
Sequential and Functional Model APIs�������������������������������������������������������������������������������� 162
Implementing a CNN������������������������������������������������������������������������������������������������������������ 163
Implementing an RNN��������������������������������������������������������������������������������������������������������� 165
Neural Networks – Terminology������������������������������������������������������������������������������������������ 168
Computing the Output of a Multilayer Neural Network�������������������������������������������������������� 168
Convolutional Neural Networks with Keras and TensorFlow: Hands-on Practice���������������� 170
Recurrent Neural Networks – Time Series Forecasting: Hands-on Practice����������������������� 171
Tuning a DL Model�������������������������������������������������������������������������������������������������������������������� 172
Activation Functions������������������������������������������������������������������������������������������������������������ 172
Gradient Descent and Backpropagation������������������������������������������������������������������������������ 174
x
Table of Contents

Other Optimization Algorithms��������������������������������������������������������������������������������������������� 175


Loss Functions�������������������������������������������������������������������������������������������������������������������� 176
Improving DL Performance�������������������������������������������������������������������������������������������������� 178
Deep Learning Best Practice – Hyperparameters��������������������������������������������������������������� 179
Wrap-up������������������������������������������������������������������������������������������������������������������������������������ 185
Softmax: Hands-on Practice������������������������������������������������������������������������������������������������ 185
Early Stopping: Hands-on Practice�������������������������������������������������������������������������������������� 186

Chapter 6: AutoML, AutoAI, and the Rise of NoLo UIs������������������������������������������� 187


Machine Learning: Process Recap�������������������������������������������������������������������������������������������� 189
Global Search Algorithms���������������������������������������������������������������������������������������������������������� 190
Bayesian Optimization and Inference���������������������������������������������������������������������������������� 191
Bayesian Inference: Hands-on Practice������������������������������������������������������������������������������� 191
Python-Based Libraries for Automation������������������������������������������������������������������������������������ 192
PyCaret�������������������������������������������������������������������������������������������������������������������������������� 192
auto-sklearn������������������������������������������������������������������������������������������������������������������������ 193
Auto-WEKA�������������������������������������������������������������������������������������������������������������������������� 194
TPOT������������������������������������������������������������������������������������������������������������������������������������ 194
Python Automation with TPOT: Hands-on Practice�������������������������������������������������������������� 195
AutoAI Tools and Platforms������������������������������������������������������������������������������������������������������� 196
IBM Cloud Pak for Data�������������������������������������������������������������������������������������������������������� 196
Azure Machine Learning������������������������������������������������������������������������������������������������������ 198
Google Cloud Vertex AI��������������������������������������������������������������������������������������������������������� 199
AWS SageMaker Autopilot��������������������������������������������������������������������������������������������������� 201
TensorFlow Extended (TFX)������������������������������������������������������������������������������������������������� 202
Wrap-up������������������������������������������������������������������������������������������������������������������������������� 203
AutoAI with IBM Cloud Pak for Data: Hands-on Practice����������������������������������������������������� 203
Healthcare diagnostics with Google Teachable Machines: Hands-on Practice������������������� 205
TFX and Vertex AI Pipelines: Hands-on Practice������������������������������������������������������������������ 206
Azure Video Analyzer: Hands-on Practice���������������������������������������������������������������������������� 208

xi
Table of Contents

Chapter 7: AI Full Stack: Application Development���������������������������������������������� 211


Introduction to AI Application Development������������������������������������������������������������������������������ 212
Developing an AI Solution���������������������������������������������������������������������������������������������������� 212
AI Apps – Up and Running��������������������������������������������������������������������������������������������������� 213
APIs and Endpoints�������������������������������������������������������������������������������������������������������������� 214
Distributed Processing and Clusters����������������������������������������������������������������������������������� 215
Virtual Environments����������������������������������������������������������������������������������������������������������� 218
Running Python from Terminal: Hands-on Practice������������������������������������������������������������� 219
API Web Services and Endpoints: Hands-on Practice���������������������������������������������������������� 220
AI Accelerators - GPUs: Hands-on Practise������������������������������������������������������������������������� 221
Software and Tools for AI Development������������������������������������������������������������������������������������ 222
AI Needs Data and Cloud����������������������������������������������������������������������������������������������������� 222
Cloud Platforms������������������������������������������������������������������������������������������������������������������� 225
Python-Based UIs���������������������������������������������������������������������������������������������������������������� 228
Other AI Software Vendors��������������������������������������������������������������������������������������������������� 231
Introduction to Dash: Hands-on Practice����������������������������������������������������������������������������� 232
Flask: Hands-on Practice����������������������������������������������������������������������������������������������������� 233
Introduction to Django: Hands-on Practice�������������������������������������������������������������������������� 233
ML Apps������������������������������������������������������������������������������������������������������������������������������������ 234
Developing Machine Learning Applications������������������������������������������������������������������������� 235
Customer Experience���������������������������������������������������������������������������������������������������������� 236
Fraud Detection and Cybersecurity������������������������������������������������������������������������������������� 237
Operations Management, Decision, and Business Support������������������������������������������������� 237
Risk Management, and Portfolio and Asset Optimization���������������������������������������������������� 238
Developing a Recommendation Engine: Hands-on Practice������������������������������������������������ 238
Portfolio Optimization Accelerator: Hands-on Practise�������������������������������������������������������� 239
DL Apps������������������������������������������������������������������������������������������������������������������������������������� 240
Developing Deep Learning Applications������������������������������������������������������������������������������ 240
Key Deep Learning Apps������������������������������������������������������������������������������������������������������ 242
Full-Stack Deep Learning: Hands-on Practice��������������������������������������������������������������������� 243
Wrap-up������������������������������������������������������������������������������������������������������������������������������������ 245

xii
Table of Contents

Chapter 8: AI Case Studies����������������������������������������������������������������������������������� 247


Industry Case Studies��������������������������������������������������������������������������������������������������������������� 248
Business/Organizational Demand for AI������������������������������������������������������������������������������ 248
AI Enablers�������������������������������������������������������������������������������������������������������������������������� 248
AI Solutions by Vertical Industry������������������������������������������������������������������������������������������ 249
AI Use Cases – Solution Frameworks���������������������������������������������������������������������������������� 249
Solution Architectures��������������������������������������������������������������������������������������������������������� 250
Telco Solutions�������������������������������������������������������������������������������������������������������������������������� 251
Specific Challenges������������������������������������������������������������������������������������������������������������� 252
Solution Categories������������������������������������������������������������������������������������������������������������� 252
Real-time Dashboards��������������������������������������������������������������������������������������������������������� 253
Sentiment Analysis�������������������������������������������������������������������������������������������������������������� 255
Predictive Analytics������������������������������������������������������������������������������������������������������������� 256
Connecting to the Twitter API from Python�������������������������������������������������������������������������� 257
Twitter API and Basic Sentiment Analysis: Hands-­on Practice�������������������������������������������� 258
Retail Solutions������������������������������������������������������������������������������������������������������������������������� 259
Challenges in the Retail Industry����������������������������������������������������������������������������������������� 259
Churn and Retention Modelling������������������������������������������������������������������������������������������� 260
Online Retail Predictive Analytics with GCP BigQuery: Hands-on Practice�������������������������� 262
Predicting Customer Churn: Hands-on Practise������������������������������������������������������������������ 263
Social Network Analysis: Hands-on Practise����������������������������������������������������������������������� 264
Banking and Financial Services/FinTech Solutions������������������������������������������������������������������ 265
Industry Challenges������������������������������������������������������������������������������������������������������������� 265
Fraud Detection������������������������������������������������������������������������������������������������������������������� 267
AWS Fraud Detection with AWS SageMaker: Hands-­on Practice���������������������������������������� 269
Supply Chain Solutions������������������������������������������������������������������������������������������������������������� 271
Challenges Across Supply Chains��������������������������������������������������������������������������������������� 271
Predictive Analytics Solutions��������������������������������������������������������������������������������������������� 272
Supply Chain Optimization and Prescriptive Analytics�������������������������������������������������������� 273
Supply Chain Optimization with IBM CloudPak/Watson Studio: Hands-on Practice������������ 274

xiii
Table of Contents

Oil and Gas/Energy and Utilities Solutions�������������������������������������������������������������������������������� 276


Challenges in Energy, Oil, and Gas Sectors������������������������������������������������������������������������� 276
AI Solutions in Energy – An Opportunity or a Threat?���������������������������������������������������������� 276
Healthcare and Pharma Solutions��������������������������������������������������������������������������������������������� 278
Healthcare – The AI Gap������������������������������������������������������������������������������������������������������ 278
Healthcare and Pharma Solutions��������������������������������������������������������������������������������������� 279
HR Solutions������������������������������������������������������������������������������������������������������������������������������ 279
HR in 2002��������������������������������������������������������������������������������������������������������������������������� 280
Sample HR Solutions����������������������������������������������������������������������������������������������������������� 281
HR Employee Attrition: Hands-on Practice�������������������������������������������������������������������������� 283
Other Case Studies������������������������������������������������������������������������������������������������������������������� 284
Public Sector and Government�������������������������������������������������������������������������������������������� 284
Manufacturing��������������������������������������������������������������������������������������������������������������������� 285
Cybersecurity���������������������������������������������������������������������������������������������������������������������� 285
Insurance/Telematics���������������������������������������������������������������������������������������������������������� 286
Legal������������������������������������������������������������������������������������������������������������������������������������ 286
DALL-E for the Creative Arts: Hands-on Practise����������������������������������������������������������������� 287
Wrap-up������������������������������������������������������������������������������������������������������������������������������������ 288

Chapter 9: Deploying an AI Solution (Productionizing and Containerization)������ 289


Productionizing an AI Application���������������������������������������������������������������������������������������������� 290
Typical Barriers to Production��������������������������������������������������������������������������������������������� 290
Cloud/CSP Roulette������������������������������������������������������������������������������������������������������������� 291
Simplifying the AI Challenge – Start Small, Stay Niche������������������������������������������������������� 292
Database Management in Python: Hands-on Practice�������������������������������������������������������� 294
App Building on GCP: Hands-on Practice����������������������������������������������������������������������������� 295
PowerBI – Python Handshake: Hands-on Practice�������������������������������������������������������������� 296
AI Project Lifecycle�������������������������������������������������������������������������������������������������������������������� 296
Design Thinking Through to Agile Development������������������������������������������������������������������ 296
Driving Development Through Hypothesis��������������������������������������������������������������������������� 297
Collaborate, Test, Measure, Repeat�������������������������������������������������������������������������������������� 298
Continual Process Improvement������������������������������������������������������������������������������������������ 299

xiv
Table of Contents

Data drift������������������������������������������������������������������������������������������������������������������������������ 300


Automated Retraining���������������������������������������������������������������������������������������������������������� 301
Hosting on Heroku – End-to-End: Hands-on Practice���������������������������������������������������������� 302
Enabling Engineering and Infrastructure���������������������������������������������������������������������������������� 303
The AI Ecosystem – The AI Cloud Stack������������������������������������������������������������������������������� 303
Data Lake Deployment – Best Practice������������������������������������������������������������������������������� 304
Data Pipeline Operationalization and Orchestration������������������������������������������������������������ 305
Big Data Engines and Parallelization���������������������������������������������������������������������������������������� 307
Dask������������������������������������������������������������������������������������������������������������������������������������ 307
Leveraging S3 File Storage: Hands-on Practise������������������������������������������������������������������ 308
Apache Spark Quick Start on Databricks: Hands-on Practice��������������������������������������������� 309
Dask Parallelization: Hands-on Practice������������������������������������������������������������������������������ 310
Full Stack and Containerization…the final frontier������������������������������������������������������������������ 311
Full Stack AI – React and Flask Case Study������������������������������������������������������������������������ 311
Deploying on Cloud with a Docker Container���������������������������������������������������������������������� 312
Implementing a Continuous Delivery Pipeline��������������������������������������������������������������������� 313
Wrap-up������������������������������������������������������������������������������������������������������������������������������� 314
DL App deployment with Streamlit and Heroku: Hands-on Practice����������������������������������� 314
Deploying on Azure with a Docker Container: Hands-on Practice��������������������������������������� 315

Chapter 10: Natural Language Processing����������������������������������������������������������� 319


Introduction to NLP������������������������������������������������������������������������������������������������������������������� 320
NLP Fundamentals�������������������������������������������������������������������������������������������������������������� 320
NLP Goals and Sector-specific Use Cases��������������������������������������������������������������������������� 322
The NLP Lifecycle���������������������������������������������������������������������������������������������������������������� 323
Creating a Word Cloud: Hands-on Practice�������������������������������������������������������������������������� 327
Preprocessing and Linguistics�������������������������������������������������������������������������������������������������� 328
Preprocessing/Initial Cleaning��������������������������������������������������������������������������������������������� 328
Linguistics and Data Transformation����������������������������������������������������������������������������������� 329
Text Parsing with NLTK: Hands-on Practice������������������������������������������������������������������������� 335

xv
Table of Contents

Text Vectorization, Word Embeddings, and Modelling in NLP���������������������������������������������������� 336


Rule-Based/Frequency-Based Embedding�������������������������������������������������������������������������� 337
Word Embeddings/Prediction-Based Embedding���������������������������������������������������������������� 340
NLP Modeling���������������������������������������������������������������������������������������������������������������������� 342
Word Embeddings: Hands-on Practice�������������������������������������������������������������������������������� 345
Seq2Seq: Hands-on Practice����������������������������������������������������������������������������������������������� 346
PyTorch NLP: Hands-on Practice����������������������������������������������������������������������������������������� 347
Tools and Applications of NLP��������������������������������������������������������������������������������������������������� 348
Python Libraries������������������������������������������������������������������������������������������������������������������� 349
NLP Applications������������������������������������������������������������������������������������������������������������������ 350
NLP 2.0�������������������������������������������������������������������������������������������������������������������������������� 353
Wrap-up������������������������������������������������������������������������������������������������������������������������������� 355
WATSON Assistant Chatbot/IVA: Hands-on Practice������������������������������������������������������������ 355
Transformers for Chatbots: Hands-on Practice������������������������������������������������������������������� 357

Postscript������������������������������������������������������������������������������������������������������������� 359

Index��������������������������������������������������������������������������������������������������������������������� 363

xvi
About the Author
Barry Walsh is a software delivery consultant and AI trainer at Pairview with a
background exploiting complex business data to optimize and de-risk energy assets
at ABB/Ventyx, Infosys, E.ON, Centrica, and his own start-up ce.tech. Certified as an
Azure AI Engineer and Data Scientist as well as an AWS Cloud Practitioner, he has a
proven track record of providing consultancy services in Data Science, BI, and Business
Analysis to businesses in Energy, IT, FinTech, Telco, Retail, and Healthcare, Barry has
been at the apex of analytics and AI solutions delivery for over 20 years. Besides being
passionate about Enterprise AI, Barry spends his spare time with his wife and 8-year-old
son, playing the piano, riding long bike rides (and a marathon on a broken toe this year),
eating out whenever its possible or getting his daily coffee fix.

xvii
About the Technical Reviewer
Pramod Singh works at Bain & Company as a Senior Manager, Data Science, in their
Advanced Analytics group. He has over 13 years of industry experience in Machine
Learning (ML) and AI at scale, data analytics, and application development. He has
authored four other books including a book on Machine Learning operations. He is also
a regular speaker at major international conferences such as Databricks AI, O’Reilly’s
Strata, and other similar conferences. He is an MBA holder from Symbiosis International
University and a data analytics certified professional from IIM Calcutta. He lives in
Gurgaon with his wife and five-year-old son. In his spare time, he enjoys playing the
guitar, coding, reading, and watching football.

xix
Preface
When Barry approached me to write a preface for this book, it filled me with delight,
not just because I was writing a preface for his new book, although it is always nice to be
asked, but primarily because I was being asked by someone who I have watched flourish
under my leadership at Pairview for the last few years.
The work we do at Pairview has helped shape thousands of fledgeling careers across
the UK and around the world for more than thirteen years at the time of writing. Fresh
graduates struggling to find high value jobs, returning to work mums who want flexible
work with high pay, and those who have reached the end of a career cycle and have no
real prospect for further growth have all turned to Pairview to kickstart their careers.
The company was created to help close the talent gap that was growing in the data
space. This gap has since spread to most other aspects of technology as new technology
innovation comes around and companies continue to grapple with the ultimatum to
adopt technology-induced change or sink.
Barry’s passion for Artificial Intelligence combined with his vast knowledge of
the subject matter and the work he has done for our numerous clients over the years
makes him an authority on the subject. Barry has acquired first-hand exposure to the
opportunities, challenges and the risks associated with AI ecosystems and development
processes. He knows what it takes to get buy-ins and drive organisation wide-adoption of
AI capabilities and the business impact. Barry has over the years become an evangelist of
the value of AI to business while being fully aware of the enormous investment of time,
resources and scrutiny required to get AI right first time and drive it through the digital
transformation value chain.
Although Artificial intelligence has been with us for many decades, in recent times
new capabilities have emerged in the constellation; enabling more complexity in
sensing, comprehending, acting and learning with human-like levels of intelligence.
With mathematical technologies like machine learning and natural language
processing the landscape of AI continues to expand and increasingly co-exist with
humans, enabling businesses to dare to digitalise with never-before levels of accuracy,
consistency and availability. A combination of data analytics, machine learning and

xxi
Preface

deep learning embedded with ever-more powerful computing power such as quantum
and edge, AI is being used to deliver next generation capabilities across all aspects of
human reach.
While we have seen many organisations invest quite heavily in machine learning
and analytics capabilities, bringing the insight and models from machine learning
developments into production continues to pose a significant challenge for many
business leaders, particularly CDOs, CEOs and Data and AI leads responsible for
the embedding and delivery or AI enabled products to markets at the speed and
scale required for success. This is why this book is a must read for leaders of these
organisations, programmes or products. It provides a strong framework for planning,
developing and deploying enterprise AI to production at scale.

Frank Abu
Director
Pairview Limited

xxii
Prologue
Out of a wasteland of failed Data Science projects and mounting technical debt,1
organizations today are attempting to redress the AI landscape and enforce a broader,
more considered Design/System Thinking approach which cuts through the hype. The
imperative is to ensure that Data/AI solutions are built with multiuser engagement at the
outset (both technical and nontechnical) and have system-wide ecosystem, enterprise
data center, infrastructure/integration, and end-to-end process in mind.
Applications of Artificial Intelligence leveraging the latest technological advances are
firmly at the top of this hype cycle.2 With the productivity benefits of AI difficult to ignore,
Covid and galloping digitalization have given rise to a vicious culture of disruption, the
accelerated uptake forcing fragile companies to build or buy solutions cheaper, smaller,
and more open sourced. This convergence of forces means that demand for rapid
prototyping and accelerated AI solution delivery is high.
At the same time, not every company is cognizant of what AI can do, or what it
means. Often these are corporates burdened by legacy tools and poor innovation
practices. Some are fearful of the impact on jobs; others have ethical concerns. But what
has become clear for most C-Levels is that AI implementation must fit an “Enterprise AI”
vision – a $341b market3 – and the prevalent trend is toward a platform of disparate but
highly integrated “best-of-breed” AI solutions.
For many of us where data and digital are inextricably tied up in our professional
life and associated opportunities in the job market, these meaningful, high-value AI
solutions are what employers are targeting. And the constant focus on delivering an
Return On Investment (ROI) – understanding and, more importantly, delivering tangible
outcomes using AI, typically machine and deep learning – is what keeps us employed.

1
The rush to digital means 60% of businesses (in Europe and globally) will find themselves with
more technical debt post-pandemic, not less (Source: Forrester).
2
https://www.gartner.com/en/articles/what-s-new-in-artificial-intelligence-from-
the-2022-gartner-hype-cycle. See also https://tinyurl.com/3c7pcpfm
3
www.idc.com/getdoc.jsp?containerId=prUS48127321

xxiii
Prologue

This can be exhausting and part of the challenge for business leaders is that
highly technical skillsets have never led to particularly visual, communicable (and
understandable) results for the rest of the organization – most Data Scientists are
not good at BI or recruited for their soft skills. Employers in the job market today are
increasingly looking for more rounded/broader “end-to-end” skills which translate
to better visualization, front-end features, and integration. The opportunity for
Data Professionals is to give themselves an “edge” by addressing technical debt and
possessing the ability to deliver full-stack data solutions.
A great deal of this “opportunity” depends on cloud computing; AI or Data Science
is not just a Python notebook and a flip chart – it demands identifying and ingesting
suitable datasets and leveraging services on cloud to scale from sandbox to proof-of-­
concept to prototype to minimum viable product. Ultimately today it is Enterprise AI that
most companies and organizations are targeting. But for many individuals employed
in roles and for many noncorporate companies, leveraging cloud is a minefield of
sometimes unclear, poorly documented artifacts and hidden costs. Enterprise AI is far
from affordable.
Successful (and affordable) Enterprise AI project delivery requires a healthy amount
of Emotional Intelligence,4 an agile mindset, robust data-fed pipelines and a whole lot
of workarounds to design, scope, and achieve integration across people, processes, and
tools – with all of us dependent on the three main hyperscalers/cloud service providers
(CSPs): Amazon Web Services, Microsoft Azure, and Google Cloud Platform,5 bound to
their data centers, scalable storage, and compute instances.
Agile is important, but so are hybrid/agnostic solutions, multiskill, T-shaped
capabilities, and results-based delivery. Above all, senior stakeholders/managers should
not be taking credit for being spiderman or spiderwoman implementing “agile” project
methodologies if they are just orchestrating chaos or spinning webs that attribute project
failures/blame elsewhere. Agile only works if it follows project design through to a
standard of delivery which meets the overall project vision, not if under the surface it’s
just a pile of shit.6

4
Amit Ray: “as more and more artificial intelligence is entering into the world, more and more
emotional intelligence must enter into leadership.”
5
All firmly in the world’s top 10 companies by market capitalization:
https://companiesmarketcap.com/
6
Forrester: “while investments in automation will continue to rise rapidly across Europe, many
companies have historically lacked a coherent data/AI strategy, with a patchwork of siloed digital
services that have left their IT function in a mess and customers frustrated.”

xxiv
Prologue

With many organizations struggling to operationalize AI, this book is intended to


go a step beyond a simple Python scripting and address the “so what” of current Data
Science delivery.
This doesn’t mean python is passed over – far from it. Python skills are more than
ever in demand in the workplace, with popularity up in September 2022 and still number
1 on the TIOBE Programming Community index.7 Developing in Python is central to
the aims of this book but here we take a top-down, “goal-focused” approach, preferring
Python-based and low-code frameworks for accelerating the full-stack development
process, rather than stream of consciousness Python back-ends. The narrative of
the book is also aligned with DataOps best practice and an awareness of meeting
KPIs around shifting requirements, slipped schedules, flexibility improvements, and
disappointed users.
Hands-on labs are populated throughout the book and are intended to present
“how-to” examples, not just utilizing Python code, but as much with critical cloud
services for AI and no-/low-code interfaces for key nontechnical stakeholders, often the
main decision makers in whether to commission, implement, or scale an AI project.
Enterprise AI is about embedding AI into an organization’s data strategy, and
an entire workforce needs to be aligned and trained on a company’s tangible (and
intangible/hidden) data and AI assets. Everyone therefore should get to use and
understand AI, and by developing the solutions in this book it is hoped the reader is
better equipped to deliver a company’s “bigger picture” goals.

7
www.tiobe.com/tiobe-index/

xxv
CHAPTER 1

Introduction to AI and
the AI Ecosystem
In the age of the Fourth Industrial Revolution that we live in today, AI is a central focus
of innovation, along with IoT and genetic engineering among others. But it comes with
a lot of hype, in particular in relation to job loss and job creation as much of the world’s
businesses and organizations hyperspeed transforming their operational model in
the Digital Age. Much of the job creation is centered around the booming career of the
Data Scientist, a role which has really only been mainstream since about 2012. But the
role itself and the scope of skills it entails has not always evolved in that relatively short
period of time to accommodate growing needs across a company’s key assets: people,
processes, and tools. In particular, much money and time has been spent on poorly
planned Data Science projects where nothing other than an R or Python script has been
developed, often with highly sophisticated coding, but of which very few people in the
organization are cognizant. In effect, while these solutions may be robust and relatable
to a group of Data Scientists, they are not “fit for purpose” in a large organizational/
enterprise-wide structure with many different people, processes, and tools interfacing
and competing for internal budgets.
This chapter introduces our take on the current mismatch in capabilities and
requirements through the lens of those topics which we consider most relevant to the
successful delivery of an AI project today.
The goal of this chapter, from an initial whistle-stop historical tour, is to define key
AI concepts at a fairly high level and introduce the reader to current and emerging
trends in AI, including the hype and the pitfalls. Ultimately the chapter leads to how
many businesses and organizations are struggling to get machine and deep learning
operationalized in today’s workplaces. The topics discussed in this chapter are then
elaborated in greater detail in the subsequent chapters.

1
© Barry Walsh 2023
B. Walsh, Productionizing AI, https://doi.org/10.1007/978-1-4842-8817-7_1
Chapter 1 Introduction to AI and the AI Ecosystem

In this chapter, we will scratch the surface first, before embarking on the more
involved hands-on practice and applications of later chapters. The intention is to provide
readers with the tools in this chapter to go forward, providing concise context and
definitions around the AI Ecosystem, the main applications of AI, data ingestion and
data pipelines, and machine and deep learning with neural networks before wrapping
up on productionizing AI.

The AI Ecosystem
Our first section sets the scene for AI today – starting with a look at the hype cycle before
a retrospective on how AI has evolved to this stage. We also introduce some definitions,
cloud computing as the enabler for scalable AI, the ecosystem for “full-stack” AI, and
discuss growing ethical concerns.

The Hype Cycle


While there is considerable hype around AI, it is generally perceived as now delivering
on its potential. The benefits for businesses and organizations are tangible, accelerated
by Covid-digitalization and evidenced by the proliferation of chatbot support during the
pandemic, deep-learning supported healthcare diagnostics, usage of computer vision
for social-distancing measures, and machine learning modeling of the effects from
reopening economies.
In the workplace, while AI is maturing as a service, application has largely involved
only a handful of IT experts. Democratization of AI is a big focus in 2022 and shifting
from expert/niche knowledge to achieving buy-in across the wider ecosystem of key
stakeholders (all employees, customers, and business partners). Industrialization of AI is
also a dominant trend today with employers pushing for “smarter” implementation of AI
projects; focusing on reusability, scalability, and safety of AI at a Design Thinking stage,
rather than as an afterthought.
We start this first section with a look at how Artificial Intelligence has evolved and
matured into this current status quo best encapsulated by a need to scale up from
“standalone AI” to “Enterprise AI.”

2
Chapter 1 Introduction to AI and the AI Ecosystem

H
 istorical Context
Depending on your perspective, Artificial Intelligence has its roots in the age of
computing in the 1950s or in the “automata” of ancient philosophy.
Modern AI probably originated in classical philosophy in references to human
thought as a mechanical process so before we start, it's useful to establish some of this
context for AI today.1 Table 1-1 provides an overview of Artificial Intelligence’s evolution.

Table 1-1. The evolution of Artificial Intelligence


Date Event

5th century BC First records of mechanical robots: Chinese Daoist Philosopher Lao Tzu
accounts of a life-sized, human-shaped mechanical automaton
c. 428–347 BC Greek scientists create “automata” – specifically Archytas creates a
mechanical bird
9th century First recorded programmable complex mechanical machine
1833 Charles Babbage conceives an Analytical Engine – a programmable calculating
machine
1872 Samuel Butler’s novel Erewhon includes the notion of machines with
human-like intelligence
1st half of 20th Science Fiction awareness of AI (Tin Man in Wizard of Oz, Maria robot double in
century Metropolis)
1950 Alan Turing publishes Computing Machinery and Intelligence – asking “Can
machines think?” – or “can machines successfully imitate thought?”
1956 MIT cognitive scientist Marvin Minsky coins the term “Artificial Intelligence”
1974–1993 Long AI “Winter” – lack of tangible commercial success and poor performance
of neural networks lead to reduced funding from governments
1997 IBM's Deep Blue defeats Garry Kasparov at Chess
2011 IBM Watson wins the quiz show "Jeopardy!"
2012 ImageNet competition – AlexNet Deep Neural Networks result in significant
reduction in error in visual object recognition

1
www.forbes.com/sites/gilpress/2016/12/30/a-very-short-history-of-artificial-
intelligence-ai/?sh=1cfaac1f6fba

3
Chapter 1 Introduction to AI and the AI Ecosystem

AI – Some Definitions


Whether we consider a philosophical automaton or a thinking machine as real “AI” is up
for debate but what we can make use of, with the benefit of hindsight, are specific terms
to understand and articulate Artificial Intelligence

Terminology Description Example

Simple A device that does work (transfer of energy Wheels, levers, pulleys, inclined
machine from one object to another) planes, wedges, and screws
Complex Combinations of simple machines Wheelbarrow, bicycle, mechanical
machines robot (Lao Tzu, mechanical bird)
Programmable Receive input, store and manipulate data, Punched cards, encoded music
machines and provide output in a useful format rolls
Calculating Mechanical device used to perform Abacus, slide rule, difference
machines automatically the basic operations of engine, calculator
arithmetic
Digital Systems that generate and process binary Computers
machines data

On a timeline, Figure 1-1 shows how this looks.

Figure 1-1. A timeline of AI’s evolution

AI Today
While the question of “what is AI” may be less clear (we will address this in the next
section), without Digital Machines or Computers we certainly wouldn’t be talking about
AI – and as we will see shortly, ultimately it’s the growth of cloud computing and the
high-performance computing that comes with it that have enabled AI or democratic AI.
4
Chapter 1 Introduction to AI and the AI Ecosystem

When we look at the mechanics and, in particular, the applied use cases of AI
today, Machine and Deep Learning are the underpinning techniques of real Artificial
Intelligence, rather than any misconceived ideas about a “rise of the machines” partly
based on ignorance, part science fiction. AI in the job-world stands for Augmented
Intelligence and no-one really wants to see Artificial General Intelligence in the same
way as no-one (hopefully) wants a third world war.

Machine Learning
As shown in Figure 1-2, Machine Learning can be thought of as a subset of AI giving
computers the ability to learn without being explicitly programmed. Operationally,
machine learning is much like how humans learn from experience, that is, if we touch
something hot and get burnt, the negative experience is stored in memory and we
quickly learn not to touch it again.
We feed a computer data, which represents past experience, and then with the use
of different statistical methods, we “learn” from the data and apply that knowledge to
future events – these are our model “predictions.”

Deep Learning
Deep Learning is often considered a subset of Machine Learning and is distinguished by
the fact that deep neural network layers are used to solve predictive problems.
Because of their reliance on Big data and Modelling, all of AI, Machine, and Deep
Learning are core techniques for Data Science which combines modeling, statistics,
programming, and some domain expertise to extract insights and value from data.

5
Chapter 1 Introduction to AI and the AI Ecosystem

Figure 1-2. Deep Learning as a subset of AI (Source: Abris AI in Banking 2)

What Is Artificial Intelligence


The Artificial Intelligence with which we are concerned with in this book is often
confused with the science fiction variety. How do we distinguish the two?
Narrow AI is the current form of AI used in business and organizations, that is,
where a machine is designed to perform a single task. The machine gets very good at
performing that particular task (such as e.g. Google Translate) but once the machine is
trained, it does not generalize to unseen domains.
Artificial General Intelligence (AGI) is the form of AI that can accomplish any
human intellectual task, with underlying “conscious” decision making. Although it may
constitute an existential threat, it does remain, for now, aspirational due to challenges
including scaling of hardware, energy consumption, and catastrophic memory loss
which also affects some of the advanced deep learning algorithms today.
Artificial Superintelligence or ASI is the form of AI most close to that used in
science fiction movies. ASI in theory has capability more than that of humans.

2
www.abrisconsult.com/artificial-intelligence-and-data-science/

6
Chapter 1 Introduction to AI and the AI Ecosystem

C
 loud Computing
So we are concerned with Narrow AI, at least for now, and by the time AGI or ASI comes
around, if we are to believe Elon Musk, we should all hope we are gone.
As mentioned above, the enabler for this form of AI is cloud and successful Narrow
AI implementation requires an end-to-end Cloud Infrastructure. It is difficult to
underestimate the degree to which cloud computing is a fundamental requirement for
any business in 2022. Growth has been explosive with a 33% increase in cloud spend in
2020 driven by intense demand to support remote working and learning, ecommerce,
content streaming, online gaming, and collaboration.
Storage and Compute Power are the main Cloud components used for Big Data
handling central to AI. While Enterprise Machine Learning projects can run with low
overheads on both, Deep Learning projects cannot. Amazon Web Services, Azure, and
Google Cloud Platform are the major (“Big Three”) cloud service providers (or CSPs),
with IBM Cloud and Heroku also used.3 We will cover hands-on examples of all of these
in this book. All CSPs provide a catalog of AI services and tools which greatly simplify the
process of building applications.
While cloud is the key enabler of AI, cloud computing only really works for
Enterprise, or production-grade AI if the company’s Data Strategy is underpinned by
rich, BIG data sources and/or training data.

CSPs – What Do They Offer ?


Each of the CSPs has clear differentiators over the others. AWS has the greatest reach,
while Azure naturally interfaces well with Windows-based systems. Google Cloud
Platform tends to have better support for app-building, as depicted in Figure 1-3.

3
Ali Baba is the fourth biggest cloud service provider but for now largely confined to the
Chinese market

7
Chapter 1 Introduction to AI and the AI Ecosystem

Figure 1-3. The leading cloud platforms Q222 (Source: Statista)

Summarized in Figure 1-4 are some of the additional USPs of each of the main cloud
platforms.

Figure 1-4. USPs for cloud service providers

8
Chapter 1 Introduction to AI and the AI Ecosystem

The Wider AI Ecosystem


Despite the dominance of the Big Three CSPs, some companies are starting to move
away or influenced by Consultant/SIs away from Big Tech “lock-in” and toward a
platform of multivendor, niche AI solutions. These open source, cheaper platforms can
also be quicker to implement, are more closely coupled with agile delivery models (more
on this in Chapter 2), and are somewhat unburdened by legacy, size, or corporate social
responsibility (CSR).

Figure 1-5. Supporting the wider AI Ecosystem – CSPs, Sis, and OEMs

9
Chapter 1 Introduction to AI and the AI Ecosystem

F ull-Stack AI
It's not all about cloud of course. While cloud provides the platform, a whole host of
proprietary and open-sourced tools are used to implement AI from data engineering
tooling such as Apache Kafka or AWS Kinesis to NoSQL databases such as mongoDB
and AWS DynamoDB through back-end programming languages like Python and Scala4
coupled with model engines like Apache Spark and front-end BI layers/dashboards like
Dash, PowerBI, and Google Data Studio.

Figure 1-6. Full-Stack AI

We will be using many of the above in our hands-on examples in this book.

4
other languages such as R and Go / Golang are of course also used for Data Science, but are
some way off the popularity and spread of Python at the moment. We will however touch on Scala
further in Chapters 3 and 9.

10
Chapter 1 Introduction to AI and the AI Ecosystem

AI Ethics and Risk: Issues and Concerns


A final word on this first section in this chapter should be reserved for what is rapidly
becoming a growing fear in many larger organizations today – the ethical use of data and
AI to drive business value.
Many problems today stem from overly hyped early years of commercial AI
development where issues around data bias, model risk, “black-box” auditability, and
even user consent were largely ignored in order to generate ROI from the outcomes.
Following some high-profile cases in the media, there is a negative perception that
the inherent bias in an AI model coupled with the overreliance on automation can
discriminate or set poverty traps for the poor. There are in effect two main algorithmic
“webs” outlined below:
Credit-reporting algorithms – these affect access to private goods and services
like cars, homes, and employment. Of concern are potential ethical breaches such as
the Apple Card case where Goldman Sachs (as the card operator) was investigated by
regulators5 for using an AI algorithm that allegedly discriminated against women by
granting larger credit limits to men.
Government/public sector agencies – here AI algorithms impact access to public
benefits like healthcare, unemployment, and child support services. Another recent
case in the United States saw UnitedHealth investigated by regulators for creating an
algorithm with racial basis toward white patients over sicker black patients.

The AI ecosystem: Hands-on Practise


AI Ethics and Governance brings to an end our first section in this introductory chapter
but in order to get to grips with some of the outcomes from an AI project, its worthwhile
taking a look at an important tool from the wider AI ecosystem.

CREATING A COVID DASHBOARD WITH POWERBI

All good AI solutions require a visualisation / business intelligence (BI) layer to ensures
solutions are delivered with a compelling dashboard or interface to a dashboard. There are
many such tools used for this purpose including AWS QuickSight, Google Data Studio, Cognos,

5
See, for example, www.standard.co.uk/tech/apple-card-sexist-algorithms-goldman-sachs-
credit-limit-a4283746.html

11
Chapter 1 Introduction to AI and the AI Ecosystem

Tableau and Looker6. Here we take a look at Microsoft PowerBI – one of the leading BI tools at
the moment.

1. Accept cookies and sign up and download PowerBI from the link below:
https://powerbi.microsoft.com

2. Google “John Hopkins Covid data GitHub” to find the latest GitHub data
from John Hopkins University. For reference the live csv files for confirmed,
recovered and mortality cases are at the link below:
https://github.com/CSSEGISandData/COVID-19/tree/master/csse_
covid_19_data/csse_covid_19_time_series

3. Open PowerBI and Go to Get Data > Web. Enter the url for each of the three files
separately, selecting “Load Data” to import the data to the PowerBI data model

NB as the link is to the “live” files, the data shown in the visuals below will
automatically update each day

4. Exercise: In the Explorer view of PowerBI recreate the visuals shown in the
example dashboard at the link below:
https://app.powerbi.com/view?r=eyJrIjoiN2FkNzZlMWQtMm
E2OC00NzRiLWI0ZGItNDMzNzZhYTIwYTViIiwidCI
6IjhlYTkwMTE5LWUxYzQtNDgyNC05Njk2LTY0NzBjYmZiMjRlNiJ9

5. Make sure to create the visuals one by one by:

a. Selecting the correct visual (e.g. card, table, bar chart, area chart, tree chart)

b. Dragging and dropping the correct dimensions (entities to report on e.g.


country) and measures (values to report on e.g. confirmed cases)

c. Filter if necessary, e.g. on top 10 cases

d. Finally add slicers on date and country to allow a user to quickly drill-down
into Covid cases by date (window) and country

6. Exercise (Stretch) – push the finished PowerBI report to PowerBI Service7, then
proceed to host your dashboard on a public url

6
And DS.js and Apache Superset. We will look into more Python-specific visualisation tools in
Chapter 7 AI Application Development

12
Chapter 1 Introduction to AI and the AI Ecosystem

A
 pplications of AI
Taking the context from the previous section and in keeping with the light introductory
nature of this first chapter, we will now address in the next section the main AI
applications:
• Machine Learning

• Deep Learning including Computer Vision and Portfolio, Risk


Management and Forecasting
• NLP including Chatbots

• Cognitive Robotic Process Automation (CRPA)

M
 achine Learning
Machine Learning is a technique enabling computers to make inferences from complex
data and remains the biggest area of AI research today. There are three main types:
Supervised, Unsupervised, and Reinforcement Learning,8 the development and
deployment of each we will look at in subsequent chapters. For now, we have provided
some basic definitions focused on the inherent difference between these machine
learning approaches:
Supervised – training on datapoints where the desired “target” output is known
Unsupervised – no outputs available but machine learning is used to identify
patterns in data
Reinforcement learning – training a machine learning model by maximizing a
reward/score
A key application of machine learning today is in Fraud Detection, which is often run
as both an unsupervised ML and supervised ML problem. The goal is to try and predict
patterns in transactional (and customer) data that indicate fraud is taking place.

7
PowerBI Service requires an organisational email. For assistance on see https://dash-bi
.medium.com/how-to-use-power-bi-service-for-free-without-a-professional-email-
in-4-steps-f97dbaf4c51e or https://learn.microsoft.com/en-us/power-bi/fundamentals/
service-self-service-signup-for-power-bi
8
Four if a semi-supervised approach is used – see Chapter 4

13
Chapter 1 Introduction to AI and the AI Ecosystem

It is assumed that most readers are familiar in some way with basic Machine
Learning techniques and would direct readers to other books to augment their
understanding in case some of the applications discussed in this book go beyond
assumed knowledge.

Deep Learning
In many ways Deep Learning is a subset of Machine Learning; essentially extending
Machine Learning to hard, “Big Data” problems typically solved using neural networks.
Neural networks themselves are inspired by neuron connections in the human brain –
when put together we get something like the image on the right (a). This is in fact a
multilayer neural network taking four inputs and providing one output after various data
transformations carried out within the two “hidden” layers of four nodes (or neurons) each.

Figure 1-7. Multilayer PerceptronComputer Vision

Deep Learning is commonly used in Image Classification or Computer Vision (such


as predicting whether an image contains people, buildings, or vehicles) where the inputs
are essentially the (training) images converted to pixels, then a machine-readable format
(tensors) and the hidden layers act as function mappings to extract “patterns” which
tend to prevail in the images.
As illustrated in Figure 1-8, Computer Vision is used for Object Classification,
Identification, Verification, Detection, Segmentation, and Recognition and, using the
picture as an example, gives rise to responses to questions such as:

14
Chapter 1 Introduction to AI and the AI Ecosystem

• Which type of object is in the image?

• Does the object exist in the image?

• What category of objects are in the image?

The many applications of Computer Vision include facial recognition and


surveillance, document search and archiving, healthcare diagnostics, and crop disease
prevention.

Figure 1-8. Object Classification in Computer Vision (Source: Ilija Mihajlovic,


towardsdatascience.com)

Portfolio, Risk Management, and Forecasting


AI, and specifically Deep Learning, is widely used today in risk management and
portfolio optimization to increase the efficiency and accuracy of operational workflows.
Similarly, the optimization of financial assets, stock price prediction, portfolio, and risk
management are all exciting areas of innovation in 2022.
Forecasting is also a big area right now – advances in cloud storage and processing
power have exposed weather and demand forecasting, asset optimization, algorithmic
trading, and robo-advisors to AI methods. High-accuracy, industrial-scale recurrent

15
Chapter 1 Introduction to AI and the AI Ecosystem

neural networks (RNNs), and specialized long short-term memory models (LSTMs)
are increasingly able to outperform traditional methods. We will look at some practical
hands-on examples of these in Chapter 5 on Deep Learning.

Natural Language Processing (NLP)


The global market for NLP is growing year on year, and is predicted to reach 43 million
dollars by 2025 (Statista).
Natural Language Processing is a branch of AI that deals with the interaction
between computers and humans using natural language. Essentially NLP applies
Machine Learning algorithms to unstructured data and converts it into a form that
computers can understand – the objective is to read, decipher, understand, and make
sense of language in a manner that is (commercially) valuable.
NLP is the driving force behind language translation apps such as Google Translate.
Word Processors such as Microsoft Word and Grammarly also employ NLP to check the
grammatical accuracy of texts. The growing adoption of NLP applications in industry
means the global market is predicted to reach $43m by 2025.9

C
 hatbots
Probably the most well-known application of NLP is chatbots and personal assistant
applications such as Siri and Alexa and Watson Assistant.
Chatbots are essentially software applications to conduct interactive dialogue, with
growing text-to-speech and speech-to-text capability.
The technology has vastly improved since the earliest days of Cortana on Windows.
Today it has evolved to the extent that today Intelligent Virtual Agents (IVAs or Chatbots
2.0) or Interactive Voice Response (IVR) applications are widely used in call centers to
respond to user requests. IVAs have in-built self-learning capability and adapt to context
in contrast to earlier dialog rule-based chatbots.
The business value in 2002 is in improving the customer journey and customer
experience – with the ability to resolve issues quickly, although not in more
complex cases.

9
Statista

16
Chapter 1 Introduction to AI and the AI Ecosystem

The main techniques in Natural Language Processing are syntactic analysis and
semantic analysis. Syntactic analysis focuses on grammar while semantic analysis is
concerned with the underlying meaning of text. Both involve a number of underlying
subprocesses (such as lemmatization and word disambiguation) important for
categorization and more ultimately, insight extraction. We will look at these in more
detail in a later chapter.
In its simplest sense, Natural Language Processing in chatbots is invoked to detect,
then best-fit user “intents” and “entities” to a preconfigured dialogue “corpus.” As user
interaction grows, increasingly more data can be used in the training process to improve
the matching process, and enhance the dialog.

Cognitive Robotic Process Automation (CRPA)


Cognitive Robotic Process Automation is Robotic Process Automation that leverages
AI. While traditional RPA configures computer software to execute a business process,
cognitive RPA tools and solutions add predictive capability and enhanced exception
handling on top of the underlying business process making use of such techniques as
OCR and automated scanning, Text Analytics, Voice to text, and Machine Learning.
While traditional RPA supports automation based on structured data, CRPA more
commonly includes unstructured data sources.
Many operational or portfolio management processes are today coupled with
Cognitive Robotic Process Automation (CRPA), marrying AI and automation for business
problems such as:

• Bulk payment processing

• Transactional risk monitoring

• Auto-completion of forms

• Document Archiving

In risk management, sophisticated AI augmentation of Monte Carlo and VaR


approaches are also increasingly common to both benchmark and improve existing risk
practices.

17
Chapter 1 Introduction to AI and the AI Ecosystem

Other AI Applications
The above introduction to the main uses of Artificial Intelligence in the workplace is
intended to give a flavor of what to expect later on in this book. Specifically, Machine and
Deep Learning, Natural Language Processing, and CRPA underpin the industry-specific
use cases adopted by the private and public sectors today.
We will describe and walk through many of these later on in our hands-on practice,
but for now we have captured in Figure 1-9 a broad segmentation of use cases by sector.

Figure 1-9. AI applications

While emerging AI applications may not yet be fully commercialized or indeed in


use in most workplaces, we also include below a view from Gartner of what is on the
horizon with several of note (e.g., Reinforcement Learning and Edge AI) likely to enter
the mainstream in the coming years.

18
Chapter 1 Introduction to AI and the AI Ecosystem

Figure 1-10. Gartner AI hype cycle

AI Applications: Hands-on Practice


Now that we have taken a first look at the main applications for Artificial Intelligence in
today’s companies and organizations, we will now take a look at a hands-on lab example

19
Chapter 1 Introduction to AI and the AI Ecosystem

CALLING AZURE TEXT ANALYTICS API

The goal of our first exercise is to start getting familiar with cloud and cloud services
(in this case Azure and the Text Analytics API) and familiarize ourselves with a key AI
application, that of Natural Language Processing
1. We use a “sandbox” environment on Microsoft Learn for this exercise:
https://docs.microsoft.com/en-us/learn/modules/classify-
user-feedback-with-the-text-analytics-api/3-exercise-call-
the-text-analytics-api-using-the-api-testing-console
2. Activating the sandbox requires a Microsoft account and an Azure account10

3. Follow the steps in the tutorial to input text and a) detect language, b) extract
key phrases, c) analyze sentiment, and d) extract entities

4. As “stretch” exercises, change the documents in section number 2 and see


what the API returns –- try with "Ich bin so sauer auf dich"

5. Try the other methods, Detect Language, Entities, and Key Phrases, using the
same subscription key

6. Try to make a call from a different region with your subscription and observe
what happens

7. Go back to your Cognitive Services resource created on Azure Portal and


observe API requests on free tier

Data Ingestion and AI Pipelines


From key AI application, we move on to our next section on Data Ingestion and
automating data pipelines. Chapter 3 will discuss this in far greater detail but for now
we introduce AI Engineering as the core skill requirement for delivering tangible,

10
Free for 30 days, then requires credit card to maintain as pay-as-you-go (as long as
resources are deleted immediately after creation, the cost is likely < £2 costs per month or
free). You can check costs incurred at the link below https://portal.azure.com/#blade/
Microsoft_Azure_CostManagement/Menu/costanalysis

20
Chapter 1 Introduction to AI and the AI Ecosystem

production-grade AI solutions11 along with important definitions for Data Pipelines,


pivotal ETL processes, best practice around data wrangling and transformation,
and AutoAI.

A
 I Engineering
Industry research shows that very few AI projects are successful, partly because
technically minded, and often junior resources on an AI project tend to forget that AI
involves people, processes, and tools. The reality is writing machine or deep learning
code is just one small part – and invariable notebooks or scripts fail when not considered
complex surrounding infrastructure.
Data pipelines lie behind every successful AI application – from data ingestion
through several stages of data classification, transformation, analytics, training machine
learning, and deep learning models through inference and retraining/data-drift
processes, the goal is to yield increasingly accurate decisions or insights.
Ultimately no AI project can be a success without a Data Strategy in place with a
robust, serviced delivery pipeline for ingesting data into downstream modeling and
analytics processes. With that in mind, we discuss in this section how data ingestion
works and setting up data pipeline necessary for building a successful AI application.

What Is a Data Pipeline?


A Data Pipeline is a flow of data from upstream source(s) to a downstream sink where
it can be more easily consumed by end users. More formally, it is an automated set of
actions that extract or ingest data from various sources, often transform the data, and
then place in a data store or repository for downstream analysis.
In the age of cloud computing, there are multiple ways this is done such as shifting
data from the web or an app to a data warehouse or from a data lake to a database. What
all have in common in 2022 is a growing need to make the tools and transformational
processes involved as seamless as possible and ultimately achieve full automation.

11
Enterprise AI – more on this in Chapter 7

21
Chapter 1 Introduction to AI and the AI Ecosystem

Extract, Transform, and Load (ETL)


Extract, transform, and load, or ETL, is often confused with a data pipeline. While an
ETL process refers to the process by which data is extracted from different sources,
transformed into a usable format, and then loaded into an end-user system, it is a
discrete, limited set of steps. Data pipelines on the other hand are not discrete in time
and deal with the continuous flow of data.
Because a data pipeline can in a sense be considered as a continuous loop of ETL
steps, it can be helpful to define these three steps.

Extract
Data is extracted from a variety of internal and external sources such as text files, csv,
excel, json, html, relational and nonrelational databases, websites, or APIs. More
modern formats such as parquet and avro are also increasingly utilized for their efficient
compression of datasets.

Transform
Data is transformed in order to make it suitable for, and compatible with, the schema
of a target end-user system. Transform involves cleansing data to remove duplicates or
out-of-date entries; converting data from one format to another; joining and aggregating
data; sorting and ordering data among others.

Load
In the final ETL step, data is loaded into a target system such as a data warehouse. Once
inside the data warehouse, data can be efficiently queried and used for analytics and
business intelligence.

Data Wrangling
The above concepts are very much central to the role of the Data Engineer but there is
considerable overlap, particularly in the Transform step in ETL in serving downstream
Data Science and Data Analysis processes.

22
Another random document with
no related content on Scribd:
His efforts were all for the good of Prussia, and his subjects
recognized what he had done for the fatherland. Zimmermann, the
Hanoverian physician, thus describes him in his old age:—
“He is not of tall stature, and seems bent under his load of
laurels and his many years of struggle. His blue coat, much worn like
his body, long boots to above the knees, and a white snuff-
besprinkled vest, gave him a peculiar aspect. But the fire of his eyes
showed that Frederick’s soul had not grown old. Though his bearing
was that of an invalid, yet one must conclude from the quickness of
his movements and the bold decisiveness of his look, that he could
yet fight like a youth. Set up his unimportant figure among a million
of men, and every one would recognize in him the king, so much
sublimity and constancy resided in this unusual man!”
And the same writer says of his palace:—
“At Sans Souci there reigned such quiet that one might notice
every breath. My first visit to this lonely spot was of an evening in the
late fall. I was indeed surprised when I saw before me a small
mansion, and learned that in it lived the hero who had already
shaken the world with his name. I went around the entire house,
approached the windows, saw light in them, but found no sentry
before the doors, nor met a man to ask me who I was or what I
craved. Then first I understood the greatness of Frederick. He needs
for his protection not armed minions or firearms. He knows that the
love and respect of the people keep watch at the doors of his modest
abode.”
Frederick’s military genius was coupled with absolute control of
his country’s resources. Though Gustavus Adolphus was both
general and king, he was not an autocrat. The constitution of
Sweden prescribed his bounds. In ancient days, only Alexander
stood in the position of Frederick, and Cæsar, during the latter
portion of his campaigns. Hannibal was always limited in his
authority. Alexander, working in a far larger sphere, had personal
ambitions and a scope which Frederick lacked, yet each worked for
the good of his country. Frederick was not a conqueror. He fought to
defend his possessions. His military education was narrow; his
favorite studies and occupations essentially peaceful. But from
history he had sucked the ambition to make more powerful the
country which owed him allegiance, and he had digested the deeds
of the great commanders as only a great soldier can. Unconscious of
his own ability, necessity soon forced him to show what he was
worth. Like the Romans, he laid down one rule: Never wait for your
opponent’s attack. If you are on the defensive, let this be still of an
offensive character in both campaigns and battles. This rule he
followed through life.
Frederick most resembled Hannibal. He possessed Hannibal’s
virtue,—the secret of keeping a secret. He never divulged his plans.
From the start he was a captain, and so he remained to the end.
How did he learn his trade? Alexander and Hannibal learned theirs
under Philip and Hamilcar in Greece and Spain. Cæsar taught
himself in Gaul; Gustavus Adolphus, in Denmark, Russia, and
Poland. But Frederick had had no opportunities, except to learn the
pipe-clay half of the art of war. His five years’ retirement after his
court-martial must have done for him more than any one ever knew.
The fertility of his intelligence, and his power of applying what he
learned, were the foundation of his skill. His first campaign advanced
him more than a life of war does the greatest among others. The
First Silesian War was a school out of which Frederick emerged the
soldier he always remained.
That Frederick was not a warrior for the sake of conquest was
well shown in his moderation after the First Silesian War. He
demanded only his rights, as he understood them. And after the
Second Silesian, and the Seven Years’ War, he asked no more than
he got at the peace of Dresden, when he might have made far
greater claims. Indeed, Frederick’s whole life showed his preference
for the arts of peace. After the glamour of the first step had vanished,
war was but his duty to Prussia.
Frederick had assimilated the theory of war from the history of
great men; but its study was never a favorite pursuit. He was a born
soldier. As Cæsar taught himself from ambition, so Frederick taught
himself from necessity. What he did had not a theoretical but an
essentially practical flavor. He rose to the highest intellectual and
characteristic plane of the art, not by imitation of others, but by native
vigor. Frederick had by heart the lesson of Leuctra and Mantinæa,
but it required genius to apply the oblique order as he did it at
Leuthen. No man has ever so perfectly done this. No one in modern
times has had such troops.
Frederick placed war among the liberal arts. Perhaps the least
straight-laced of any captain, he held that only broad principles can
govern it; that the use of the maxims of war depends on the
personality of the soldier and the demands of the moment. His
“Instructions” to his generals set out Frederick’s whole art. It is full of
simple, common sense; apt rules, practical to the last degree. But it
was the man who made them so fruitful. Just because they do
represent the man they are interesting in this connection.
Frederick is the first writer on the military art who goes to the root
of the matter. He always wrote profusely,—most plentifully in bad
French verse,—but his “Instructions” are admirable throughout. At
the head of the paper stands this motto: “Always move into the field
sooner than the enemy;” and this was his course in campaign and
battle alike. He asked of the enemy a categorical yes or no to his
ultimatum, and upon no struck an instant blow. So novel was
Frederick’s quick decisiveness that he was at first looked upon in
Europe as a rank disturber of the peace. But his was only the old
Roman method revamped.
Underlying this rule was the good of Prussia. This motive he
ground into his men’s souls. He demanded as a daily habit
extraordinary exertions. His men must perform the unusual at all
times. And “from highest officer to last private, no one is to argue,
but to obey,” says he. A habit of obedience supplanted fear of
punishment. The king’s zeal flowed down through every channel to
the ranks. He was himself notoriously the hardest-worked man in
Prussia, and his men appreciated the fact.
Next in importance to discipline comes the care of the troops. In
his day subsistence tied armies down to predetermined manœuvres.
Frederick carried his rations with him, and in his rapid movements
made requisitions on the country, as Napoleon, a generation later,
did more fully.
Then follows the study of topography. Positions were to
Frederick only links in a chain, or resting places, but he ably utilized
the lay of the land in his battles. He taught his generals, wherever
they might be, to look at the surrounding country and ask
themselves, “What should I do if I was suddenly attacked in this
position?” He enunciated many maxims scarcely known at his day.
“If you divide your forces you will be beaten in detail. If you wish to
deliver a battle bring together as many troops as possible.” Frederick
did not try to keep everything, but put all his energy into the one
important matter. His was no hard and fast system. He did what was
most apt. His battle plans were conceived instantly on the ground.
What was intricate to others was simple to him and to the Prussian
army. Frederick held Hannibal up as a pattern. “Always,” said the
king, “lead the enemy to believe you will do the very reverse of what
you intend to do.”
Minor operations are clearly treated of. In general the motif of
these “Instructions” is attack and initiative. “Prussians,” said he, “are
invariably to attack the enemy.” Close with him even if weaker. Make
up for weakness by boldness and energy. He opposed passive
defence. Every one of his battles was offensive. He complained,
indeed, that he had to risk much all his life.
Frederick’s irrepressible courage under misfortune is equalled in
history only by Hannibal’s. Fortune was not his servant as she was
Alexander’s and Cæsar’s. He thanked himself for his good luck, or
rather his successes were due to the fact that he made use of good
luck when he had it, and threw no chances away. The magnificence
of his warlike deeds is traceable almost solely to his own mental
power and remarkable persistency. No danger or difficulty ever, in
the remotest degree, changed his purpose or affected his reasoning
power. It was this kept the ascendant on his side.
Despite sternest discipline, Frederick was familiar with his men,
who knew him as Vater Fritz, and bandied rough jokes with him.
“The Austrians are three to one of us, and stoutly entrenched,” said
the king, riding the outposts before Leuthen. “And were the devil in
front and all around them, we’ll hustle them out, only thou lead us
on!” answered a brawny grenadier. “Good-night, Fritz.” He gained
such personal love from his men that it seems to have been
transmitted as a heritage of the Hohenzollerns. He spurred his men
to the most heroic efforts, the most extraordinary feats of daring and
endurance. As the complement to this quality, he infused in his
enemies a dread of his presence. He utilized the mistakes they
made and led them into still others, less from any system than by
doing the right thing at the right moment. Strict rules aid only the
minds whose conceptions are not clear, and whose execution lacks
promptness. Rules were as nothing to Frederick. He observed them,
not because they were rules, but because they were grounded on
truths which his own mind grasped without them. He broke them
when there was distinct gain in so doing. His operations against six
armies surrounding him was based on his own maxim, that “Whoso
attempts to defend everything runs danger of losing everything,” and
he turned from one to the other, risking much to gain much. This idea
of Frederick’s was a novel one in his century, whose warfare
consisted in an attempt to protect and hold everything by fortresses
and partial detachments. In working out this idea he is
unapproached.
Frederick never allowed his enemies to carry out their own
plans. His movements imposed limitations upon them. He impressed
his own personality on every campaign. To carry his victuals with him
enabled him to outmanœuvre them, for his enemies relied
exclusively on magazines established beforehand. He could select
his routes according to the exigencies of the moment, while they
must keep within reach of their depots.
Tactically, Frederick stands highest of all soldiers. Strategically
he was less great. In strategic movements, his brother, Prince Henry,
did occasional work worthy to be placed beside the king’s. Tactically,
no one could approach him. His method of handling the three arms
was perfect.
Gustavus Adolphus had given new impulse to systematic,
intelligent war. But what he did was not understood. His imitators
jumbled the old and new systems. They placed too much reliance on
fortresses and magazines, and on natural and artificial obstacles;
they made strained efforts to threaten the enemy’s communications;
they manœuvred for the mere sake of doing something and apart
from any general plan; they avoided decisive movements and
battles.
Frederick, by making his armies less dependent on magazines,
acquired a freer, bolder, and more rapid style. The allies aimed to
parcel out Prussia. Frederick met them with decision. Surrounded on
all sides by overwhelming numbers, he was compelled to defend
himself by hard knocks. And his individual equipment as well as the
discipline of his army enabled him to do this with unequalled
brilliancy. In all history there is no such series of tactical feats as
Frederick’s.
Each captain must be weighed by the conditions under which he
worked. We cannot try Alexander by the standard of Napoleon.
While Napoleon’s battle tactics have something stupendous in their
magnificence, Frederick’s battles, in view of numbers and difficulties,
are distinctly finer. Frederick’s decisiveness aroused fresh interest in
battle. Manœuvres now sought battle as an object, while sieges
became fewer and of small moment.
All Europe was agog at Frederick’s successes, but no one
understood them. Lloyd alone saw below the surface. As Gustavus
had been misinterpreted, so now Frederick. Some imitated his
minutiæ down to the pig-tails of his grenadiers. Some saw the cure-
all of war in operations against the enemy’s flanks and rear. Some
saw in detachments, some in concentration, the trick of the king.
Only Lloyd recognized that it all lay in the magnificent personality of
the king himself, that there was no secret, no set rule, no
legerdemain, but that here again was one of the world’s great
captains. The imitators of Frederick caught but the letter. The spirit
they could not catch. Until two generations more had passed, and
Lloyd and Jomini had put in printed form what Frederick and
Napoleon did, the world could not guess the riddle.
His own fortresses were of importance to Frederick because his
enemy respected them. But he paid small heed to the enemy’s. He
could strike him so much harder by battle, that he never frittered
away his time on sieges, except as a means to an end. The allies
clung to their fortified positions. Frederick despised them, and
showed the world that his gallant Prussians could take them by
assault.
This period, then, is distinguished for the revival of battles, and
of operations looking towards battle. Of these Frederick was the
author. Battles in the Seven Years’ War were not haphazard. Each
had its purpose. Pursuit had, however, not yet been made effective
so to glean the utmost from victory. No single battle in this period
had remarkable results. Frederick’s battles were generally fought to
prevent some particular enemy from penetrating too far into the
dominions of Prussia. In this they were uniformly successful. But in
the sense of Napoleon’s battles they were not decisive. The superior
decisiveness of Napoleon’s lay in the strategic conditions and in his
superiority of forces. No battles—as battles—could be more
thoroughly fought out than Frederick’s; no victories more brilliant.
Frederick not only showed Europe what speed and decision can
do in war, but he made many minor improvements in drill, discipline,
and battle-tactics. He introduced horse-artillery. His giving scope to
such men as Seydlitz and Ziethen made the Prussian cavalry a
model for all time. He demonstrated that armies can march and
operate continuously, with little rest, and without regard to seasons.
Light troops grew in efficiency. War put on an aspect of energetic
purpose, but without the ruthless barbarity of the Thirty Years’ War.
No doubt Napoleon, at his best, was the greater soldier. But
Napoleon had Frederick’s example before him, as well as the
lessons of all other great captains by heart. Napoleon’s motive was
aggressive; Frederick’s, pure defence. Hence partly the larger
method. But Frederick in trial or disaster was unspeakably greater
than Napoleon, both as soldier and man.
In the forty-six years of his reign Frederick added sixty per cent.
to the Prussian dominion, doubled its population, put seventy million
thalers in its treasury, and created two hundred thousand of the best
troops in existence. Prussia had been a small state, which the
powers of Europe united to parcel out. He left it a great state, which
all Europe respected, and planted in it the seed which has raised its
kings to be emperors of Germany. This result is in marked contrast
to what Napoleon’s wars did for France.
Whoever, under the sumptuous dome of the Invalides, has
gazed down upon the splendid sarcophagus of Napoleon, and has
stepped within the dim and narrow vault of the plain old garrison
church at Potsdam, where stand the simple metal coffins of
Frederick the Great and of his father, must have felt that in the latter
shrine, rather than the other, he has stood in the presence of the
ashes of a king.
Whatever may be said of Frederick’s personal method of
government, or of the true Hohenzollern theory that Prussia
belonged to him as an heritage to make or to mar as he saw fit, it
cannot be denied that he was true to the spirit of his own verses,
penned in the days of his direst distress:—

“Pour moi, menacé du naufrage,


Je dois, en affrontant l’orage,
Penser, vivre et mourir en Roi.”
LECTURE VI.
NAPOLEON.

THE career of Napoleon Bonaparte is so near to our own times and


so commonly familiar, that it is not essential to describe any of those
operations which were, within the memory of some men yet living,
the wonder and dread of Europe. In certain respects Napoleon was
the greatest of all soldiers. He had, to be sure, the history of other
great captains to profit by; he had not to invent; he had only to
improve. But he did for the military art what constitutes the greatest
advance in any art, he reduced it to its most simple, most perfect
form; and his and Frederick’s campaigns furnished the final material
from which Jomini and his followers could elucidate the science; for it
has taken more than two thousand years of the written history of war
to produce a written science of war.
I shall not touch upon Napoleon’s life as statesman or lawgiver,
nor on his services in carrying forward the results of the Revolution
toward its legitimate consequence,—the equality of all men before
the law. In these rôles no more useful man appears in the history of
modern times. I shall look at him simply as a soldier.
Napoleon’s career is a notable example of the necessity of
coexistent intellect, character, and opportunity to produce the
greatest success in war. His strength distinctly rose through half his
career, and as distinctly fell during the other half. His intellectual
power never changed. The plan of the Waterloo campaign was as
brilliant as any which he ever conceived. His opportunity here was
equal to that of 1796. But his execution was marred by weakening
physique, upon which followed a decline of that decisiveness which
is so indispensable to the great captain. It will, perhaps, be
interesting to trace certain resemblances between the opening of his
first independent campaign in 1796, and his last one in 1815, to
show how force of character won him the first and the lack of it lost
him the last; and to connect the two campaigns by a thread of the
intervening years of growth till 1808, and of decline from that time
on.
When Napoleon was appointed to the command of the Army of
Italy he had for the moment a serious problem. In this army were
able and more experienced officers of mature powers and full of
manly strength, who looked on this all but unknown, twenty-seven
years old, small, pale, untried commander-in-chief, decidedly
askance. But Napoleon was not long in impressing his absolute
superiority upon them all. They soon recognized the master-hand.
The army lay strung out along the coast from Loano to Savona,
in a worse than bad position. The English fleet held the sea in its
rear, and could make descents on any part of this long and ill-held
line. Its communications lay in prolongation of the left flank, over a
single bad road, subject not only to interruption by the English, but
the enemy, by forcing the Col di Tenda, could absolutely cut it off
from France. The troops were in woful condition. They had neither
clothing nor rations. They were literally “heroes in rags.” On the
further side of the Maritime Alps lay the Austrian general, Beaulieu,
commanding a superior army equally strung out from Mount Blanc to
Genoa. His right wing consisted of the Piedmontese army under Colli
at Ceva; his centre was at Sassello; with his left he was reaching out
to join hands with the English at Genoa. Kellerman faced, in the
passes of the Alps, a force of twenty-five thousand Sardinians, but
for the moment was out of the business.
1796.
Napoleon spent but few days in providing for his troops, and
then began to concentrate on his right flank at Savona. He knew that
his own position was weak, but he also divined from the reports
brought in from the outposts that the enemy’s was worse. From the
very start he enunciated in his strategic plan the maxim he obeyed
through life: Move upon your enemy in one mass on one line so that
when brought to battle you shall outnumber him, and from such a
direction that you shall compromise him. This is, so to speak, the
motto of Napoleon’s success. All perfect art is simple, and after
much complication or absence of theoretical canons from ancient
times to his, Napoleon reduced strategy down to this beautifully
simple, rational rule.
Nothing in war seems at first blush so full of risk as to move into
the very midst of your enemy’s several detachments. No act in truth
is so safe, if his total outnumbers yours and if you outnumber each of
his detachments. For, as always seemed to be more clear to
Napoleon and Frederick than to any of the other great captains, you
can first throw yourself upon any one of them, beat him and then turn
upon the next. But to do this requires audacity, skill, and, above all,
tireless legs. And success is predicated in all cases on the
assumption that God is on the side of the heaviest battalions.
So Napoleon, who was very familiar with the topography of Italy,
at once determined to strike Beaulieu’s centre, and by breaking
through it, to separate the twenty-five thousand Piedmontese in the
right wing from the thirty-five thousand Austrians in the left wing, so
that he might beat each separately with his own thirty-seven
thousand men.
Beaulieu’s reaching out toward Genoa facilitated Napoleon’s
manœuvre, for the Austrian would have a range of mountains
between him and his centre under Argenteau, whom he had at the
same time ordered forward on Savona via Montenotte. Napoleon’s
manœuvre was strategically a rupture of Beaulieu’s centre. Tactically
it first led to an attack on the right of Argenteau’s column. The details
of the manœuvre it would consume hours to follow. Suffice it to say
that by a restless activity which, barring Frederick, had not been
seen in war since the days of Cæsar, Napoleon struck blow after
blow, first upon Argenteau, throwing him back easterly, then on Colli,
throwing him back westerly, absolutely cut the allies in two, fought
half a dozen battles in scarce a greater number of days, and in a
short fortnight had beaten the enemy at all points, had captured
fifteen thousand prisoners, fifty guns, and twenty-one flags.
Still the problem was serious. Beaulieu, if active, could shortly
concentrate one hundred thousand men. Napoleon must allow him
not a moment of breathing spell. He issued a proclamation to his
troops which sounds like the blare of a trumpet. It set ablaze the
hearts of his men; it carried dread to his enemies, and Napoleon
followed it up by a march straight on Turin. Alarmed and
disconcerted, the King of Sardinia sued for peace. Napoleon
concluded an armistice with him, and thus saw himself dis-
embarrassed of the enemy’s right wing and free to turn on the left
under Beaulieu. His columns were at once launched on Alexandria,
and by his skilful manœuvres and unparalleled alertness he soon got
the better of the Austrians. He had at a stroke made himself the most
noted general of Europe. The rest of the campaign was equally
brilliant and successful.
Napoleon had shown his army that he commanded not by the
mere commission of the Directory, but by the divine right of genius.
He had not only taken advantage of every error of his opponents, but
had so acted as to make them commit errors, and those very errors
of which he had need. His army had been far from good. But “I
believe,” says Jomini, “that if Napoleon had commanded the most
excellent troops he would not have accomplished more, even as
Frederick in the reversed case would not have accomplished less.”
We recognize in this first independent campaign of Napoleon the
heroic zeal of Alexander, the intellectual subtlety of Hannibal, the
reckless self-confidence of Cæsar, the broad method of Gustavus,
the heart of oak of Frederick. But one fault is discoverable, and this,
at the time, was rather a virtue,—Napoleon underrated his
adversary. By and by this error grew in the wrong direction, and
became a strong factor in his failures.
Through the rest of this campaign, which numbered the victories
of Lodi, Castiglione, Bassano, Arcole, the most noteworthy thing
except his own personal diligence is the speed with which Napoleon
manœuvred his troops. To state an instance: from September 5 to
September 11, six days, Napoleon’s men fought one pitched battle
and two important combats and marched, Masséna eighty-eight
miles, Augereau ninety-six miles, and the other corps less distances.
He was far from being uniformly lucky. He had many days of serious
backsets. But whenever luck ran in his favor, he seized it and made
it useful; when against him, he gamely strove to stem its tide. If
Fortune frowned, he wooed her unceasingly till she smiled again.
The campaign which began in April, 1796, really lasted till April,
1797. Napoleon pushed the Austrians out of Italy and well back
towards Vienna. His triumphs culminated in the brilliant victory of
Rivoli, and his success at the truce of Leoben. At Rivoli, with thirty
thousand men, Napoleon defeated the enemy and captured twenty
thousand prisoners. The men who had left Verona and fought at San
Michele on the 13th of January, marched all night to Rivoli, there
conquered on the 14th, and again marching to Mantua, some thirty
miles, compelled Provera to lay down his arms on the 15th.
Napoleon could rightfully boast to have equalled Cæsar in speed of
foot.
The men of the Revolution had cut loose from eighteenth century
methods of warfare by rising en masse and putting the personal
element into the scale. But it was reserved for Napoleon to substitute
a new method for the old. From Nice to Leoben he showed the world
what modern war can do. He made himself independent of
magazines, as Frederick had done but rarely. With a smaller army he
always had more men at the point of contact. This was Napoleon’s
strongest point. He divined what his enemy would do, not from his
tent but from the saddle, seeing with his own eyes and weighing all
he saw and heard. He was every day and all day long in motion; he
rode unheard-of distances. He relied on no one but himself, as, with
his comparatively small army, he could well do; and correctly seeing
and therefore correctly gauging circumstances, he had the courage
to act upon his facts. He sought battle as the result of every
manœuvre. The weight of his intellect and his character were equally
thrown into all he did. And his abnormal ambition drove him to
abnormal energy. In this his first campaign and in one year, with
moderate forces, he had advanced from Nice to within eighty miles
of Vienna, and had wrung a peace from astonished Austria.
Napoleon next undertook the Egyptian campaign. His ambition
had grown with success. But matters in France were not in a
condition of which he could personally avail, and he believed he
could increase his reputation and power by conquests in the East.
His imagination was boundless. Perhaps no great soldier can be free
from imagination, or its complement, enthusiasm. Napoleon had it to
excess, and in many respects it helped him in his hazardous
undertakings. At this time he dreamed himself another Alexander
conquering the Eastern world, thence to return, as Alexander did not,
with hordes of soldiers disciplined by himself and fanatically attached
to his person, to subjugate all Europe to his will. The narration of this
campaign of sixteen months may be made to sound brilliant; its
result was miscarriage. It is full of splendid achievements and
marred but by one mishap,—the siege of Acre. But the total result of
the campaign was failure to France, though gain to Napoleon, who
won renown, and, abandoning his army when the campaign closed,
returned to Paris at a season more suited to his advancement.
Napoleon’s military conduct in this campaign shows the same
marvellous energy, the same power of adapting means to end, of
keeping all his extraordinary measures secret, the better to impose
on the enemy by their sudden development, the same power over
men. But the discipline of the army was disgraceful. The plundering
which always accompanied Napoleon’s movements—for, unlike
Gustavus and Frederick, he believed in allowing the soldier freedom
beyond bounds if only he would march and fight—was excessive.
The health of the army was bad; its deprivations so great that suicide
was common to avoid suffering which was worse. And yet Napoleon,
by his unequalled management, kept this army available as a tool,
and an excellent one.
Napoleon now became First Consul. The campaign of 1800 was
initiated by the celebrated crossing of the Alps. This feat, of itself,
can no more be compared, as it has been, to Hannibal’s great
achievement, nor indeed to Alexander’s crossing the Paropamisus,
than a Pullman excursion to Salt Lake City can be likened to Albert
Sidney Johnston’s terrible march across the Plains in 1857.
Napoleon’s crossing was merely an incident deftly woven into a
splendid plan of campaign. From Switzerland, a geographical salient
held by them, the French could debouch at will into Italy or Germany.
Mélas, the Austrian general in Italy, had his eyes fixed upon
Masséna in Genoa. A large reserve army was collected by Napoleon
in France, while Moreau pushed toward the Danube. Mélas naturally
expected that the French would issue from Provence, and kept his
outlook towards that point. When Napoleon actually descended from
the Great St. Bernard upon his rear, he was as badly startled as
compromised. This splendid piece of strategy was followed up with
Napoleon’s usual restless push, and culminated in the battle of
Marengo. This was at first a distinct Austrian victory, but good
countenance, Mélas’ neglect to pursue his gain, and Napoleon’s
ability to rally and hold his troops until absent Dessaix could rejoin
him, turned it into an overwhelming Austrian defeat. And Napoleon,
by the direction given to his mass, had so placed Mélas that defeat
meant ruin. He was glad to accept an armistice on Napoleon’s own
terms.

MARENGO CAMPAIGN
This superb campaign had lasted but a month, and had been
characterized by the utmost dash and clearness of perception. Again
Napoleon’s one mass projected on one properly chosen line had
accomplished wonders.
Napoleon once said to Jomini, “The secret of war lies in the
secret of communications. Keep your own and attack your enemy’s
in such a way that a lost battle may not harm you, a battle won may
ruin your adversary. Seize your enemy’s communications and then
march to battle.” Napoleon’s success came from study of the
situation. His art was founded on an intimate knowledge of all the
facts, coupled with such reasoning power as enabled him to gauge
correctly what his enemy was apt to do. Without the art the study
would be useless. But the art could not exist apart from study.
After Marengo there were five years of peace. These and the
four years between Wagram and the Russian campaign were the
only two periods of rest from war in Napoleon’s career. Succeeding
this came the memorable Austerlitz campaign. Napoleon had had for
some months three of his best officers in Germany studying up
topography, roads, bridges, towns, in the Black Forest region and
toward the Tyrol and Bohemia. To thus make himself familiar with the
status was his uniform habit.

Ulm-Austerlitz Campaign
Napoleon, now Emperor, was at Boulogne, threatening and
perhaps at times half purposing an invasion of England. He
commanded the best army he ever had. The Austrians, not
supposing him ready, inundated Bavaria with troops, without waiting
for their allies, the Russians, and marched up the Danube to the Iller,
under Field-Marshal Mack. Napoleon put an embargo on the mails,
broke up from Boulogne at twenty-four hours’ notice, and reached
the vicinity of the enemy with an overwhelming force before Mack
was aware of his having left the sea. His line of march was about
Mack’s right flank, because this was the nearest to Boulogne and
gave him a safe base on the confederate German provinces. So well
planned was the manœuvre, so elastic in its design for change of
circumstances, that it fully succeeded, step for step, until Mack was
surrounded at Ulm and surrendered with his thirty thousand men.
Here again we find the Napoleonic rule fairly overwhelming Mack
with superior numbers. Except in 1796 and 1814, Napoleon always
had more men than the enemy on the field at the proper time. “They
ascribe more talent to me than to others,” he observed, “and yet to
give battle to an enemy I am in the habit of beating, I never think I
have enough men; I call to my aid all that I can unite.”
The chart herewith given of the grand manœuvre of Ulm is so
simple as to suggest no difficulties of execution. But there is
probably nothing in human experience which taxes strength,
intellect, judgment, and character to so great a degree as the
strategy and logistics of such a movement, unless it be the tactics of
the ensuing battle. The difficulties are, in reality, gigantic.
Napoleon headed direct for Vienna, and on the way absolutely
lived on the country. “In the movements and wars of invasion
conducted by the Emperor, there are no magazines; it is a matter for
the commanding generals of the corps to collect the means of
victualling in the countries through which they march,” writes Berthier
to Marmont. Napoleon took Vienna and marched out towards Brünn,
where the Austrians and Russians had concentrated. Here he was
far from secure, if equal talent had been opposed to him; but he took
up a position near Austerlitz, from which he could retreat through
Bohemia, if necessary, and, calmly watching the enemy and allowing
several chances of winning an ordinary victory to pass, he waited,
with an audacity which almost ran into braggadocio, for the enemy to
commit some error from which he could wrest a decisive one. And
this the allies did, as Napoleon divined they would do. They tried to
turn his right flank and cut him off from Vienna. Napoleon massed his
forces on their centre and right, broke these in pieces, and won the
victory of which he was always most proud. Napoleon’s conduct here
showed distinctly a glint of what he himself so aptly calls the divine
part of the art.
There is always a corresponding danger in every plan which is of
the kind to compass decisive results. In this case Napoleon risked
his right wing. But to judge how much it is wise to risk and to guess
just how much the enemy is capable of undertaking is a
manifestation of genius.
The era of the great battles of modern war dates from Austerlitz.
Marengo was rather two combats than one great battle. Frederick’s
battles were wonders of tactics and courage, but they differ from the
Napoleonic system. In Frederick’s battles the whole army was set in
motion for one manœuvre at one time to be executed under the
management of the chief. If the manœuvre was interrupted by
unforeseen events, the battle might be lost. In Napoleon’s system,
the centre might be broken and the wings still achieve victory; one
wing might be crushed while the other destroyed the enemy. A bait
was offered the enemy by the exhibition of a weak spot to attract his
eye, while Napoleon fell on the key-point with overwhelming odds.
But in this system the control passed from the hand of the leader. All
he could do was to project a corps in a given direction at a given
time. Once set in motion, these could not readily be arrested. Such a
system required reserves much more than the old method. “Battles
are only won by strengthening the line at a critical moment,” says
Napoleon. Once in, Napoleon’s corps worked out their own
salvation. He could but aid them with his reserves.
There is a magnificence of uncertainty and risk, and
corresponding genius in the management of the battles of Napoleon;
but for purely artistic tactics they do not appeal to us as do
Frederick’s. The motif of Alexander’s battles is more akin to
Napoleon’s; that of Hannibal’s, to Frederick’s.
It has been said that Napoleon never considered what he should
do in case of failure. The reverse is more exact. Before delivering a
battle, Napoleon busied himself little with what he would do in case
of success. That was easy to decide. He busied himself markedly
with what could be done in case of reverse.
Like all great captains, Napoleon preferred lieutenants who
obeyed instead of initiating. He chafed at independent action. This
was the chief’s prerogative. But as his armies grew in size he gave
his marshals charge of detail under general instructions from himself.
Dependence on Napoleon gradually sapped the self-reliance of more
than one of his lieutenants, and though there are instances of noble
ability at a distance from control, most of his marshals were able
tacticians, rather than great generals. Napoleon grew impatient of
contradiction or explanation; and he sometimes did not learn or was
not told of things he ought to know. He was no longer so active.
Campaigning was a hardship. His belief in his destiny became so
strong that he began to take greater risks. Such a thing as failure did
not exist for him. His armies were increasing in size, and railroads
and telegraphs at that day did not hasten transportation and news.
The difficulties he had to contend with were growing fast.
These things had the effect of making Napoleon’s military plans
more magnificent, more far-reaching. But all the less could he pay
heed to detail, and from now on one can, with some brilliant
exceptions, perceive more errors of execution. In the general
conception he was greater than ever, and this balanced the scale.
His ability to put all his skill into the work immediately in hand was
marvellous. But with a vast whole in view, the parts were, perhaps of
necessity, lost sight of.
The campaigns of 1806 and 1807 were in sequence. To move on
the Prussians, who, under the superannuated Duke of Brunswick,
were concentrated in Thuringia, Napoleon massed on his own right,
disgarnishing his left, turned their left,—in this case their strategic
flank, because the manœuvre cut them off from Berlin and their
allies, the Russians,—and with overwhelming vigor fell on the
dawdling enemy at Jena and Auerstädt. The Prussians had
remained stationary in the art of war where they had been left by
Frederick, and had lost his burning genius.

Вам также может понравиться